Class: Authlogic::TestCase::MockSignedCookieJar

Inherits:
MockCookieJar
  • Object
show all
Defined in:
lib/authlogic/test_case/mock_cookie_jar.rb

Overview

A mock of `ActionDispatch::Cookies::SignedKeyRotatingCookieJar`

> .. a jar that'll automatically generate a signed representation of > cookie value and verify it when reading from the cookie again. > actionpack/lib/action_dispatch/middleware/cookies.rb

Instance Attribute Summary collapse

Attributes inherited from MockCookieJar

#set_cookies

Instance Method Summary collapse

Methods inherited from MockCookieJar

#delete, #encrypted, #signed

Constructor Details

#initialize(parent_jar) ⇒ MockSignedCookieJar

Returns a new instance of MockSignedCookieJar.


40
41
42
43
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 40

def initialize(parent_jar)
  @parent_jar = parent_jar
  parent_jar.each { |k, v| self[k] = v }
end

Instance Attribute Details

#parent_jarObject (readonly)

helper for testing


38
39
40
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 38

def parent_jar
  @parent_jar
end

Instance Method Details

#[](val) ⇒ Object


45
46
47
48
49
50
51
52
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 45

def [](val)
  signed_message = @parent_jar[val]
  if signed_message
    payload, signature = signed_message.split("--")
    raise "Invalid signature" unless Digest::SHA1.hexdigest(payload) == signature
    payload
  end
end

#[]=(key, options) ⇒ Object


54
55
56
57
# File 'lib/authlogic/test_case/mock_cookie_jar.rb', line 54

def []=(key, options)
  options[:value] = "#{options[:value]}--#{Digest::SHA1.hexdigest options[:value]}"
  @parent_jar[key] = options
end