File: clear_site_data_spec.rb

package info (click to toggle)
ruby-secure-headers 7.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 508 kB
  • sloc: ruby: 3,353; makefile: 5
file content (87 lines) | stat: -rw-r--r-- 2,388 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# frozen_string_literal: true
require "spec_helper"

module SecureHeaders
  describe ClearSiteData do
    describe "make_header" do
      it "returns nil with nil config" do
        expect(described_class.make_header).to be_nil
      end

      it "returns nil with empty config" do
        expect(described_class.make_header([])).to be_nil
      end

      it "returns nil with opt-out config" do
        expect(described_class.make_header(OPT_OUT)).to be_nil
      end

      it "returns all types with `true` config" do
        name, value = described_class.make_header(true)

        expect(name).to eq(ClearSiteData::HEADER_NAME)
        expect(value).to eq(
          %("cache", "cookies", "storage", "executionContexts")
        )
      end

      it "returns specified types" do
        name, value = described_class.make_header(["foo", "bar"])

        expect(name).to eq(ClearSiteData::HEADER_NAME)
        expect(value).to eq(%("foo", "bar"))
      end
    end

    describe "validate_config!" do
      it "succeeds for `true` config" do
        expect do
          described_class.validate_config!(true)
        end.not_to raise_error
      end

      it "succeeds for `nil` config" do
        expect do
          described_class.validate_config!(nil)
        end.not_to raise_error
      end

      it "succeeds for opt-out config" do
        expect do
          described_class.validate_config!(OPT_OUT)
        end.not_to raise_error
      end

      it "succeeds for empty config" do
        expect do
          described_class.validate_config!([])
        end.not_to raise_error
      end

      it "succeeds for Array of Strings config" do
        expect do
          described_class.validate_config!(["foo"])
        end.not_to raise_error
      end

      it "fails for Array of non-String config" do
        expect do
          described_class.validate_config!([1])
        end.to raise_error(ClearSiteDataConfigError)
      end

      it "fails for other types of config" do
        expect do
          described_class.validate_config!(:cookies)
        end.to raise_error(ClearSiteDataConfigError)
      end
    end

    describe "make_header_value" do
      it "returns a string of quoted values that are comma separated" do
        value = described_class.make_header_value(["foo", "bar"])
        expect(value).to eq(%("foo", "bar"))
      end
    end
  end
end