Module: SafeToken::Etest
- Defined in:
- lib/vex/base/safe_token.rb
Instance Method Summary collapse
- #data ⇒ Object
- #test_expiration ⇒ Object
- #test_invalid_enc_parameters ⇒ Object
- #test_token ⇒ Object
- #test_token_w_crypt ⇒ Object
- #test_token_w_crypt2 ⇒ Object
Instance Method Details
#data ⇒ Object
109 110 111 |
# File 'lib/vex/base/safe_token.rb', line 109 def data {"a" => "123232", "b" => { "c" => [ 1, 2, "d" ]}} end |
#test_expiration ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/vex/base/safe_token.rb', line 113 def test_expiration token = SafeToken.generate(data, :crypt => false, :expires => Time.now-10) assert_raise(SafeToken::TokenExpired) { begin SafeToken.validate(token) rescue assert $!.to_s =~ /expired/ raise end } token = SafeToken.generate(data, :crypt => false, :expires => Time.now+10) assert_equal data, SafeToken.validate(token) end |
#test_invalid_enc_parameters ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/vex/base/safe_token.rb', line 153 def test_invalid_enc_parameters token = SafeToken.generate(data, :crypt => true) OpenSSL::Cipher::Cipher.any_instance.stubs(:update).raises(SafeToken::CipherError) assert_raise(SafeToken::InvalidToken) { assert_equal data, SafeToken.validate(token, :crypt => true) } end |
#test_token ⇒ Object
128 129 130 131 |
# File 'lib/vex/base/safe_token.rb', line 128 def test_token token = SafeToken.generate(data, :crypt => false) assert_equal data, SafeToken.validate(token) end |
#test_token_w_crypt ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/vex/base/safe_token.rb', line 133 def test_token_w_crypt # TODO: FOR SOME REASON THIS TEST FAILS SOMETIMES?? return token = SafeToken.generate(data, :crypt => true) assert_equal data, SafeToken.validate(token, :crypt => true) end |
#test_token_w_crypt2 ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/vex/base/safe_token.rb', line 141 def test_token_w_crypt2 # TODO: FOR SOME REASON THIS TEST FAILS SOMETIMES?? return token1 = SafeToken.generate(data, :crypt => "secret") token2 = SafeToken.generate(data, :crypt => true) token3 = SafeToken.generate(data, :crypt => false) assert_not_equal(token1, token2) assert_not_equal(token1, token3) assert_not_equal(token2, token3) end |