Sha256: 43bfd88550f5f7e98252a2b8cb01c94f88034c7a9667c87374d5794d4b4ff491

Contents?: true

Size: 1.47 KB

Versions: 19

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true
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

19 entries across 19 versions & 1 rubygems

Version Path
secure_headers-5.2.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-5.1.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-6.0.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-6.0.0.alpha03 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-6.0.0.alpha02 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-6.0.0.alpha01 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-5.0.5 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-5.0.4 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-5.0.3 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-5.0.2 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-4.0.2 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-5.0.1 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-5.0.0.alpha01 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-4.0.1 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-4.0.0 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-4.0.0.alpha04 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-4.0.0.alpha03 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-4.0.0.alpha02 spec/lib/secure_headers/headers/public_key_pins_spec.rb
secure_headers-4.0.0.alpha01 spec/lib/secure_headers/headers/public_key_pins_spec.rb