entp-multipass 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/multipass.rb +2 -21
- data/test/multipass_test.rb +5 -5
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/multipass.rb
CHANGED
@@ -43,13 +43,13 @@ class MultiPass
|
|
43
43
|
when Time, DateTime, Date then options[:expires].to_s
|
44
44
|
else options[:expires].to_s
|
45
45
|
end
|
46
|
-
|
46
|
+
@crypto_key.encrypt64(options.to_json)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Decrypts the given multipass string and parses it as JSON. Then, it checks
|
50
50
|
# for a valid expiration date.
|
51
51
|
def decode(data)
|
52
|
-
json = @crypto_key.decrypt64(
|
52
|
+
json = @crypto_key.decrypt64(data)
|
53
53
|
|
54
54
|
if json.nil?
|
55
55
|
raise MultiPass::DecryptError
|
@@ -89,23 +89,4 @@ private
|
|
89
89
|
raise MultiPass::JSONError
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
93
|
-
if Object.const_defined?(:Rack)
|
94
|
-
def escape_value(s)
|
95
|
-
Rack::Utils.escape(s)
|
96
|
-
end
|
97
|
-
|
98
|
-
def unescape_value(s)
|
99
|
-
Rack::Utils.unescape(s)
|
100
|
-
end
|
101
|
-
else
|
102
|
-
require 'cgi'
|
103
|
-
def escape_value(s)
|
104
|
-
CGI.escape(s)
|
105
|
-
end
|
106
|
-
|
107
|
-
def unescape_value(s)
|
108
|
-
CGI.unescape(s)
|
109
|
-
end
|
110
|
-
end
|
111
92
|
end
|
data/test/multipass_test.rb
CHANGED
@@ -14,12 +14,12 @@ class MultiPassTest < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
def test_encodes_multipass
|
16
16
|
expected = @key.encrypt64(@output.to_json)
|
17
|
-
assert_equal
|
17
|
+
assert_equal expected, @mp.encode(@input)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_encodes_multipass_with_class_method
|
21
21
|
expected = @key.encrypt64(@output.to_json)
|
22
|
-
assert_equal
|
22
|
+
assert_equal expected, MultiPass.encode('example', 'abc', @input)
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_decodes_multipass
|
@@ -40,15 +40,15 @@ class MultiPassTest < Test::Unit::TestCase
|
|
40
40
|
|
41
41
|
def test_invalidates_bad_json
|
42
42
|
assert_raises MultiPass::JSONError do
|
43
|
-
@mp.decode(
|
43
|
+
@mp.decode(@key.encrypt64("abc"))
|
44
44
|
end
|
45
45
|
assert_raises MultiPass::JSONError do
|
46
|
-
@mp.decode(
|
46
|
+
@mp.decode(@key.encrypt64("{a"))
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_invalidates_old_expiration
|
51
|
-
encrypted =
|
51
|
+
encrypted = @key.encrypt64(@input.merge(:expires => (Time.now - 1)).to_json)
|
52
52
|
assert_raises MultiPass::ExpiredError do
|
53
53
|
@mp.decode(encrypted)
|
54
54
|
end
|