mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 20:34:26 +08:00
50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe "Discobot Certificate" do
|
|
let(:user) { Fabricate(:user, name: 'Jeff Atwood') }
|
|
|
|
describe 'when viewing the certificate' do
|
|
it 'should return the right text' do
|
|
params = {
|
|
date: Time.zone.now.strftime("%b %d %Y"),
|
|
user_id: user.id
|
|
}
|
|
|
|
stub_request(:get, /letter_avatar_proxy/).to_return(status: 200)
|
|
|
|
stub_request(:get, "http://test.localhost//images/d-logo-sketch-small.png")
|
|
.to_return(status: 200)
|
|
|
|
xhr :get, '/discobot/certificate.svg', params
|
|
|
|
expect(response.status).to eq(200)
|
|
end
|
|
|
|
describe 'when params are missing' do
|
|
it "should raise the right errors" do
|
|
params = {
|
|
date: Time.zone.now.strftime("%b %d %Y"),
|
|
user_id: user.id
|
|
}
|
|
|
|
params.each do |key, _|
|
|
expect { xhr :get, '/discobot/certificate.svg', params.except(key) }
|
|
.to raise_error(Discourse::InvalidParameters)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'when date is invalid' do
|
|
it 'should raise the right error' do
|
|
expect do
|
|
xhr :get, '/discobot/certificate.svg',
|
|
name: user.name,
|
|
date: "<script type=\"text/javascript\">alert('This app is probably vulnerable to XSS attacks!');</script>",
|
|
avatar_url: 'https://somesite.com/someavatar',
|
|
user_id: user.id
|
|
end.to raise_error(ArgumentError, 'invalid date')
|
|
end
|
|
end
|
|
end
|
|
end
|