2019-12-12 21:12:12 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe WildcardUrlChecker do
|
|
|
|
|
|
|
|
describe 'check_url' do
|
|
|
|
context 'valid url' do
|
2020-01-02 11:03:13 -05:00
|
|
|
it 'returns true' do
|
2019-12-12 21:12:12 -05:00
|
|
|
result1 = described_class.check_url('https://*.discourse.org', 'https://anything.is.possible.discourse.org')
|
2020-01-02 11:03:13 -05:00
|
|
|
expect(result1).to eq(true)
|
2019-12-12 21:12:12 -05:00
|
|
|
|
|
|
|
result2 = described_class.check_url('https://www.discourse.org', 'https://www.discourse.org')
|
2020-01-02 11:03:13 -05:00
|
|
|
expect(result2).to eq(true)
|
2019-12-12 21:12:12 -05:00
|
|
|
|
|
|
|
result3 = described_class.check_url('*', 'https://hello.discourse.org')
|
2020-01-02 11:03:13 -05:00
|
|
|
expect(result3).to eq(true)
|
2019-12-12 21:12:12 -05:00
|
|
|
|
|
|
|
result4 = described_class.check_url('discourse://auth_redirect', 'discourse://auth_redirect')
|
2020-01-02 11:03:13 -05: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-12 21:12:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid domain' do
|
2020-01-02 11:03:13 -05:00
|
|
|
it "returns false" do
|
2019-12-12 21:12:12 -05:00
|
|
|
result1 = described_class.check_url('https://*.discourse.org', 'https://bad-domain.discourse.org.evil.com')
|
2020-01-02 11:03:13 -05:00
|
|
|
expect(result1).to eq(false)
|
2019-12-12 21:12:12 -05:00
|
|
|
|
|
|
|
result2 = described_class.check_url('https://www.discourse.org', 'https://www.discourse.org.evil.com')
|
2020-01-02 11:03:13 -05:00
|
|
|
expect(result2).to eq(false)
|
2019-12-12 21:12:12 -05:00
|
|
|
|
|
|
|
result3 = described_class.check_url('https://www.discourse.org', 'https://www.www.discourse.org')
|
2020-01-02 11:03:13 -05:00
|
|
|
expect(result3).to eq(false)
|
2019-12-12 21:12:12 -05:00
|
|
|
|
|
|
|
result4 = described_class.check_url('https://www.discourse.org', "https://www.discourse.org\nwww.discourse.org.evil.com")
|
2020-01-02 11:03:13 -05:00
|
|
|
expect(result4).to eq(false)
|
|
|
|
|
|
|
|
result5 = described_class.check_url('https://', "https://")
|
|
|
|
expect(result5).to eq(false)
|
2019-12-12 21:12:12 -05:00
|
|
|
|
2020-01-02 11:03:13 -05:00
|
|
|
result6 = described_class.check_url('invalid$protocol://www.discourse.org', "invalid$protocol://www.discourse.org")
|
|
|
|
expect(result6).to eq(false)
|
2019-12-12 21:12:12 -05:00
|
|
|
|
2020-01-02 11:03:13 -05:00
|
|
|
result7 = described_class.check_url('noscheme', "noscheme")
|
|
|
|
expect(result7).to eq(false)
|
2019-12-12 21:12:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|