Sha256: 8fa14e624c9a27c6e635e1353877be29ff4ee57348fada26c3ce396176a18fb2

Contents?: true

Size: 1.44 KB

Versions: 36

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

module SecureHeaders
  describe PublicKeyPins do
    specify { expect(PublicKeyPins.new(max_age: 1234, report_only: true).name).to eq("Public-Key-Pins-Report-Only") }
    specify { expect(PublicKeyPins.new(max_age: 1234).name).to eq("Public-Key-Pins") }

    specify { expect(PublicKeyPins.new(max_age: 1234).value).to eq("max-age=1234") }
    specify { expect(PublicKeyPins.new(max_age: 1234).value).to eq("max-age=1234") }
    specify do
      config = { max_age: 1234, pins: [{ sha256: 'base64encodedpin1' }, { sha256: 'base64encodedpin2' }] }
      header_value = "max-age=1234; pin-sha256=\"base64encodedpin1\"; pin-sha256=\"base64encodedpin2\""
      expect(PublicKeyPins.new(config).value).to eq(header_value)
    end

    context "with an invalid configuration" do
      it "raises an exception when max-age is not provided" do
        expect do
          PublicKeyPins.validate_config!(foo: 'bar')
        end.to raise_error(PublicKeyPinsConfigError)
      end

      it "raises an exception with an invalid max-age" do
        expect do
          PublicKeyPins.validate_config!(max_age: 'abc123')
        end.to raise_error(PublicKeyPinsConfigError)
      end

      it 'raises an exception with less than 2 pins' do
        expect do
          config = { max_age: 1234, pins: [{ sha256: 'base64encodedpin' }] }
          PublicKeyPins.validate_config!(config)
        end.to raise_error(PublicKeyPinsConfigError)
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
secure_headers-3.9.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.8.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.7.4 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.7.3 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.7.2 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.7.1 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.7.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.6.7 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.6.6 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.6.5 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.6.4 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.6.3 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.6.2 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.6.1 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.6.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.5.1 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.5.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.5.0.pre spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.4.1 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-3.4.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb