Fix invalid artist URLs being allowed

The problem was that the Addressable parser does not catch all invalid
URL cases, so some extra checks were added in.

- hostname must contain a dot

This accounts for URLs of the following type:

http://http://something.com

which has a hostname of http.

The artist URL tests were also updated with cases which test all validation
errors.
This commit is contained in:
BrokenEagle
2020-05-29 22:33:46 +00:00
parent 364343453c
commit c21af0c853
2 changed files with 21 additions and 4 deletions

View File

@@ -24,10 +24,18 @@ class ArtistUrlTest < ActiveSupport::TestCase
end
should "disallow invalid urls" do
url = FactoryBot.build(:artist_url, url: "www.example.com")
urls = [
FactoryBot.build(:artist_url, url: "www.example.com"),
FactoryBot.build(:artist_url, url: ":www.example.com"),
FactoryBot.build(:artist_url, url: "http://http://www.example.com"),
]
assert_equal(false, url.valid?)
assert_match(/must begin with http/, url.errors.full_messages.join)
assert_equal(false, urls[0].valid?)
assert_match(/must begin with http/, urls[0].errors.full_messages.join)
assert_equal(false, urls[1].valid?)
assert_match(/is malformed/, urls[1].errors.full_messages.join)
assert_equal(false, urls[2].valid?)
assert_match(/that does not contain a dot/, urls[2].errors.full_messages.join)
end
should "always add a trailing slash when normalized" do