Class: MemCacheStoreTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/plugins/open_id_authentication/test/mem_cache_store_test.rb

Constant Summary collapse

ALLOWED_HANDLE =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>[email protected][\\]^_`{|}~'

Instance Method Summary collapse

Instance Method Details

#setupObject


14
15
16
# File 'lib/plugins/open_id_authentication/test/mem_cache_store_test.rb', line 14

def setup
  @store = OpenIdAuthentication::MemCacheStore.new
end

#test_nonceObject


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/plugins/open_id_authentication/test/mem_cache_store_test.rb', line 106

def test_nonce
  server_url = "http://www.myopenid.com/openid"

  [server_url, ''].each do |url|
    nonce1 = OpenID::Nonce::mk_nonce

    assert_nonce(nonce1, true, url, "#{url}: nonce allowed by default")
    assert_nonce(nonce1, false, url, "#{url}: nonce not allowed twice")
    assert_nonce(nonce1, false, url, "#{url}: nonce not allowed third time")

    # old nonces shouldn't pass
    old_nonce = OpenID::Nonce::mk_nonce(3600)
    assert_nonce(old_nonce, false, url, "Old nonce #{old_nonce.inspect} passed")
  end
end

#test_storeObject


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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/plugins/open_id_authentication/test/mem_cache_store_test.rb', line 18

def test_store
  server_url = "http://www.myopenid.com/openid"
  assoc = gen_assoc(0)

  # Make sure that a missing association returns no result
  assert_retrieve(server_url)

  # Check that after storage, getting returns the same result
  @store.store_association(server_url, assoc)
  assert_retrieve(server_url, nil, assoc)

  # more than once
  assert_retrieve(server_url, nil, assoc)

  # Storing more than once has no ill effect
  @store.store_association(server_url, assoc)
  assert_retrieve(server_url, nil, assoc)

  # Removing an association that does not exist returns not present
  assert_remove(server_url, assoc.handle + 'x', false)

  # Removing an association that does not exist returns not present
  assert_remove(server_url + 'x', assoc.handle, false)

  # Removing an association that is present returns present
  assert_remove(server_url, assoc.handle, true)

  # but not present on subsequent calls
  assert_remove(server_url, assoc.handle, false)

  # Put assoc back in the store
  @store.store_association(server_url, assoc)

  # More recent and expires after assoc
  assoc2 = gen_assoc(1)
  @store.store_association(server_url, assoc2)

  # After storing an association with a different handle, but the
  # same server_url, the handle with the later expiration is returned.
  assert_retrieve(server_url, nil, assoc2)

  # We can still retrieve the older association
  assert_retrieve(server_url, assoc.handle, assoc)

  # Plus we can retrieve the association with the later expiration
  # explicitly
  assert_retrieve(server_url, assoc2.handle, assoc2)

  # More recent, and expires earlier than assoc2 or assoc. Make sure
  # that we're picking the one with the latest issued date and not
  # taking into account the expiration.
  assoc3 = gen_assoc(2, 100)
  @store.store_association(server_url, assoc3)

  assert_retrieve(server_url, nil, assoc3)
  assert_retrieve(server_url, assoc.handle, assoc)
  assert_retrieve(server_url, assoc2.handle, assoc2)
  assert_retrieve(server_url, assoc3.handle, assoc3)

  assert_remove(server_url, assoc2.handle, true)

  assert_retrieve(server_url, nil, assoc3)
  assert_retrieve(server_url, assoc.handle, assoc)
  assert_retrieve(server_url, assoc2.handle, nil)
  assert_retrieve(server_url, assoc3.handle, assoc3)

  assert_remove(server_url, assoc2.handle, false)
  assert_remove(server_url, assoc3.handle, true)

  assert_retrieve(server_url, nil, assoc)
  assert_retrieve(server_url, assoc.handle, assoc)
  assert_retrieve(server_url, assoc2.handle, nil)
  assert_retrieve(server_url, assoc3.handle, nil)

  assert_remove(server_url, assoc2.handle, false)
  assert_remove(server_url, assoc.handle, true)
  assert_remove(server_url, assoc3.handle, false)

  assert_retrieve(server_url, nil, nil)
  assert_retrieve(server_url, assoc.handle, nil)
  assert_retrieve(server_url, assoc2.handle, nil)
  assert_retrieve(server_url, assoc3.handle, nil)

  assert_remove(server_url, assoc2.handle, false)
  assert_remove(server_url, assoc.handle, false)
  assert_remove(server_url, assoc3.handle, false)
end