Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cookies_helper_spec.rb « helpers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c73e7d64987e66e140343c852a103f35e60a960b (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe CookiesHelper do
  describe '#set_secure_cookie' do
    it 'creates an encrypted cookie with expected attributes' do
      stub_config_setting(https: true)
      expiration = 1.month.from_now
      key = :secure_cookie
      value = 'secure value'

      expect_next_instance_of(ActionDispatch::Cookies::EncryptedKeyRotatingCookieJar) do |instance|
        expect(instance).to receive(:[]=).with(key, httponly: true, secure: true, expires: expiration, value: value)
      end

      helper.set_secure_cookie(key, value, httponly: true, expires: expiration, type: CookiesHelper::COOKIE_TYPE_ENCRYPTED)
    end

    it 'creates a permanent cookie with expected attributes' do
      key = :permanent_cookie
      value = 'permanent value'

      expect_next_instance_of(ActionDispatch::Cookies::PermanentCookieJar) do |instance|
        expect(instance).to receive(:[]=).with(key, httponly: false, secure: false, expires: nil, value: value)
      end

      helper.set_secure_cookie(key, value, type: CookiesHelper::COOKIE_TYPE_PERMANENT)
    end

    it 'creates a regular cookie with expected attributes' do
      key = :regular_cookie
      value = 'regular value'

      expect_next_instance_of(ActionDispatch::Cookies::CookieJar) do |instance|
        expect(instance).to receive(:[]=).with(key, httponly: false, secure: false, expires: nil, value: value)
      end

      helper.set_secure_cookie(key, value)
    end
  end
end