2019-12-13 10:12:12 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe WildcardUrlChecker do
|
2022-07-28 00:14:14 +08:00
|
|
|
describe '.check_url' do
|
|
|
|
context 'when url is valid' do
|
2020-01-03 00:03:13 +08:00
|
|
|
it 'returns true' do
|
2019-12-13 10:12:12 +08:00
|
|
|
result1 = described_class.check_url('https://*.discourse.org', 'https://anything.is.possible.discourse.org')
|
2020-01-03 00:03:13 +08:00
|
|
|
expect(result1).to eq(true)
|
2019-12-13 10:12:12 +08:00
|
|
|
|
|
|
|
result2 = described_class.check_url('https://www.discourse.org', 'https://www.discourse.org')
|
2020-01-03 00:03:13 +08:00
|
|
|
expect(result2).to eq(true)
|
2019-12-13 10:12:12 +08:00
|
|
|
|
|
|
|
result3 = described_class.check_url('*', 'https://hello.discourse.org')
|
2020-01-03 00:03:13 +08:00
|
|
|
expect(result3).to eq(true)
|
2019-12-13 10:12:12 +08:00
|
|
|
|
|
|
|
result4 = described_class.check_url('discourse://auth_redirect', 'discourse://auth_redirect')
|
2020-01-03 00:03:13 +08:00
|
|
|
expect(result4).to eq(true)
|
|
|
|
|
|
|
|
result5 = described_class.check_url('customprotocol://www.discourse.org', "customprotocol://www.discourse.org")
|
|
|
|
expect(result5).to eq(true)
|
2019-12-13 10:12:12 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context 'when url is invalid' do
|
2020-01-03 00:03:13 +08:00
|
|
|
it "returns false" do
|
2019-12-13 10:12:12 +08:00
|
|
|
result1 = described_class.check_url('https://*.discourse.org', 'https://bad-domain.discourse.org.evil.com')
|
2020-01-03 00:03:13 +08:00
|
|
|
expect(result1).to eq(false)
|
2019-12-13 10:12:12 +08:00
|
|
|
|
|
|
|
result2 = described_class.check_url('https://www.discourse.org', 'https://www.discourse.org.evil.com')
|
2020-01-03 00:03:13 +08:00
|
|
|
expect(result2).to eq(false)
|
2019-12-13 10:12:12 +08:00
|
|
|
|
|
|
|
result3 = described_class.check_url('https://www.discourse.org', 'https://www.www.discourse.org')
|
2020-01-03 00:03:13 +08:00
|
|
|
expect(result3).to eq(false)
|
2019-12-13 10:12:12 +08:00
|
|
|
|
|
|
|
result4 = described_class.check_url('https://www.discourse.org', "https://www.discourse.org\nwww.discourse.org.evil.com")
|
2020-01-03 00:03:13 +08:00
|
|
|
expect(result4).to eq(false)
|
|
|
|
|
|
|
|
result5 = described_class.check_url('https://', "https://")
|
|
|
|
expect(result5).to eq(false)
|
2019-12-13 10:12:12 +08:00
|
|
|
|
2020-01-03 00:03:13 +08:00
|
|
|
result6 = described_class.check_url('invalid$protocol://www.discourse.org', "invalid$protocol://www.discourse.org")
|
|
|
|
expect(result6).to eq(false)
|
2019-12-13 10:12:12 +08:00
|
|
|
|
2020-01-03 00:03:13 +08:00
|
|
|
result7 = described_class.check_url('noscheme', "noscheme")
|
|
|
|
expect(result7).to eq(false)
|
2019-12-13 10:12:12 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|