authlete 1.6.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2021 Authlete, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+
18
+ require 'authlete'
19
+ require 'json'
20
+ require 'minitest/autorun'
21
+
22
+
23
+ class HskTest < Minitest::Test
24
+ KTY = 'EC'
25
+ USE = 'sig'
26
+ ALG = 'ES256'
27
+ KID = 'jane'
28
+ HSM_NAME = 'google'
29
+ HANDLE = '<handle>'
30
+ PUBLIC_KEY = '<public-key>'
31
+
32
+
33
+ def generate_json
34
+ return <<~JSON
35
+ {
36
+ "kty": "EC",
37
+ "use": "sig",
38
+ "alg": "ES256",
39
+ "kid": "jane",
40
+ "hsmName": "google",
41
+ "handle": "<handle>",
42
+ "publicKey": "<public-key>"
43
+ }
44
+ JSON
45
+ end
46
+
47
+
48
+ def generate_hash
49
+ {
50
+ kty: 'EC',
51
+ use: 'sig',
52
+ alg: 'ES256',
53
+ kid: 'jane',
54
+ hsmName: 'google',
55
+ handle: '<handle>',
56
+ publicKey: '<public-key>'
57
+ }
58
+ end
59
+
60
+
61
+ def set_params(obj)
62
+ obj.kty = KTY
63
+ obj.use = USE
64
+ obj.alg = ALG
65
+ obj.kid = KID
66
+ obj.hsmName = HSM_NAME
67
+ obj.handle = HANDLE
68
+ obj.publicKey = PUBLIC_KEY
69
+ end
70
+
71
+
72
+ def match(obj)
73
+ assert_equal KTY, obj.kty
74
+ assert_equal USE, obj.use
75
+ assert_equal ALG, obj.alg
76
+ assert_equal KID, obj.kid
77
+ assert_equal HSM_NAME, obj.hsmName
78
+ assert_equal HANDLE, obj.handle
79
+ assert_equal PUBLIC_KEY, obj.publicKey
80
+ end
81
+
82
+
83
+ def test_from_json
84
+ jsn = generate_json
85
+ hsh = JSON.parse(jsn)
86
+ actual = Authlete::Model::Hsk.new(hsh)
87
+
88
+ match(actual)
89
+ end
90
+
91
+
92
+ def test_setters
93
+ actual = Authlete::Model::Hsk.new
94
+ set_params(actual)
95
+
96
+ match(actual)
97
+ end
98
+
99
+
100
+ def test_to_hash
101
+ obj = Authlete::Model::Hsk.new
102
+ set_params(obj)
103
+ actual = obj.to_hash
104
+ expected = generate_hash
105
+
106
+ assert_equal expected, actual
107
+ end
108
+ end