discourse/plugins/discourse-narrative-bot/spec/lib/certificate_generator_spec.rb
Roman Rizzi 835d2be4da
FIX: Rate limit and hijack certificate generation. (#8215)
To eliminate a DDOS attack vector, we're taking the following measures:

The endpoint will be rate-limited to 3 requests every 60 seconds (per user).
A 24 hours max-age cache header is sent with the response.
The route will be hijacked to generate the certificate in the background.
2019-10-21 13:14:15 -03:00

30 lines
810 B
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe DiscourseNarrativeBot::CertificateGenerator do
let(:user) { Fabricate(:user) }
let(:avatar_url) { 'http://test.localhost/cdn/avatar.png' }
let(:date) { "2017-00-10" }
describe 'when an invalid date is given' do
it 'should default to the current date' do
expect { described_class.new(user, date, avatar_url) }.to_not raise_error
end
end
describe '#logo_group' do
describe 'when SiteSetting.site_logo_small_url is blank' do
before do
SiteSetting.logo_small = ''
SiteSetting.logo_small_url = ''
end
it 'should not try to fetch a image' do
expect(described_class.new(user, date, avatar_url).send(:logo_group, 1, 1, 1))
.to eq(nil)
end
end
end
end