lyrebird 1.0.1 → 2.0.0

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.
@@ -1,353 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module Lyrebird
6
- class AssertionTest < Minitest::Test
7
- NS = { "saml" => SAML_ASSERTION_NS }.freeze
8
-
9
- def setup
10
- unless defined?(@@assertion)
11
- @@assertion = Assertion.new.document
12
- @@root = @@assertion.root
13
- @@subject = @@root.at_xpath("saml:Subject", NS)
14
- @@sc = @@subject.at_xpath("saml:SubjectConfirmation", NS)
15
- @@scd = @@sc.at_xpath("saml:SubjectConfirmationData", NS)
16
- @@conditions = @@root.at_xpath("saml:Conditions", NS)
17
- @@audience_restriction = @@conditions.at_xpath("saml:AudienceRestriction", NS)
18
- @@authn_statement = @@root.at_xpath("saml:AuthnStatement", NS)
19
- end
20
-
21
- @assertion = @@assertion
22
- @root = @@root
23
- @subject = @@subject
24
- @sc = @@sc
25
- @scd = @@scd
26
- @conditions = @@conditions
27
- @audience_restriction = @@audience_restriction
28
- @authn_statement = @@authn_statement
29
- end
30
-
31
- def test_root_name
32
- assert_equal "Assertion", @root.name
33
- assert_equal "saml", @root.namespace.prefix
34
- end
35
-
36
- def test_document_is_memoized
37
- assertion = Assertion.new
38
- assert_same assertion.document, assertion.document
39
- end
40
-
41
- def test_root_namespace
42
- assert_equal SAML_ASSERTION_NS, @root.namespace.href
43
- end
44
-
45
- def test_root_id
46
- assert @root["ID"].start_with?("_")
47
- end
48
-
49
- def test_root_version
50
- assert_equal "2.0", @root["Version"]
51
- end
52
-
53
- def test_root_issue_instant
54
- instant = Time.iso8601(@root["IssueInstant"])
55
- assert_in_delta Time.now.to_i, instant.to_i, 1
56
- end
57
-
58
- def test_issuer
59
- issuer = @root.at_xpath("saml:Issuer", NS)
60
- assert_equal "Issuer", issuer.name
61
- assert_equal "saml", issuer.namespace.prefix
62
- assert_equal DEFAULTS.issuer, issuer.text
63
- end
64
-
65
- def test_issuer_override
66
- assertion = Assertion.new(issuer: "https://test.example.com").document
67
- issuer = assertion.root.at_xpath("saml:Issuer", NS)
68
- assert_equal "https://test.example.com", issuer.text
69
- end
70
-
71
- def test_subject
72
- assert_equal "Subject", @subject.name
73
- assert_equal "saml", @subject.namespace.prefix
74
- end
75
-
76
- def test_name_id
77
- name_id = @subject.at_xpath("saml:NameID", NS)
78
- assert_equal "NameID", name_id.name
79
- assert_equal "saml", name_id.namespace.prefix
80
- assert_equal DEFAULTS.name_id, name_id.text
81
- end
82
-
83
- def test_name_id_format_default
84
- name_id = @subject.at_xpath("saml:NameID", NS)
85
- assert_equal NAMEID_EMAIL, name_id["Format"]
86
- end
87
-
88
- def test_name_id_override
89
- email = "user@test.com"
90
- refute_equal email, DEFAULTS.name_id
91
- assertion = Assertion.new(name_id: email).document
92
- name_id = assertion.root.at_xpath("saml:Subject/saml:NameID", NS)
93
- assert_equal email, name_id.text
94
- end
95
-
96
- def test_name_id_format_override
97
- format = NAMEID_PERSISTENT
98
- refute_equal format, DEFAULTS.name_id_format
99
- assertion = Assertion.new(name_id_format: format).document
100
- name_id = assertion.root.at_xpath("saml:Subject/saml:NameID", NS)
101
- assert_equal format, name_id["Format"]
102
- end
103
-
104
- def test_subject_confirmation
105
- assert_equal "SubjectConfirmation", @sc.name
106
- assert_equal "saml", @sc.namespace.prefix
107
- end
108
-
109
- def test_subject_confirmation_method
110
- assert_equal CM_BEARER, @sc["Method"]
111
- end
112
-
113
- def test_subject_confirmation_data
114
- assert_equal "SubjectConfirmationData", @scd.name
115
- assert_equal "saml", @scd.namespace.prefix
116
- end
117
-
118
- def test_valid_for_default
119
- not_on_or_after = Time.iso8601(@scd["NotOnOrAfter"])
120
- expected = Time.now.utc + DEFAULTS.valid_for
121
- assert_in_delta expected.to_i, not_on_or_after.to_i, 1
122
- end
123
-
124
- def test_recipient_default
125
- assert_equal DEFAULTS.recipient, @scd["Recipient"]
126
- end
127
-
128
- def test_in_response_to_default
129
- assert_equal DEFAULTS.in_response_to, @scd["InResponseTo"]
130
- end
131
-
132
- def test_recipient_override
133
- recipient = "https://custom.example.com/acs"
134
- refute_equal recipient, DEFAULTS.recipient
135
- assertion = Assertion.new(recipient: recipient).document
136
- subject = assertion.root.at_xpath("saml:Subject", NS)
137
- sc = subject.at_xpath("saml:SubjectConfirmation", NS)
138
- scd = sc.at_xpath("saml:SubjectConfirmationData", NS)
139
- assert_equal recipient, scd["Recipient"]
140
- end
141
-
142
- def test_in_response_to_override
143
- in_response_to = "_custom_request"
144
- refute_equal in_response_to, DEFAULTS.in_response_to
145
- assertion = Assertion.new(in_response_to: in_response_to).document
146
- subject = assertion.root.at_xpath("saml:Subject", NS)
147
- sc = subject.at_xpath("saml:SubjectConfirmation", NS)
148
- scd = sc.at_xpath("saml:SubjectConfirmationData", NS)
149
- assert_equal in_response_to, scd["InResponseTo"]
150
- end
151
-
152
- def test_in_response_to_omitted_when_nil
153
- assertion = Assertion.new(in_response_to: nil).document
154
- subject = assertion.root.at_xpath("saml:Subject", NS)
155
- sc = subject.at_xpath("saml:SubjectConfirmation", NS)
156
- scd = sc.at_xpath("saml:SubjectConfirmationData", NS)
157
- assert_nil scd["InResponseTo"]
158
- end
159
-
160
- def test_valid_for_override
161
- valid_for = 600 # 10 minutes
162
- refute_equal valid_for, DEFAULTS.valid_for
163
- assertion = Assertion.new(valid_for: valid_for).document
164
- subject = assertion.root.at_xpath("saml:Subject", NS)
165
- sc = subject.at_xpath("saml:SubjectConfirmation", NS)
166
- scd = sc.at_xpath("saml:SubjectConfirmationData", NS)
167
- not_on_or_after = Time.iso8601(scd["NotOnOrAfter"])
168
- expected = Time.now.utc + valid_for
169
- assert_in_delta expected.to_i, not_on_or_after.to_i, 1
170
- end
171
-
172
- def test_conditions
173
- assert_equal "Conditions", @conditions.name
174
- assert_equal "saml", @conditions.namespace.prefix
175
- end
176
-
177
- def test_conditions_not_before
178
- not_before = Time.iso8601(@conditions["NotBefore"])
179
- assert_in_delta Time.now.to_i, not_before.to_i, 1
180
- end
181
-
182
- def test_conditions_not_before_override
183
- not_before = Time.now.utc - 60
184
- assertion = Assertion.new(not_before: not_before).document
185
- conditions = assertion.root.at_xpath("saml:Conditions", NS)
186
- assert_equal not_before.iso8601, conditions["NotBefore"]
187
- end
188
-
189
- def test_conditions_not_on_or_after
190
- not_on_or_after = Time.iso8601(@conditions["NotOnOrAfter"])
191
- expected = Time.now.utc + DEFAULTS.valid_for
192
- assert_in_delta expected.to_i, not_on_or_after.to_i, 1
193
- end
194
-
195
- def test_conditions_valid_for_override
196
- valid_for = 600 # 10 minutes
197
- refute_equal valid_for, DEFAULTS.valid_for
198
- assertion = Assertion.new(valid_for: valid_for).document
199
- conditions = assertion.root.at_xpath("saml:Conditions", NS)
200
- not_on_or_after = Time.iso8601(conditions["NotOnOrAfter"])
201
- expected = Time.now.utc + valid_for
202
- assert_in_delta expected.to_i, not_on_or_after.to_i, 1
203
- end
204
-
205
- def test_audience_restriction
206
- assert_equal "AudienceRestriction", @audience_restriction.name
207
- assert_equal "saml", @audience_restriction.namespace.prefix
208
- end
209
-
210
- def test_audience
211
- audience = @audience_restriction.at_xpath("saml:Audience", NS)
212
- assert_equal "Audience", audience.name
213
- assert_equal "saml", audience.namespace.prefix
214
- assert_equal DEFAULTS.audience, audience.text
215
- end
216
-
217
- def test_audience_override
218
- audience = "https://custom.sp.example.com"
219
- refute_equal audience, DEFAULTS.audience
220
- assertion = Assertion.new(audience: audience).document
221
- conditions = assertion.root.at_xpath("saml:Conditions", NS)
222
- ar = conditions.at_xpath("saml:AudienceRestriction", NS)
223
- assert_equal audience, ar.at_xpath("saml:Audience", NS).text
224
- end
225
-
226
- def test_authn_statement
227
- assert_equal "AuthnStatement", @authn_statement.name
228
- assert_equal "saml", @authn_statement.namespace.prefix
229
- end
230
-
231
- def test_authn_statement_authn_instant
232
- authn_instant = Time.iso8601(@authn_statement["AuthnInstant"])
233
- assert_in_delta Time.now.to_i, authn_instant.to_i, 1
234
- end
235
-
236
- def test_authn_statement_session_index
237
- assert @authn_statement["SessionIndex"].start_with?("_")
238
- end
239
-
240
- def test_authn_context
241
- authn_context = @authn_statement.at_xpath("saml:AuthnContext", NS)
242
- assert_equal "AuthnContext", authn_context.name
243
- assert_equal "saml", authn_context.namespace.prefix
244
- end
245
-
246
- def test_authn_context_class_ref
247
- ac = @authn_statement.at_xpath("saml:AuthnContext", NS)
248
- class_ref = ac.at_xpath("saml:AuthnContextClassRef", NS)
249
- assert_equal "AuthnContextClassRef", class_ref.name
250
- assert_equal "saml", class_ref.namespace.prefix
251
- assert_equal DEFAULTS.authn_context, class_ref.text
252
- end
253
-
254
- def test_authn_context_override
255
- custom_ref = "urn:oasis:names:tc:SAML:2.0:ac:classes:Password"
256
- refute_equal custom_ref, DEFAULTS.authn_context
257
- assertion = Assertion.new(authn_context: custom_ref).document
258
- as = assertion.root.at_xpath("saml:AuthnStatement", NS)
259
- ac = as.at_xpath("saml:AuthnContext", NS)
260
- class_ref = ac.at_xpath("saml:AuthnContextClassRef", NS)
261
- assert_equal custom_ref, class_ref.text
262
- end
263
-
264
- def test_default_attributes
265
- as = @root.at_xpath("saml:AttributeStatement", NS)
266
- attrs = as.xpath("saml:Attribute", NS)
267
- assert_equal 2, attrs.size
268
-
269
- first = attrs.find { |a| a["Name"] == "first_name" }
270
- assert_equal "Test", first.at_xpath("saml:AttributeValue", NS).text
271
-
272
- last = attrs.find { |a| a["Name"] == "last_name" }
273
- assert_equal "User", last.at_xpath("saml:AttributeValue", NS).text
274
- end
275
-
276
- def test_no_attribute_statement_when_empty
277
- assertion = Assertion.new(attributes: {}).document
278
- assert_nil assertion.root.at_xpath("saml:AttributeStatement", NS)
279
- end
280
-
281
- def test_attribute_statement_with_single_value
282
- attributes = { "email" => "user@example.com" }
283
- assertion = Assertion.new(attributes: attributes).document
284
- as = assertion.root.at_xpath("saml:AttributeStatement", NS)
285
- assert_equal "AttributeStatement", as.name
286
- assert_equal "saml", as.namespace.prefix
287
- end
288
-
289
- def test_attribute_name_and_format
290
- attributes = { "email" => "user@example.com" }
291
- assertion = Assertion.new(attributes: attributes).document
292
- path = "saml:AttributeStatement/saml:Attribute"
293
- attr = assertion.root.at_xpath(path, NS)
294
-
295
- assert_equal "Attribute", attr.name
296
- assert_equal "saml", attr.namespace.prefix
297
- assert_equal "email", attr["Name"]
298
- assert_equal ATTR_NAME_FORMAT, attr["NameFormat"]
299
- end
300
-
301
- def test_attribute_single_value
302
- attributes = { "email" => "user@example.com" }
303
- assertion = Assertion.new(attributes: attributes).document
304
- path = "saml:AttributeStatement/saml:Attribute"
305
- attr = assertion.root.at_xpath(path, NS)
306
- value = attr.at_xpath("saml:AttributeValue", NS)
307
-
308
- assert_equal "AttributeValue", value.name
309
- assert_equal "saml", value.namespace.prefix
310
- assert_equal "user@example.com", value.text
311
- end
312
-
313
- def test_attribute_multi_value
314
- attributes = { "groups" => ["admin", "users", "developers"] }
315
- assertion = Assertion.new(attributes: attributes).document
316
- path = "saml:AttributeStatement/saml:Attribute"
317
- attr = assertion.root.at_xpath(path, NS)
318
- values = attr.xpath("saml:AttributeValue", NS)
319
-
320
- assert_equal 3, values.size
321
- assert_equal "admin", values[0].text
322
- assert_equal "users", values[1].text
323
- assert_equal "developers", values[2].text
324
- end
325
-
326
- def test_multiple_attributes
327
- attributes = {
328
- email: "user@example.com",
329
- name: "Test User",
330
- groups: ["admin", "users"]
331
- }
332
-
333
- assertion = Assertion.new(attributes: attributes).document
334
- as = assertion.root.at_xpath("saml:AttributeStatement", NS)
335
- attrs = as.xpath("saml:Attribute", NS)
336
- assert_equal 3, attrs.size
337
-
338
- email_attr = attrs.find { |a| a["Name"] == "email" }
339
- email_value = email_attr.at_xpath("saml:AttributeValue", NS).text
340
- assert_equal "user@example.com", email_value
341
-
342
- name_attr = attrs.find { |a| a["Name"] == "name" }
343
- name_value = name_attr.at_xpath("saml:AttributeValue", NS).text
344
- assert_equal "Test User", name_value
345
-
346
- groups_attr = attrs.find { |a| a["Name"] == "groups" }
347
- group_values = groups_attr.xpath("saml:AttributeValue", NS)
348
- assert_equal 2, group_values.size
349
- assert_equal "admin", group_values[0].text
350
- assert_equal "users", group_values[1].text
351
- end
352
- end
353
- end
@@ -1,113 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module Lyrebird
6
- class CertificateTest < Minitest::Test
7
- def setup
8
- unless defined?(@@shared)
9
- @@shared = Certificate.build
10
- @@created_at = Time.now.utc
11
- end
12
-
13
- @certificate = @@shared
14
- @created_at = @@created_at
15
- end
16
-
17
- def test_key_is_rsa
18
- assert_instance_of OpenSSL::PKey::RSA, @certificate.key
19
- end
20
-
21
- def test_key_defaults_to_2048_bits
22
- assert_equal 2048, @certificate.key.n.num_bits
23
- end
24
-
25
- def test_key_with_custom_bits
26
- certificate = Certificate.build(bits: 4096)
27
- assert_equal 4096, certificate.key.n.num_bits
28
- end
29
-
30
- def test_x509_is_x509
31
- assert_instance_of OpenSSL::X509::Certificate, @certificate.x509
32
- end
33
-
34
- def test_x509_version_is_v3
35
- assert_equal 2, @certificate.x509.version
36
- end
37
-
38
- def test_x509_has_serial_number
39
- refute_nil @certificate.x509.serial
40
- assert @certificate.x509.serial.to_i > 0
41
- end
42
-
43
- def test_x509_not_before_is_now
44
- assert_in_delta @created_at, @certificate.x509.not_before, 1
45
- end
46
-
47
- def test_x509_not_after_is_one_year_from_now
48
- expected = @created_at + (365 * 24 * 60 * 60)
49
- assert_in_delta expected, @certificate.x509.not_after, 1
50
- end
51
-
52
- def test_x509_is_signed
53
- assert @certificate.x509.verify(@certificate.key)
54
- end
55
-
56
- def test_x509_with_custom_subject
57
- certificate = Certificate.build(cn: "Test", o: "Acme")
58
- subject = certificate.x509.subject.to_s
59
- assert_equal "/CN=Test/O=Acme", subject
60
- end
61
-
62
- def test_x509_with_custom_valid_for
63
- certificate = Certificate.build(valid_for: 30).x509
64
- expected = Time.now.utc + (30 * 24 * 60 * 60)
65
- assert_in_delta expected, certificate.not_after, 1
66
- end
67
-
68
- def test_x509_with_valid_until
69
- valid_until = Time.new(2030, 1, 1)
70
- certificate = Certificate.build(valid_until: valid_until)
71
- assert_equal valid_until, certificate.x509.not_after
72
- end
73
-
74
- def test_key_pem
75
- assert @certificate.key_pem.start_with?("-----BEGIN")
76
- end
77
-
78
- def test_x509_pem
79
- assert @certificate.x509_pem.start_with?("-----BEGIN")
80
- end
81
-
82
- def test_fingerprint
83
- der = @certificate.x509.to_der
84
- expected = OpenSSL::Digest::SHA256.hexdigest(der)
85
- assert_equal expected, @certificate.fingerprint
86
- end
87
-
88
- def test_base64
89
- der = @certificate.x509.to_der
90
- expected = Base64.strict_encode64(der)
91
- assert_equal expected, @certificate.base64
92
- end
93
-
94
- def test_build_with_block
95
- certificate = Certificate.build do |c|
96
- c.cn = "Name"
97
- c.o = "Org"
98
- end
99
-
100
- subject = certificate.x509.subject.to_s
101
- assert_equal "/CN=Name/O=Org", subject
102
- end
103
-
104
- def test_load
105
- loaded = Certificate.load(
106
- key_pem: @certificate.key_pem,
107
- x509_pem: @certificate.x509_pem,
108
- )
109
-
110
- assert_equal @certificate.fingerprint, loaded.fingerprint
111
- end
112
- end
113
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module Lyrebird
6
- class DefaultsTest < Minitest::Test
7
- def test_issuer
8
- assert_equal "https://idp.example.com", DEFAULTS.issuer
9
- end
10
-
11
- def test_name_id
12
- assert_equal "user@example.com", DEFAULTS.name_id
13
- end
14
-
15
- def test_name_id_format
16
- assert_equal NAMEID_EMAIL, DEFAULTS.name_id_format
17
- end
18
-
19
- def test_recipient
20
- assert_equal "https://sp.example.com/acs", DEFAULTS.recipient
21
- end
22
-
23
- def test_in_response_to
24
- assert_equal "_request_id", DEFAULTS.in_response_to
25
- end
26
-
27
- def test_valid_for
28
- assert_equal 300, DEFAULTS.valid_for
29
- end
30
-
31
- def test_audience
32
- assert_equal "https://sp.example.com", DEFAULTS.audience
33
- end
34
-
35
- def test_authn_context
36
- expected = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
37
- assert_equal expected, DEFAULTS.authn_context
38
- end
39
-
40
- def test_attributes
41
- expected = { first_name: "Test", last_name: "User" }
42
- assert_equal expected, DEFAULTS.attributes
43
- end
44
- end
45
-
46
- class ConfigureTest < Minitest::Test
47
- def test_configure_yields_defaults
48
- yielded = nil
49
- Lyrebird.configure { |d| yielded = d }
50
- assert_same DEFAULTS, yielded
51
- end
52
-
53
- def test_configure_freezes_defaults
54
- Lyrebird.configure { |d| }
55
- assert DEFAULTS.frozen?
56
- end
57
- end
58
- end
@@ -1,139 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module Lyrebird
6
- class EncryptionTest < Minitest::Test
7
- NS = {
8
- "saml" => SAML_ASSERTION_NS,
9
- "xenc" => XMLENC_NS,
10
- "ds" => XMLDSIG_NS
11
- }.freeze
12
-
13
- def setup
14
- unless defined?(@@certificate)
15
- @@assertion = Assertion.new.document
16
- @@element = @@assertion.root
17
- @@certificate = Certificate.build
18
- @@encrypted = Encryption.new(@@element, @@certificate).encrypt
19
- end
20
-
21
- @assertion = @@assertion
22
- @element = @@element
23
- @certificate = @@certificate
24
- @encrypted = @@encrypted
25
- @ed = @encrypted.at_xpath("xenc:EncryptedData", NS)
26
- @ki = @ed.at_xpath("ds:KeyInfo", NS)
27
- @ek = @ki.at_xpath("xenc:EncryptedKey", NS)
28
- @cd = @ed.at_xpath("xenc:CipherData", NS)
29
- end
30
-
31
- def test_returns_encrypted_assertion_element
32
- assert_equal "EncryptedAssertion", @encrypted.name
33
- assert_equal "saml", @encrypted.namespace.prefix
34
- end
35
-
36
- def test_encrypted_assertion_namespace
37
- assert_equal SAML_ASSERTION_NS, @encrypted.namespace.href
38
- end
39
-
40
- def test_encrypted_data_element
41
- assert_equal "EncryptedData", @ed.name
42
- assert_equal "xenc", @ed.namespace.prefix
43
- end
44
-
45
- def test_encrypted_data_namespace
46
- assert_equal XMLENC_NS, @ed.namespace.href
47
- end
48
-
49
- def test_encrypted_data_type
50
- assert_equal "#{XMLENC_NS}Element", @ed["Type"]
51
- end
52
-
53
- def test_encryption_method_element
54
- em = @ed.at_xpath("xenc:EncryptionMethod", NS)
55
- assert_equal "EncryptionMethod", em.name
56
- assert_equal "xenc", em.namespace.prefix
57
- end
58
-
59
- def test_encryption_method_algorithm
60
- em = @ed.at_xpath("xenc:EncryptionMethod", NS)
61
- assert_equal AES256_CBC, em["Algorithm"]
62
- end
63
-
64
- def test_cipher_data_element
65
- assert_equal "CipherData", @cd.name
66
- assert_equal "xenc", @cd.namespace.prefix
67
- end
68
-
69
- def test_cipher_value_element
70
- cv = @cd.at_xpath("xenc:CipherValue", NS)
71
- assert_equal "CipherValue", cv.name
72
- assert_equal "xenc", cv.namespace.prefix
73
- end
74
-
75
- def test_cipher_value_is_base64
76
- cv = @cd.at_xpath("xenc:CipherValue", NS)
77
- decoded = Base64.strict_decode64(cv.text)
78
- assert decoded.bytesize > 16
79
- end
80
-
81
- def test_cipher_value_starts_with_iv
82
- cv = @cd.at_xpath("xenc:CipherValue", NS)
83
- decoded = Base64.strict_decode64(cv.text)
84
- iv = decoded[0, 16]
85
- assert_equal 16, iv.bytesize
86
- end
87
-
88
- def test_key_info_element
89
- assert_equal "KeyInfo", @ki.name
90
- assert_equal "ds", @ki.namespace.prefix
91
- end
92
-
93
- def test_key_info_namespace
94
- assert_equal XMLDSIG_NS, @ki.namespace.href
95
- end
96
-
97
- def test_encrypted_key_element
98
- assert_equal "EncryptedKey", @ek.name
99
- assert_equal "xenc", @ek.namespace.prefix
100
- end
101
-
102
- def test_encrypted_key_namespace
103
- assert_equal XMLENC_NS, @ek.namespace.href
104
- end
105
-
106
- def test_encrypted_key_encryption_method
107
- em = @ek.at_xpath("xenc:EncryptionMethod", NS)
108
- assert_equal "EncryptionMethod", em.name
109
- assert_equal RSA_OAEP, em["Algorithm"]
110
- end
111
-
112
- def test_encrypted_key_cipher_data
113
- cd = @ek.at_xpath("xenc:CipherData", NS)
114
- assert_equal "CipherData", cd.name
115
- assert_equal "xenc", cd.namespace.prefix
116
- end
117
-
118
- def test_encrypted_key_cipher_value
119
- cv = @ek.at_xpath("xenc:CipherData/xenc:CipherValue", NS)
120
- assert_equal "CipherValue", cv.name
121
- assert_equal "xenc", cv.namespace.prefix
122
- end
123
-
124
- def test_encrypted_key_cipher_value_is_base64
125
- cv = @ek.at_xpath("xenc:CipherData/xenc:CipherValue", NS)
126
- decoded = Base64.strict_decode64(cv.text)
127
- assert decoded.bytesize > 0
128
- end
129
-
130
- def test_encrypted_key_can_be_decrypted
131
- cv = @ek.at_xpath("xenc:CipherData/xenc:CipherValue", NS)
132
- encrypted_key = Base64.strict_decode64(cv.text)
133
- private_key = @certificate.key
134
- padding = OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING
135
- decrypted_key = private_key.private_decrypt(encrypted_key, padding)
136
- assert_equal 32, decrypted_key.bytesize
137
- end
138
- end
139
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- module Lyrebird
6
- class IDTest < Minitest::Test
7
- def test_generate_starts_with_underscore
8
- assert ID.generate.start_with?("_")
9
- end
10
-
11
- def test_generate_contains_uuid
12
- id = ID.generate
13
- uuid = id[1..]
14
- uuid_pattern = /\A[0-9a-f-]{36}\z/
15
- assert_match uuid_pattern, uuid
16
- end
17
- end
18
- end