2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe WildcardDomainChecker do
|
2022-07-27 12:14:14 -04:00
|
|
|
describe ".check_domain" do
|
|
|
|
context "when domain is valid" do
|
2018-10-15 01:03:53 -04:00
|
|
|
it "returns correct domain" do
|
|
|
|
result1 =
|
|
|
|
WildcardDomainChecker.check_domain(
|
|
|
|
"*.discourse.org",
|
|
|
|
"anything.is.possible.discourse.org",
|
|
|
|
)
|
|
|
|
expect(result1[0]).to eq("anything.is.possible.discourse.org")
|
2023-01-09 06:18:21 -05:00
|
|
|
|
2018-10-15 01:03:53 -04:00
|
|
|
result2 = WildcardDomainChecker.check_domain("www.discourse.org", "www.discourse.org")
|
|
|
|
expect(result2[0]).to eq("www.discourse.org")
|
2023-01-09 06:18:21 -05:00
|
|
|
|
2018-10-15 01:03:53 -04:00
|
|
|
result3 = WildcardDomainChecker.check_domain("*", "hello.discourse.org")
|
|
|
|
expect(result3[0]).to eq("hello.discourse.org")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when domain is invalid" do
|
2018-10-15 01:03:53 -04:00
|
|
|
it "doesn't return the domain" do
|
|
|
|
result1 =
|
|
|
|
WildcardDomainChecker.check_domain("*.discourse.org", "bad-domain.discourse.org.evil.com")
|
|
|
|
expect(result1).to eq(nil)
|
|
|
|
|
|
|
|
result2 =
|
|
|
|
WildcardDomainChecker.check_domain("www.discourse.org", "www.discourse.org.evil.com")
|
|
|
|
expect(result2).to eq(nil)
|
|
|
|
|
|
|
|
result3 = WildcardDomainChecker.check_domain("www.discourse.org", "www.www.discourse.org")
|
|
|
|
expect(result3).to eq(nil)
|
|
|
|
|
|
|
|
result4 = WildcardDomainChecker.check_domain("www.*.discourse.org", "www.www.discourse.org")
|
|
|
|
expect(result4).to eq(nil)
|
2019-12-12 21:12:12 -05:00
|
|
|
|
|
|
|
result5 =
|
|
|
|
WildcardDomainChecker.check_domain(
|
|
|
|
"www.discourse.org",
|
|
|
|
"www.discourse.org\nwww.discourse.org.evil.com",
|
|
|
|
)
|
|
|
|
expect(result5).to eq(nil)
|
2018-10-15 01:03:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|