forked from glitch-soc/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate allowed schemes on preview card URLs (mastodon#27485)
- Loading branch information
1 parent
9d45a44
commit b021347
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe PreviewCard do | ||
describe 'validations' do | ||
describe 'urls' do | ||
it 'allows http schemes' do | ||
record = described_class.new(url: 'http://example.host/path') | ||
|
||
expect(record).to be_valid | ||
end | ||
|
||
it 'allows https schemes' do | ||
record = described_class.new(url: 'https://example.host/path') | ||
|
||
expect(record).to be_valid | ||
end | ||
|
||
it 'does not allow javascript: schemes' do | ||
record = described_class.new(url: 'javascript:alert()') | ||
|
||
expect(record).to_not be_valid | ||
expect(record).to model_have_error_on_field(:url) | ||
end | ||
end | ||
end | ||
end |