Sha256: c4db5bd0f99199995d4d837448c431afc9f531b9c436c2a7d84c397e577f128c

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

module SecureHeaders
  describe XXssProtection do
    specify { expect(XXssProtection.new.name).to eq(X_XSS_PROTECTION_HEADER_NAME)}
    specify { expect(XXssProtection.new.value).to eq("1")}
    specify { expect(XXssProtection.new("0").value).to eq("0")}
    specify { expect(XXssProtection.new(:value => 1, :mode => 'block').value).to eq('1; mode=block') }
    specify { expect(XXssProtection.new(:value => 1, :mode => 'block', :report_uri => 'https://www.secure.com/reports').value).to eq('1; mode=block; report=https://www.secure.com/reports') }

    context "with invalid configuration" do
      it "should raise an error when providing a string that is not valid" do
        expect {
          XXssProtection.new("asdf")
        }.to raise_error(XXssProtectionBuildError)

        expect {
          XXssProtection.new("asdf; mode=donkey")
        }.to raise_error(XXssProtectionBuildError)
      end

      context "when using a hash value" do
        it "should allow string values ('1' or '0' are the only valid strings)" do
          expect {
            XXssProtection.new(:value => '1')
          }.not_to raise_error
        end

        it "should allow integer values (1 or 0 are the only valid integers)" do
          expect {
            XXssProtection.new(:value => 1)
          }.not_to raise_error
        end

        it "should raise an error if no value key is supplied" do
          expect {
            XXssProtection.new(:mode => 'block')
          }.to raise_error(XXssProtectionBuildError)
        end

        it "should raise an error if an invalid key is supplied" do
          expect {
            XXssProtection.new(:value => 123)
          }.to raise_error(XXssProtectionBuildError)
        end

        it "should raise an error if mode != block" do
          expect {
            XXssProtection.new(:value => 1, :mode => "donkey")
          }.to raise_error(XXssProtectionBuildError)
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
secure_headers-2.5.3 spec/lib/secure_headers/headers/x_xss_protection_spec.rb
secure_headers-2.5.2 spec/lib/secure_headers/headers/x_xss_protection_spec.rb
secure_headers-2.5.1 spec/lib/secure_headers/headers/x_xss_protection_spec.rb
secure_headers-2.5.0 spec/lib/secure_headers/headers/x_xss_protection_spec.rb