lyrebird 1.0.0 → 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,348 +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_root_namespace
37
- assert_equal SAML_ASSERTION_NS, @root.namespace.href
38
- end
39
-
40
- def test_root_id
41
- assert @root["ID"].start_with?("_")
42
- end
43
-
44
- def test_root_version
45
- assert_equal "2.0", @root["Version"]
46
- end
47
-
48
- def test_root_issue_instant
49
- instant = Time.iso8601(@root["IssueInstant"])
50
- assert_in_delta Time.now.to_i, instant.to_i, 1
51
- end
52
-
53
- def test_issuer
54
- issuer = @root.at_xpath("saml:Issuer", NS)
55
- assert_equal "Issuer", issuer.name
56
- assert_equal "saml", issuer.namespace.prefix
57
- assert_equal DEFAULTS.issuer, issuer.text
58
- end
59
-
60
- def test_issuer_override
61
- assertion = Assertion.new(issuer: "https://test.example.com").document
62
- issuer = assertion.root.at_xpath("saml:Issuer", NS)
63
- assert_equal "https://test.example.com", issuer.text
64
- end
65
-
66
- def test_subject
67
- assert_equal "Subject", @subject.name
68
- assert_equal "saml", @subject.namespace.prefix
69
- end
70
-
71
- def test_name_id
72
- name_id = @subject.at_xpath("saml:NameID", NS)
73
- assert_equal "NameID", name_id.name
74
- assert_equal "saml", name_id.namespace.prefix
75
- assert_equal DEFAULTS.name_id, name_id.text
76
- end
77
-
78
- def test_name_id_format_default
79
- name_id = @subject.at_xpath("saml:NameID", NS)
80
- assert_equal NAMEID_EMAIL, name_id["Format"]
81
- end
82
-
83
- def test_name_id_override
84
- email = "user@test.com"
85
- refute_equal email, DEFAULTS.name_id
86
- assertion = Assertion.new(name_id: email).document
87
- name_id = assertion.root.at_xpath("saml:Subject/saml:NameID", NS)
88
- assert_equal email, name_id.text
89
- end
90
-
91
- def test_name_id_format_override
92
- format = NAMEID_PERSISTENT
93
- refute_equal format, DEFAULTS.name_id_format
94
- assertion = Assertion.new(name_id_format: format).document
95
- name_id = assertion.root.at_xpath("saml:Subject/saml:NameID", NS)
96
- assert_equal format, name_id["Format"]
97
- end
98
-
99
- def test_subject_confirmation
100
- assert_equal "SubjectConfirmation", @sc.name
101
- assert_equal "saml", @sc.namespace.prefix
102
- end
103
-
104
- def test_subject_confirmation_method
105
- assert_equal CM_BEARER, @sc["Method"]
106
- end
107
-
108
- def test_subject_confirmation_data
109
- assert_equal "SubjectConfirmationData", @scd.name
110
- assert_equal "saml", @scd.namespace.prefix
111
- end
112
-
113
- def test_valid_for_default
114
- not_on_or_after = Time.iso8601(@scd["NotOnOrAfter"])
115
- expected = Time.now.utc + DEFAULTS.valid_for
116
- assert_in_delta expected.to_i, not_on_or_after.to_i, 1
117
- end
118
-
119
- def test_recipient_default
120
- assert_equal DEFAULTS.recipient, @scd["Recipient"]
121
- end
122
-
123
- def test_in_response_to_default
124
- assert_equal DEFAULTS.in_response_to, @scd["InResponseTo"]
125
- end
126
-
127
- def test_recipient_override
128
- recipient = "https://custom.example.com/acs"
129
- refute_equal recipient, DEFAULTS.recipient
130
- assertion = Assertion.new(recipient: recipient).document
131
- subject = assertion.root.at_xpath("saml:Subject", NS)
132
- sc = subject.at_xpath("saml:SubjectConfirmation", NS)
133
- scd = sc.at_xpath("saml:SubjectConfirmationData", NS)
134
- assert_equal recipient, scd["Recipient"]
135
- end
136
-
137
- def test_in_response_to_override
138
- in_response_to = "_custom_request"
139
- refute_equal in_response_to, DEFAULTS.in_response_to
140
- assertion = Assertion.new(in_response_to: in_response_to).document
141
- subject = assertion.root.at_xpath("saml:Subject", NS)
142
- sc = subject.at_xpath("saml:SubjectConfirmation", NS)
143
- scd = sc.at_xpath("saml:SubjectConfirmationData", NS)
144
- assert_equal in_response_to, scd["InResponseTo"]
145
- end
146
-
147
- def test_in_response_to_omitted_when_nil
148
- assertion = Assertion.new(in_response_to: nil).document
149
- subject = assertion.root.at_xpath("saml:Subject", NS)
150
- sc = subject.at_xpath("saml:SubjectConfirmation", NS)
151
- scd = sc.at_xpath("saml:SubjectConfirmationData", NS)
152
- assert_nil scd["InResponseTo"]
153
- end
154
-
155
- def test_valid_for_override
156
- valid_for = 600 # 10 minutes
157
- refute_equal valid_for, DEFAULTS.valid_for
158
- assertion = Assertion.new(valid_for: valid_for).document
159
- subject = assertion.root.at_xpath("saml:Subject", NS)
160
- sc = subject.at_xpath("saml:SubjectConfirmation", NS)
161
- scd = sc.at_xpath("saml:SubjectConfirmationData", NS)
162
- not_on_or_after = Time.iso8601(scd["NotOnOrAfter"])
163
- expected = Time.now.utc + valid_for
164
- assert_in_delta expected.to_i, not_on_or_after.to_i, 1
165
- end
166
-
167
- def test_conditions
168
- assert_equal "Conditions", @conditions.name
169
- assert_equal "saml", @conditions.namespace.prefix
170
- end
171
-
172
- def test_conditions_not_before
173
- not_before = Time.iso8601(@conditions["NotBefore"])
174
- assert_in_delta Time.now.to_i, not_before.to_i, 1
175
- end
176
-
177
- def test_conditions_not_before_override
178
- not_before = Time.now.utc - 60
179
- assertion = Assertion.new(not_before: not_before).document
180
- conditions = assertion.root.at_xpath("saml:Conditions", NS)
181
- assert_equal not_before.iso8601, conditions["NotBefore"]
182
- end
183
-
184
- def test_conditions_not_on_or_after
185
- not_on_or_after = Time.iso8601(@conditions["NotOnOrAfter"])
186
- expected = Time.now.utc + DEFAULTS.valid_for
187
- assert_in_delta expected.to_i, not_on_or_after.to_i, 1
188
- end
189
-
190
- def test_conditions_valid_for_override
191
- valid_for = 600 # 10 minutes
192
- refute_equal valid_for, DEFAULTS.valid_for
193
- assertion = Assertion.new(valid_for: valid_for).document
194
- conditions = assertion.root.at_xpath("saml:Conditions", NS)
195
- not_on_or_after = Time.iso8601(conditions["NotOnOrAfter"])
196
- expected = Time.now.utc + valid_for
197
- assert_in_delta expected.to_i, not_on_or_after.to_i, 1
198
- end
199
-
200
- def test_audience_restriction
201
- assert_equal "AudienceRestriction", @audience_restriction.name
202
- assert_equal "saml", @audience_restriction.namespace.prefix
203
- end
204
-
205
- def test_audience
206
- audience = @audience_restriction.at_xpath("saml:Audience", NS)
207
- assert_equal "Audience", audience.name
208
- assert_equal "saml", audience.namespace.prefix
209
- assert_equal DEFAULTS.audience, audience.text
210
- end
211
-
212
- def test_audience_override
213
- audience = "https://custom.sp.example.com"
214
- refute_equal audience, DEFAULTS.audience
215
- assertion = Assertion.new(audience: audience).document
216
- conditions = assertion.root.at_xpath("saml:Conditions", NS)
217
- ar = conditions.at_xpath("saml:AudienceRestriction", NS)
218
- assert_equal audience, ar.at_xpath("saml:Audience", NS).text
219
- end
220
-
221
- def test_authn_statement
222
- assert_equal "AuthnStatement", @authn_statement.name
223
- assert_equal "saml", @authn_statement.namespace.prefix
224
- end
225
-
226
- def test_authn_statement_authn_instant
227
- authn_instant = Time.iso8601(@authn_statement["AuthnInstant"])
228
- assert_in_delta Time.now.to_i, authn_instant.to_i, 1
229
- end
230
-
231
- def test_authn_statement_session_index
232
- assert @authn_statement["SessionIndex"].start_with?("_")
233
- end
234
-
235
- def test_authn_context
236
- authn_context = @authn_statement.at_xpath("saml:AuthnContext", NS)
237
- assert_equal "AuthnContext", authn_context.name
238
- assert_equal "saml", authn_context.namespace.prefix
239
- end
240
-
241
- def test_authn_context_class_ref
242
- ac = @authn_statement.at_xpath("saml:AuthnContext", NS)
243
- class_ref = ac.at_xpath("saml:AuthnContextClassRef", NS)
244
- assert_equal "AuthnContextClassRef", class_ref.name
245
- assert_equal "saml", class_ref.namespace.prefix
246
- assert_equal DEFAULTS.authn_context, class_ref.text
247
- end
248
-
249
- def test_authn_context_override
250
- custom_ref = "urn:oasis:names:tc:SAML:2.0:ac:classes:Password"
251
- refute_equal custom_ref, DEFAULTS.authn_context
252
- assertion = Assertion.new(authn_context: custom_ref).document
253
- as = assertion.root.at_xpath("saml:AuthnStatement", NS)
254
- ac = as.at_xpath("saml:AuthnContext", NS)
255
- class_ref = ac.at_xpath("saml:AuthnContextClassRef", NS)
256
- assert_equal custom_ref, class_ref.text
257
- end
258
-
259
- def test_default_attributes
260
- as = @root.at_xpath("saml:AttributeStatement", NS)
261
- attrs = as.xpath("saml:Attribute", NS)
262
- assert_equal 2, attrs.size
263
-
264
- first = attrs.find { |a| a["Name"] == "first_name" }
265
- assert_equal "Test", first.at_xpath("saml:AttributeValue", NS).text
266
-
267
- last = attrs.find { |a| a["Name"] == "last_name" }
268
- assert_equal "User", last.at_xpath("saml:AttributeValue", NS).text
269
- end
270
-
271
- def test_no_attribute_statement_when_empty
272
- assertion = Assertion.new(attributes: {}).document
273
- assert_nil assertion.root.at_xpath("saml:AttributeStatement", NS)
274
- end
275
-
276
- def test_attribute_statement_with_single_value
277
- attributes = { "email" => "user@example.com" }
278
- assertion = Assertion.new(attributes: attributes).document
279
- as = assertion.root.at_xpath("saml:AttributeStatement", NS)
280
- assert_equal "AttributeStatement", as.name
281
- assert_equal "saml", as.namespace.prefix
282
- end
283
-
284
- def test_attribute_name_and_format
285
- attributes = { "email" => "user@example.com" }
286
- assertion = Assertion.new(attributes: attributes).document
287
- path = "saml:AttributeStatement/saml:Attribute"
288
- attr = assertion.root.at_xpath(path, NS)
289
-
290
- assert_equal "Attribute", attr.name
291
- assert_equal "saml", attr.namespace.prefix
292
- assert_equal "email", attr["Name"]
293
- assert_equal ATTR_NAME_FORMAT, attr["NameFormat"]
294
- end
295
-
296
- def test_attribute_single_value
297
- attributes = { "email" => "user@example.com" }
298
- assertion = Assertion.new(attributes: attributes).document
299
- path = "saml:AttributeStatement/saml:Attribute"
300
- attr = assertion.root.at_xpath(path, NS)
301
- value = attr.at_xpath("saml:AttributeValue", NS)
302
-
303
- assert_equal "AttributeValue", value.name
304
- assert_equal "saml", value.namespace.prefix
305
- assert_equal "user@example.com", value.text
306
- end
307
-
308
- def test_attribute_multi_value
309
- attributes = { "groups" => ["admin", "users", "developers"] }
310
- assertion = Assertion.new(attributes: attributes).document
311
- path = "saml:AttributeStatement/saml:Attribute"
312
- attr = assertion.root.at_xpath(path, NS)
313
- values = attr.xpath("saml:AttributeValue", NS)
314
-
315
- assert_equal 3, values.size
316
- assert_equal "admin", values[0].text
317
- assert_equal "users", values[1].text
318
- assert_equal "developers", values[2].text
319
- end
320
-
321
- def test_multiple_attributes
322
- attributes = {
323
- email: "user@example.com",
324
- name: "Test User",
325
- groups: ["admin", "users"]
326
- }
327
-
328
- assertion = Assertion.new(attributes: attributes).document
329
- as = assertion.root.at_xpath("saml:AttributeStatement", NS)
330
- attrs = as.xpath("saml:Attribute", NS)
331
- assert_equal 3, attrs.size
332
-
333
- email_attr = attrs.find { |a| a["Name"] == "email" }
334
- email_value = email_attr.at_xpath("saml:AttributeValue", NS).text
335
- assert_equal "user@example.com", email_value
336
-
337
- name_attr = attrs.find { |a| a["Name"] == "name" }
338
- name_value = name_attr.at_xpath("saml:AttributeValue", NS).text
339
- assert_equal "Test User", name_value
340
-
341
- groups_attr = attrs.find { |a| a["Name"] == "groups" }
342
- group_values = groups_attr.xpath("saml:AttributeValue", NS)
343
- assert_equal 2, group_values.size
344
- assert_equal "admin", group_values[0].text
345
- assert_equal "users", group_values[1].text
346
- end
347
- end
348
- end
@@ -1,120 +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_sign
57
- data = "test"
58
- signature = @certificate.sign(data)
59
- public_key = @certificate.x509.public_key
60
- assert public_key.verify("SHA256", signature, data)
61
- end
62
-
63
- def test_x509_with_custom_subject
64
- certificate = Certificate.build(cn: "Test", o: "Acme")
65
- subject = certificate.x509.subject.to_s
66
- assert_equal "/CN=Test/O=Acme", subject
67
- end
68
-
69
- def test_x509_with_custom_valid_for
70
- certificate = Certificate.build(valid_for: 30).x509
71
- expected = Time.now.utc + (30 * 24 * 60 * 60)
72
- assert_in_delta expected, certificate.not_after, 1
73
- end
74
-
75
- def test_x509_with_valid_until
76
- valid_until = Time.new(2030, 1, 1)
77
- certificate = Certificate.build(valid_until: valid_until)
78
- assert_equal valid_until, certificate.x509.not_after
79
- end
80
-
81
- def test_key_pem
82
- assert @certificate.key_pem.start_with?("-----BEGIN")
83
- end
84
-
85
- def test_x509_pem
86
- assert @certificate.x509_pem.start_with?("-----BEGIN")
87
- end
88
-
89
- def test_fingerprint
90
- der = @certificate.x509.to_der
91
- expected = OpenSSL::Digest::SHA256.hexdigest(der)
92
- assert_equal expected, @certificate.fingerprint
93
- end
94
-
95
- def test_base64
96
- der = @certificate.x509.to_der
97
- expected = Base64.strict_encode64(der)
98
- assert_equal expected, @certificate.base64
99
- end
100
-
101
- def test_build_with_block
102
- certificate = Certificate.build do |c|
103
- c.cn = "Name"
104
- c.o = "Org"
105
- end
106
-
107
- subject = certificate.x509.subject.to_s
108
- assert_equal "/CN=Name/O=Org", subject
109
- end
110
-
111
- def test_load
112
- loaded = Certificate.load(
113
- key_pem: @certificate.key_pem,
114
- x509_pem: @certificate.x509_pem,
115
- )
116
-
117
- assert_equal @certificate.fingerprint, loaded.fingerprint
118
- end
119
- end
120
- 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