Sha256: f3ab902131a032f0b6fc5530dd9343002e17d5f97f986e97e86e3a345fb66e0a

Contents?: true

Size: 1.93 KB

Versions: 30

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true
require "spec_helper"

module SecureHeaders
  describe ExpectCertificateTransparency do
    specify { expect(ExpectCertificateTransparency.new(max_age: 1234, enforce: true).value).to eq("enforce, max-age=1234") }
    specify { expect(ExpectCertificateTransparency.new(max_age: 1234, enforce: false).value).to eq("max-age=1234") }
    specify { expect(ExpectCertificateTransparency.new(max_age: 1234, enforce: "yolocopter").value).to eq("max-age=1234") }
    specify { expect(ExpectCertificateTransparency.new(max_age: 1234, report_uri: "https://report-uri.io/expect-ct").value).to eq("max-age=1234, report-uri=\"https://report-uri.io/expect-ct\"") }
    specify do
      config = { enforce: true, max_age: 1234, report_uri: "https://report-uri.io/expect-ct" }
      header_value = "enforce, max-age=1234, report-uri=\"https://report-uri.io/expect-ct\""
      expect(ExpectCertificateTransparency.new(config).value).to eq(header_value)
    end

    context "with an invalid configuration" do
      it "raises an exception when configuration isn't a hash" do
        expect do
          ExpectCertificateTransparency.validate_config!(%w(a))
        end.to raise_error(ExpectCertificateTransparencyConfigError)
      end

      it "raises an exception when max-age is not provided" do
        expect do
          ExpectCertificateTransparency.validate_config!(foo: "bar")
        end.to raise_error(ExpectCertificateTransparencyConfigError)
      end

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

      it "raises an exception with an invalid enforce value" do
        expect do
          ExpectCertificateTransparency.validate_config!(enforce: "brokenstring")
        end.to raise_error(ExpectCertificateTransparencyConfigError)
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
secure_headers-7.0.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.7.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.6.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.5.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.4.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.3.4 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.3.3 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.3.2 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.3.1 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-5.2.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-3.9.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.3.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-5.1.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-3.8.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.2.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-3.7.4 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.1.2 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.1.1 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.1.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb
secure_headers-6.0.0 spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb