2022-07-31 08:56:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-02-05 07:32:44 -05:00
|
|
|
RSpec.describe Rack::Protection::StrictTransport do
|
2022-07-31 08:56:44 -04:00
|
|
|
it_behaves_like 'any rack application'
|
2016-01-18 06:40:35 -05:00
|
|
|
|
|
|
|
it 'should set the Strict-Transport-Security header' do
|
2022-07-31 08:56:44 -04:00
|
|
|
expect(get('/', {}, 'wants' => 'text/html').headers['Strict-Transport-Security']).to eq('max-age=31536000')
|
2016-01-18 06:40:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should allow changing the max-age option' do
|
|
|
|
mock_app do
|
2022-07-31 08:56:44 -04:00
|
|
|
use Rack::Protection::StrictTransport, max_age: 16_070_400
|
2016-01-18 06:40:35 -05:00
|
|
|
run DummyApp
|
|
|
|
end
|
|
|
|
|
2022-07-31 08:56:44 -04:00
|
|
|
expect(get('/', {}, 'wants' => 'text/html').headers['Strict-Transport-Security']).to eq('max-age=16070400')
|
2016-01-18 06:40:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should allow switching on the include_subdomains option' do
|
|
|
|
mock_app do
|
2022-07-31 08:56:44 -04:00
|
|
|
use Rack::Protection::StrictTransport, include_subdomains: true
|
2016-01-18 06:40:35 -05:00
|
|
|
run DummyApp
|
|
|
|
end
|
|
|
|
|
2022-07-31 08:56:44 -04:00
|
|
|
expect(get('/', {}, 'wants' => 'text/html').headers['Strict-Transport-Security']).to eq('max-age=31536000; includeSubDomains')
|
2016-01-18 06:40:35 -05:00
|
|
|
end
|
2016-11-26 11:05:55 -05:00
|
|
|
|
|
|
|
it 'should allow switching on the preload option' do
|
|
|
|
mock_app do
|
2022-07-31 08:56:44 -04:00
|
|
|
use Rack::Protection::StrictTransport, preload: true
|
2016-11-26 11:05:55 -05:00
|
|
|
run DummyApp
|
|
|
|
end
|
|
|
|
|
2022-07-31 08:56:44 -04:00
|
|
|
expect(get('/', {}, 'wants' => 'text/html').headers['Strict-Transport-Security']).to eq('max-age=31536000; preload')
|
2016-11-26 11:05:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should allow switching on all the options' do
|
|
|
|
mock_app do
|
2022-07-31 08:56:44 -04:00
|
|
|
use Rack::Protection::StrictTransport, preload: true, include_subdomains: true
|
2016-11-26 11:05:55 -05:00
|
|
|
run DummyApp
|
|
|
|
end
|
|
|
|
|
2022-07-31 08:56:44 -04:00
|
|
|
expect(get('/', {}, 'wants' => 'text/html').headers['Strict-Transport-Security']).to eq('max-age=31536000; includeSubDomains; preload')
|
2016-11-26 11:05:55 -05:00
|
|
|
end
|
2016-01-18 06:40:35 -05:00
|
|
|
end
|