authlete 1.26.1 → 1.28.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  # :nodoc:
2
2
  #
3
- # Copyright (C) 2014-2020 Authlete, Inc.
3
+ # Copyright (C) 2014-2022 Authlete, Inc.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ class ClientTest < Minitest::Test
55
55
  TOS_URI_VALUE = '<tos-uri0-value>'
56
56
  TOS_URIS = [ Authlete::Model::TaggedValue.new(tag: TOS_URI_TAG, value: TOS_URI_VALUE) ]
57
57
  JWKS_URI = '<jwks-uri>'
58
- JWKS = '<jwks>'
58
+ JWKS = '{"keys":[]}'
59
59
  DERIVED_SECTOR_IDENTIFIER = '<derived-sector-identifier>'
60
60
  SECTOR_IDENTIFIER_URI = '<sector-identifier-uri>'
61
61
  SUBJECT_TYPE = 'PUBLIC'
@@ -125,6 +125,8 @@ class ClientTest < Minitest::Test
125
125
  SINGLE_ACCESS_TOKEN_PER_SUBJECT = false
126
126
  PKCE_REQUIRED = false
127
127
  PKCE_S256_REQUIRED = false
128
+ AUTOMATICALLY_REGISTERED = false
129
+ EXPLICITLY_REGISTERED = false
128
130
 
129
131
  def generate_json
130
132
  return <<~JSON
@@ -153,7 +155,7 @@ class ClientTest < Minitest::Test
153
155
  "tosUri": "<tos-uri>",
154
156
  "tosUris": [ { "tag": "<tos-uri0-tag>", "value": "<tos-uri0-value>" } ],
155
157
  "jwksUri": "<jwks-uri>",
156
- "jwks": "<jwks>",
158
+ "jwks": "{\\"keys\\":[]}",
157
159
  "derivedSectorIdentifier": "<derived-sector-identifier>",
158
160
  "sectorIdentifierUri": "<sector-identifier-uri>",
159
161
  "subjectType": "PUBLIC",
@@ -213,11 +215,13 @@ class ClientTest < Minitest::Test
213
215
  "digestAlgorithm": "<digest-algorithm>",
214
216
  "singleAccessTokenPerSubject": false,
215
217
  "pkceRequired": false,
216
- "pkceS256Required": false
218
+ "pkceS256Required": false,
219
+ "automaticallyRegistered": false,
220
+ "explicitlyRegistered": false
217
221
  }
218
222
  JSON
219
- end
220
-
223
+ end
224
+
221
225
 
222
226
  def generate_hash
223
227
  {
@@ -245,7 +249,7 @@ class ClientTest < Minitest::Test
245
249
  tosUri: '<tos-uri>',
246
250
  tosUris: [ { tag: '<tos-uri0-tag>', value: '<tos-uri0-value>' } ],
247
251
  jwksUri: '<jwks-uri>',
248
- jwks: '<jwks>',
252
+ jwks: '{"keys":[]}',
249
253
  derivedSectorIdentifier: '<derived-sector-identifier>',
250
254
  sectorIdentifierUri: '<sector-identifier-uri>',
251
255
  subjectType: 'PUBLIC',
@@ -306,6 +310,8 @@ class ClientTest < Minitest::Test
306
310
  singleAccessTokenPerSubject: false,
307
311
  pkceRequired: false,
308
312
  pkceS256Required: false,
313
+ automaticallyRegistered: false,
314
+ explicitlyRegistered: false,
309
315
  }
310
316
  end
311
317
 
@@ -389,6 +395,8 @@ class ClientTest < Minitest::Test
389
395
  obj.singleAccessTokenPerSubject = SINGLE_ACCESS_TOKEN_PER_SUBJECT
390
396
  obj.pkceRequired = PKCE_REQUIRED
391
397
  obj.pkceS256Required = PKCE_S256_REQUIRED
398
+ obj.automaticallyRegistered = AUTOMATICALLY_REGISTERED
399
+ obj.explicitlyRegistered = EXPLICITLY_REGISTERED
392
400
  end
393
401
 
394
402
 
@@ -481,6 +489,8 @@ class ClientTest < Minitest::Test
481
489
  assert_equal SINGLE_ACCESS_TOKEN_PER_SUBJECT, obj.singleAccessTokenPerSubject
482
490
  assert_equal PKCE_REQUIRED, obj.pkceRequired
483
491
  assert_equal PKCE_S256_REQUIRED, obj.pkceS256Required
492
+ assert_equal AUTOMATICALLY_REGISTERED, obj.automaticallyRegistered
493
+ assert_equal EXPLICITLY_REGISTERED, obj.explicitlyRegistered
484
494
  end
485
495
 
486
496
 
@@ -509,4 +519,81 @@ class ClientTest < Minitest::Test
509
519
 
510
520
  assert_equal expected, actual
511
521
  end
522
+
523
+
524
+ def test_standard_metadata_full
525
+ client = Authlete::Model::Client.new
526
+ set_params(client)
527
+
528
+ expected_response_types = ['none', 'code', 'token', 'id_token']
529
+ expected_grant_types = ['authorization_code', 'refresh_token']
530
+ expected_jwks = { "keys" => [] }
531
+
532
+ metadata = client.standard_metadata(false, false, false)
533
+
534
+ assert_equal "#{CLIENT_ID}", metadata[:client_id]
535
+ assert_equal REDIRECT_URIS, metadata[:redirect_uris]
536
+ assert_equal expected_response_types, metadata[:response_types]
537
+ assert_equal expected_grant_types, metadata[:grant_types]
538
+ assert_equal 'web', metadata[:application_type]
539
+ assert_equal CONTACTS, metadata[:contacts]
540
+ assert_equal CLIENT_NAME, metadata[:client_name]
541
+ assert_equal LOGO_URI, metadata[:logo_uri]
542
+ assert_equal CLIENT_URI, metadata[:client_uri]
543
+ assert_equal POLICY_URI, metadata[:policy_uri]
544
+ assert_equal TOS_URI, metadata[:tos_uri]
545
+ assert_equal JWKS_URI, metadata[:jwks_uri]
546
+ assert_equal expected_jwks, metadata[:jwks]
547
+ assert_equal SECTOR_IDENTIFIER_URI, metadata[:sector_identifier_uri]
548
+ assert_equal 'public', metadata[:subject_type]
549
+ assert_equal 'HS256', metadata[:id_token_signed_response_alg]
550
+ assert_equal 'PBES2-HS256+A128KW', metadata[:id_token_encrypted_response_alg]
551
+ assert_equal 'A128CBC-HS256', metadata[:id_token_encrypted_response_enc]
552
+ assert_equal 'HS256', metadata[:userinfo_signed_response_alg]
553
+ assert_equal 'PBES2-HS256+A128KW', metadata[:userinfo_encrypted_response_alg]
554
+ assert_equal 'A128CBC-HS256', metadata[:userinfo_encrypted_response_enc]
555
+ assert_equal 'HS256', metadata[:request_object_signing_alg]
556
+ assert_equal 'PBES2-HS256+A128KW', metadata[:request_object_encryption_alg]
557
+ assert_equal 'A128CBC-HS256', metadata[:request_object_encryption_enc]
558
+ assert_equal 'client_secret_basic', metadata[:token_endpoint_auth_method]
559
+ assert_equal 'HS256', metadata[:token_endpoint_auth_signing_alg]
560
+ assert_equal DEFAULT_MAX_AGE, metadata[:default_max_age]
561
+ assert_equal DEFAULT_ACRS, metadata[:default_acr_values]
562
+ assert_equal AUTH_TIME_REQUIRED, metadata[:require_auth_time]
563
+ assert_equal LOGIN_URI, metadata[:initiate_login_uri]
564
+ assert_equal REQUEST_URIS, metadata[:request_uris]
565
+ assert_equal TLS_CLIENT_AUTH_SUBJECT_DN, metadata[:tls_client_auth_subject_dn]
566
+ assert_equal TLS_CLIENT_AUTH_SAN_DNS, metadata[:tls_client_auth_san_dns]
567
+ assert_equal TLS_CLIENT_AUTH_SAN_URI, metadata[:tls_client_auth_san_uri]
568
+ assert_equal TLS_CLIENT_AUTH_SAN_IP, metadata[:tls_client_auth_san_ip]
569
+ assert_equal TLS_CLIENT_AUTH_SAN_EMAIL, metadata[:tls_client_auth_san_email]
570
+ assert_equal TLS_CLIENT_CERTIFICATE_BOUND_ACCESS_TOKENS, metadata[:tls_client_certificate_bound_access_tokens]
571
+ assert_equal SOFTWARE_ID, metadata[:software_id]
572
+ assert_equal SOFTWARE_VERSION, metadata[:software_version]
573
+ assert_equal 'HS256', metadata[:authorization_signed_response_alg]
574
+ assert_equal 'PBES2-HS256+A128KW', metadata[:authorization_encrypted_response_alg]
575
+ assert_equal 'A128CBC-HS256', metadata[:authorization_encrypted_response_enc]
576
+ assert_equal 'poll', metadata[:backchannel_token_delivery_mode]
577
+ assert_equal BC_NOTIFICATION_ENDPOINT, metadata[:backchannel_client_notification_endpoint]
578
+ assert_equal 'HS256', metadata[:backchannel_authentication_request_signing_alg]
579
+ assert_equal BC_USER_CODE_REQUIRED, metadata[:backchannel_user_code_parameter]
580
+ assert_equal AUTHORIZATION_DETAILS_TYPES, metadata[:authorization_details_types]
581
+ assert_equal DIGEST_ALGORITHM, metadata[:digest_algorithm]
582
+ end
583
+
584
+
585
+ def test_standard_metadata_minimum
586
+ client = Authlete::Model::Client.new
587
+ set_params(client)
588
+
589
+ client.default_max_age = 0
590
+ client.auth_time_required = false
591
+ client.login_uri = nil
592
+
593
+ metadata = client.standard_metadata
594
+
595
+ assert_nil metadata[:default_max_age]
596
+ assert_nil metadata[:require_auth_time]
597
+ assert_nil metadata[:initiate_login_uri]
598
+ end
512
599
  end
@@ -1,6 +1,6 @@
1
1
  # :nodoc:
2
2
  #
3
- # Copyright (C) 2014-2020 Authlete, Inc.
3
+ # Copyright (C) 2014-2022 Authlete, Inc.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -194,6 +194,7 @@ class ServiceTest < Minitest::Test
194
194
  FEDERATION_SIGNATURE_KEY_ID = '<federation-signature-key-id>'
195
195
  FEDERATION_CONFIGURATION_DURATION = 100
196
196
  DCR_DUPLICATE_SOFTWARE_ID_BLOCKED = false
197
+ OPENID_DROPPED_ON_REFRESH_WITHOUT_OFFLINE_ACCESS = false
197
198
 
198
199
  def generate_json
199
200
  return <<~JSON
@@ -347,7 +348,8 @@ class ServiceTest < Minitest::Test
347
348
  "jwtGrantUnsignedJwtRejected": false,
348
349
  "federationSignatureKeyId": "<federation-signature-key-id>",
349
350
  "federationConfigurationDuration": 100,
350
- "dcrDuplicateSoftwareIdBlocked": false
351
+ "dcrDuplicateSoftwareIdBlocked": false,
352
+ "openidDroppedOnRefreshWithoutOfflineAccess": false
351
353
  }
352
354
  JSON
353
355
 
@@ -505,7 +507,8 @@ class ServiceTest < Minitest::Test
505
507
  jwtGrantUnsignedJwtRejected: false,
506
508
  federationSignatureKeyId: '<federation-signature-key-id>',
507
509
  federationConfigurationDuration: 100,
508
- dcrDuplicateSoftwareIdBlocked: false
510
+ dcrDuplicateSoftwareIdBlocked: false,
511
+ openidDroppedOnRefreshWithoutOfflineAccess: false
509
512
  }
510
513
  end
511
514
 
@@ -659,6 +662,7 @@ class ServiceTest < Minitest::Test
659
662
  obj.federation_signature_key_id = FEDERATION_SIGNATURE_KEY_ID
660
663
  obj.federation_configuration_duration = FEDERATION_CONFIGURATION_DURATION
661
664
  obj.dcr_duplicate_software_id_blocked = DCR_DUPLICATE_SOFTWARE_ID_BLOCKED
665
+ obj.openidDroppedOnRefreshWithoutOfflineAccess = OPENID_DROPPED_ON_REFRESH_WITHOUT_OFFLINE_ACCESS
662
666
  end
663
667
 
664
668
  def match(obj)
@@ -827,6 +831,7 @@ class ServiceTest < Minitest::Test
827
831
  assert_equal FEDERATION_SIGNATURE_KEY_ID, obj.federationSignatureKeyId
828
832
  assert_equal FEDERATION_CONFIGURATION_DURATION, obj.federationConfigurationDuration
829
833
  assert_equal DCR_DUPLICATE_SOFTWARE_ID_BLOCKED, obj.dcrDuplicateSoftwareIdBlocked
834
+ assert_equal OPENID_DROPPED_ON_REFRESH_WITHOUT_OFFLINE_ACCESS, obj.openidDroppedOnRefreshWithoutOfflineAccess
830
835
  end
831
836
 
832
837
 
@@ -0,0 +1,44 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2022 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 'minitest/autorun'
20
+
21
+
22
+ class ApplicationTypeTest < Minitest::Test
23
+ def do_test(input, expected)
24
+ output = Authlete::Types::ApplicationType::constant_get(input)
25
+
26
+ if expected.nil?
27
+ assert_nil output
28
+ else
29
+ assert_equal expected, output
30
+ end
31
+ end
32
+
33
+ def test_unknown
34
+ do_test('UNKNOWN', nil)
35
+ end
36
+
37
+ def test_web
38
+ do_test('WEB', 'web')
39
+ end
40
+
41
+ def test_native
42
+ do_test('NATIVE', 'native')
43
+ end
44
+ end
@@ -0,0 +1,64 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2022 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 'minitest/autorun'
20
+
21
+
22
+ class ClientAuthMethodTest < Minitest::Test
23
+ def do_test(input, expected)
24
+ output = Authlete::Types::ClientAuthMethod::constant_get(input)
25
+
26
+ if expected.nil?
27
+ assert_nil output
28
+ else
29
+ assert_equal expected, output
30
+ end
31
+ end
32
+
33
+ def test_unknown
34
+ do_test('UNKNOWN', nil)
35
+ end
36
+
37
+ def test_none
38
+ do_test('NONE', 'none')
39
+ end
40
+
41
+ def test_client_secret_basic
42
+ do_test('CLIENT_SECRET_BASIC', 'client_secret_basic')
43
+ end
44
+
45
+ def test_client_secret_post
46
+ do_test('CLIENT_SECRET_POST', 'client_secret_post')
47
+ end
48
+
49
+ def test_client_secret_jwt
50
+ do_test('CLIENT_SECRET_JWT', 'client_secret_jwt')
51
+ end
52
+
53
+ def test_private_key_jwt
54
+ do_test('PRIVATE_KEY_JWT', 'private_key_jwt')
55
+ end
56
+
57
+ def test_tls_client_auth
58
+ do_test('TLS_CLIENT_AUTH', 'tls_client_auth')
59
+ end
60
+
61
+ def test_self_signed_tls_client_auth
62
+ do_test('SELF_SIGNED_TLS_CLIENT_AUTH', 'self_signed_tls_client_auth')
63
+ end
64
+ end
@@ -0,0 +1,48 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2022 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 'minitest/autorun'
20
+
21
+
22
+ class DeliveryModeTest < Minitest::Test
23
+ def do_test(input, expected)
24
+ output = Authlete::Types::DeliveryMode::constant_get(input)
25
+
26
+ if expected.nil?
27
+ assert_nil output
28
+ else
29
+ assert_equal expected, output
30
+ end
31
+ end
32
+
33
+ def test_unknown
34
+ do_test('UNKNOWN', nil)
35
+ end
36
+
37
+ def test_poll
38
+ do_test('POLL', 'poll')
39
+ end
40
+
41
+ def test_ping
42
+ do_test('PING', 'ping')
43
+ end
44
+
45
+ def test_push
46
+ do_test('PUSH', 'push')
47
+ end
48
+ end
@@ -0,0 +1,72 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2022 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 'minitest/autorun'
20
+
21
+
22
+ class GrantTypeTest < Minitest::Test
23
+ def do_test(input, expected)
24
+ output = Authlete::Types::GrantType::constant_get(input)
25
+
26
+ if expected.nil?
27
+ assert_nil output
28
+ else
29
+ assert_equal expected, output
30
+ end
31
+ end
32
+
33
+ def test_unknown
34
+ do_test('UNKNOWN', nil)
35
+ end
36
+
37
+ def test_authorization_code
38
+ do_test('AUTHORIZATION_CODE', 'authorization_code')
39
+ end
40
+
41
+ def test_implicit
42
+ do_test('IMPLICIT', 'implicit')
43
+ end
44
+
45
+ def test_password
46
+ do_test('PASSWORD', 'password')
47
+ end
48
+
49
+ def test_client_credentials
50
+ do_test('CLIENT_CREDENTIALS', 'client_credentials')
51
+ end
52
+
53
+ def test_refresh_token
54
+ do_test('REFRESH_TOKEN', 'refresh_token')
55
+ end
56
+
57
+ def test_ciba
58
+ do_test('CIBA', 'urn:openid:params:grant-type:ciba')
59
+ end
60
+
61
+ def test_device_code
62
+ do_test('DEVICE_CODE', 'urn:ietf:params:oauth:grant-type:device_code')
63
+ end
64
+
65
+ def test_token_exchange
66
+ do_test('TOKEN_EXCHANGE', 'urn:ietf:params:oauth:grant-type:token-exchange')
67
+ end
68
+
69
+ def test_jwt_bearer
70
+ do_test('JWT_BEARER', 'urn:ietf:params:oauth:grant-type:jwt-bearer')
71
+ end
72
+ end
@@ -0,0 +1,104 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2022 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 'minitest/autorun'
20
+
21
+
22
+ class JWEAlgTest < Minitest::Test
23
+ def do_test(input, expected)
24
+ output = Authlete::Types::JWEAlg::constant_get(input)
25
+
26
+ if expected.nil?
27
+ assert_nil output
28
+ else
29
+ assert_equal expected, output
30
+ end
31
+ end
32
+
33
+ def test_unknown
34
+ do_test('UNKNOWN', nil)
35
+ end
36
+
37
+ def test_rsa1_5
38
+ do_test('RSA1_5', 'RSA1_5')
39
+ end
40
+
41
+ def test_oaep
42
+ do_test('RSA_OAEP', 'RSA-OAEP')
43
+ end
44
+
45
+ def test_oaep_256
46
+ do_test('RSA_OAEP_256', 'RSA-OAEP-256')
47
+ end
48
+
49
+ def test_a128kw
50
+ do_test('A128KW', 'A128KW')
51
+ end
52
+
53
+ def test_a192kw
54
+ do_test('A192KW', 'A192KW')
55
+ end
56
+
57
+ def test_a256kw
58
+ do_test('A256KW', 'A256KW')
59
+ end
60
+
61
+ def test_dir
62
+ do_test('DIR', 'dir')
63
+ end
64
+
65
+ def test_ecdh_es
66
+ do_test('ECDH_ES', 'ECDH-ES')
67
+ end
68
+
69
+ def test_ecdh_es_a128kw
70
+ do_test('ECDH_ES_A128KW', 'ECDH-ES+A128KW')
71
+ end
72
+
73
+ def test_ecdh_es_a192kw
74
+ do_test('ECDH_ES_A192KW', 'ECDH-ES+A192KW')
75
+ end
76
+
77
+ def test_ecdh_es_a256kw
78
+ do_test('ECDH_ES_A256KW', 'ECDH-ES+A256KW')
79
+ end
80
+
81
+ def test_a128gcmkw
82
+ do_test('A128GCMKW', 'A128GCMKW')
83
+ end
84
+
85
+ def test_a192gcmkw
86
+ do_test('A192GCMKW', 'A192GCMKW')
87
+ end
88
+
89
+ def test_a256gcmkw
90
+ do_test('A256GCMKW', 'A256GCMKW')
91
+ end
92
+
93
+ def test_pbes2_hs256_a128kw
94
+ do_test('PBES2_HS256_A128KW', 'PBES2-HS256+A128KW')
95
+ end
96
+
97
+ def test_pbes2_hs384_a192kw
98
+ do_test('PBES2_HS384_A192KW', 'PBES2-HS384+A192KW')
99
+ end
100
+
101
+ def test_pbes2_hs512_a256kw
102
+ do_test('PBES2_HS512_A256KW', 'PBES2-HS512+A256KW')
103
+ end
104
+ end
@@ -0,0 +1,60 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2022 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 'minitest/autorun'
20
+
21
+
22
+ class JWEEncTest < Minitest::Test
23
+ def do_test(input, expected)
24
+ output = Authlete::Types::JWEEnc::constant_get(input)
25
+
26
+ if expected.nil?
27
+ assert_nil output
28
+ else
29
+ assert_equal expected, output
30
+ end
31
+ end
32
+
33
+ def test_unknown
34
+ do_test('UNKNOWN', nil)
35
+ end
36
+
37
+ def test_a128cbc_hs256
38
+ do_test('A128CBC_HS256', 'A128CBC-HS256')
39
+ end
40
+
41
+ def test_a192cbc_hs384
42
+ do_test('A192CBC_HS384', 'A192CBC-HS384')
43
+ end
44
+
45
+ def test_a256cbc_hs512
46
+ do_test('A256CBC_HS512', 'A256CBC-HS512')
47
+ end
48
+
49
+ def test_a128gcm
50
+ do_test('A128GCM', 'A128GCM')
51
+ end
52
+
53
+ def test_a192gcm
54
+ do_test('A192GCM', 'A192GCM')
55
+ end
56
+
57
+ def test_a256gcm
58
+ do_test('A256GCM', 'A256GCM')
59
+ end
60
+ end