authlete 1.0.24 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Makefile +40 -0
  4. data/Rakefile +5 -0
  5. data/authlete.gemspec +2 -2
  6. data/lib/authlete.rb +28 -9
  7. data/lib/authlete/api.rb +146 -321
  8. data/lib/authlete/authentication-server.rb +2 -2
  9. data/lib/authlete/exception.rb +14 -15
  10. data/lib/authlete/model/base.rb +30 -0
  11. data/lib/authlete/model/client-extension.rb +17 -119
  12. data/lib/authlete/model/client.rb +196 -345
  13. data/lib/authlete/model/hashable.rb +13 -33
  14. data/lib/authlete/model/named-uri.rb +13 -74
  15. data/lib/authlete/model/pair.rb +13 -74
  16. data/lib/authlete/model/param-initializer.rb +45 -0
  17. data/lib/authlete/model/property.rb +15 -85
  18. data/lib/authlete/model/request/authentication-callback-request.rb +63 -55
  19. data/lib/authlete/model/request/authorization-fail-request.rb +14 -75
  20. data/lib/authlete/model/request/authorization-issue-request.rb +38 -119
  21. data/lib/authlete/model/request/authorization-request.rb +8 -73
  22. data/lib/authlete/model/request/backchannel-authentication-complete-request.rb +97 -0
  23. data/lib/authlete/model/request/backchannel-authentication-fail-request.rb +55 -0
  24. data/lib/authlete/model/request/backchannel-authentication-issue-request.rb +37 -0
  25. data/lib/authlete/model/request/backchannel-authentication-request.rb +63 -0
  26. data/lib/authlete/model/request/base.rb +26 -0
  27. data/lib/authlete/model/request/client-authorization-delete-request.rb +7 -93
  28. data/lib/authlete/model/request/client-authorization-get-list-request.rb +17 -89
  29. data/lib/authlete/model/request/client-authorization-update-request.rb +11 -86
  30. data/lib/authlete/model/request/client-registration-request.rb +49 -0
  31. data/lib/authlete/model/request/client-secret-update-request.rb +7 -89
  32. data/lib/authlete/model/request/developer-authentication-callback-request.rb +40 -43
  33. data/lib/authlete/model/request/device-authorization-request.rb +63 -0
  34. data/lib/authlete/model/request/device-complete-request.rb +99 -0
  35. data/lib/authlete/model/request/device-verification-request.rb +40 -0
  36. data/lib/authlete/model/request/granted-scopes-request.rb +8 -74
  37. data/lib/authlete/model/request/introspection-request.rb +24 -83
  38. data/lib/authlete/model/request/pushed-auth-req-request.rb +64 -0
  39. data/lib/authlete/model/request/revocation-request.rb +14 -88
  40. data/lib/authlete/model/request/standard-introspection-request.rb +8 -73
  41. data/lib/authlete/model/request/token-create-request.rb +52 -183
  42. data/lib/authlete/model/request/token-fail-request.rb +12 -74
  43. data/lib/authlete/model/request/token-issue-request.rb +22 -80
  44. data/lib/authlete/model/request/token-request.rb +44 -81
  45. data/lib/authlete/model/request/token-update-request.rb +35 -121
  46. data/lib/authlete/model/request/user-info-issue-request.rb +14 -80
  47. data/lib/authlete/model/request/user-info-request.rb +25 -70
  48. data/lib/authlete/model/response/access-token.rb +96 -0
  49. data/lib/authlete/model/response/authentication-callback-response.rb +24 -19
  50. data/lib/authlete/model/response/authorization-fail-response.rb +13 -15
  51. data/lib/authlete/model/response/authorization-issue-response.rb +29 -32
  52. data/lib/authlete/model/response/authorization-response.rb +97 -123
  53. data/lib/authlete/model/response/authorized-client-list-response.rb +37 -0
  54. data/lib/authlete/model/response/backchannel-authentication-complete-response.rb +143 -0
  55. data/lib/authlete/model/response/backchannel-authentication-fail-response.rb +47 -0
  56. data/lib/authlete/model/response/backchannel-authentication-issue-response.rb +63 -0
  57. data/lib/authlete/model/response/backchannel-authentication-response.rb +160 -0
  58. data/lib/authlete/model/response/client-list-response.rb +58 -0
  59. data/lib/authlete/model/response/client-registration-response.rb +50 -0
  60. data/lib/authlete/model/response/client-secret-refresh-response.rb +12 -12
  61. data/lib/authlete/model/response/client-secret-update-response.rb +12 -12
  62. data/lib/authlete/model/response/developer-authentication-callback-response.rb +24 -19
  63. data/lib/authlete/model/response/device-authorization-response.rb +134 -0
  64. data/lib/authlete/model/response/device-complete-response.rb +39 -0
  65. data/lib/authlete/model/response/device-verification-response.rb +96 -0
  66. data/lib/authlete/model/response/granted-scopes-get-response.rb +27 -19
  67. data/lib/authlete/model/response/introspection-response.rb +64 -58
  68. data/lib/authlete/model/response/pushed-auth-req-response.rb +59 -0
  69. data/lib/authlete/model/response/revocation-response.rb +12 -15
  70. data/lib/authlete/model/response/service-list-response.rb +54 -0
  71. data/lib/authlete/model/response/standard-introspection-response.rb +13 -15
  72. data/lib/authlete/model/response/token-create-response.rb +50 -55
  73. data/lib/authlete/model/response/token-fail-response.rb +14 -17
  74. data/lib/authlete/model/response/token-issue-response.rb +49 -62
  75. data/lib/authlete/model/response/token-list-response.rb +64 -0
  76. data/lib/authlete/model/response/token-response.rb +59 -79
  77. data/lib/authlete/model/response/token-update-response.rb +28 -23
  78. data/lib/authlete/model/response/user-info-issue-response.rb +16 -16
  79. data/lib/authlete/model/response/user-info-response.rb +48 -42
  80. data/lib/authlete/model/result.rb +14 -13
  81. data/lib/authlete/model/scope.rb +29 -119
  82. data/lib/authlete/model/service-owner.rb +32 -116
  83. data/lib/authlete/model/service.rb +464 -685
  84. data/lib/authlete/model/sns-credentials.rb +18 -91
  85. data/lib/authlete/model/tagged-value.rb +14 -69
  86. data/lib/authlete/utility.rb +3 -32
  87. data/lib/authlete/version.rb +3 -3
  88. data/test/authlete/model/request/test_authentication-callback-request.rb +100 -0
  89. data/test/authlete/model/request/test_authorization-fail-request.rb +67 -0
  90. data/test/authlete/model/request/test_authorization-issue-request.rb +94 -0
  91. data/test/authlete/model/request/test_authorization-request.rb +57 -0
  92. data/test/authlete/model/request/test_backchannel-authentication-complete-request.rb +102 -0
  93. data/test/authlete/model/request/test_backchannel-authentication-fail-request.rb +71 -0
  94. data/test/authlete/model/request/test_backchannel-authentication-issue-request.rb +57 -0
  95. data/test/authlete/model/request/test_backchannel-authentication-request.rb +75 -0
  96. data/test/authlete/model/request/test_client-authorization-delete-request.rb +57 -0
  97. data/test/authlete/model/request/test_client-authorization-get-list-request.rb +71 -0
  98. data/test/authlete/model/request/test_client-authorization-update-request.rb +63 -0
  99. data/test/authlete/model/request/test_client-registration-request.rb +68 -0
  100. data/test/authlete/model/request/test_device-authorization-request.rb +75 -0
  101. data/test/authlete/model/request/test_device-complete-request.rb +102 -0
  102. data/test/authlete/model/request/test_device-verification-request.rb +57 -0
  103. data/test/authlete/model/request/test_granted-scopes-request.rb +57 -0
  104. data/test/authlete/model/request/test_introspection-request.rb +79 -0
  105. data/test/authlete/model/request/test_pushed-auth-req-request.rb +75 -0
  106. data/test/authlete/model/request/test_revocation-request.rb +67 -0
  107. data/test/authlete/model/request/test_standard-introspection-request.rb +57 -0
  108. data/test/authlete/model/request/test_token-create-request.rb +110 -0
  109. data/test/authlete/model/request/test_token-fail-request.rb +63 -0
  110. data/test/authlete/model/request/test_token-issue-request.rb +70 -0
  111. data/test/authlete/model/request/test_token-request.rb +94 -0
  112. data/test/authlete/model/request/test_token-update-request.rb +82 -0
  113. data/test/authlete/model/request/test_user-info-issue-request.rb +67 -0
  114. data/test/authlete/model/request/test_user-info-request.rb +75 -0
  115. data/test/authlete/model/response/test_access-token.rb +101 -0
  116. data/test/authlete/model/response/test_authorization-fail-response.rb +68 -0
  117. data/test/authlete/model/response/test_authorization-issue-response.rb +92 -0
  118. data/test/authlete/model/response/test_authorization-response.rb +145 -0
  119. data/test/authlete/model/response/test_authorized-client-list-response.rb +83 -0
  120. data/test/authlete/model/response/test_backchannel-authentication-complete-response.rb +132 -0
  121. data/test/authlete/model/response/test_backchannel-authentication-fail-response.rb +68 -0
  122. data/test/authlete/model/response/test_backchannel-authentication-issue-response.rb +80 -0
  123. data/test/authlete/model/response/test_backchannel-authentication-response.rb +156 -0
  124. data/test/authlete/model/response/test_client-list-response.rb +79 -0
  125. data/test/authlete/model/response/test_client-secret-refresh-response.rb +68 -0
  126. data/test/authlete/model/response/test_client-secret-update-response.rb +68 -0
  127. data/test/authlete/model/response/test_device-authorization-response.rb +140 -0
  128. data/test/authlete/model/response/test_device-complete-response.rb +64 -0
  129. data/test/authlete/model/response/test_device-verification-response.rb +112 -0
  130. data/test/authlete/model/response/test_granted-scopes-get-response.rb +84 -0
  131. data/test/authlete/model/response/test_introspection-response.rb +127 -0
  132. data/test/authlete/model/response/test_pushed-auth-req-response.rb +76 -0
  133. data/test/authlete/model/response/test_revocation-response.rb +68 -0
  134. data/test/authlete/model/response/test_service-list-response.rb +72 -0
  135. data/test/authlete/model/response/test_standard-introspection-response.rb +68 -0
  136. data/test/authlete/model/response/test_token-create-response.rb +107 -0
  137. data/test/authlete/model/response/test_token-fail-response.rb +68 -0
  138. data/test/authlete/model/response/test_token-issue-response.rb +127 -0
  139. data/test/authlete/model/response/test_token-list-response.rb +84 -0
  140. data/test/authlete/model/response/test_token-response.rb +147 -0
  141. data/test/authlete/model/response/test_token-update-response.rb +87 -0
  142. data/test/authlete/model/response/test_user-info-issue-response.rb +68 -0
  143. data/test/authlete/model/response/test_user-info-response.rb +107 -0
  144. data/test/authlete/model/test_client-extension.rb +95 -0
  145. data/test/authlete/model/test_client.rb +461 -0
  146. data/test/authlete/model/test_named-uri.rb +85 -0
  147. data/test/authlete/model/test_pair.rb +85 -0
  148. data/test/authlete/model/test_property.rb +90 -0
  149. data/test/authlete/model/test_result.rb +68 -0
  150. data/test/authlete/model/test_scope.rb +106 -0
  151. data/test/authlete/model/test_service-owner.rb +80 -0
  152. data/test/authlete/model/test_service.rb +614 -0
  153. data/test/authlete/model/test_sns-credentials.rb +88 -0
  154. data/test/authlete/model/test_tagged-value.rb +83 -0
  155. data/test/authlete/test_exception.rb +70 -0
  156. metadata +169 -9
  157. data/lib/authlete/model/client-list.rb +0 -129
  158. data/lib/authlete/model/response/client-authorization-get-list-response.rb +0 -60
  159. data/lib/authlete/model/response/service-creatable-response.rb +0 -51
  160. data/lib/authlete/model/service-list.rb +0 -128
@@ -0,0 +1,132 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2020 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 BackchannelAuthenticationCompleteResponseTest < Minitest::Test
24
+ RESULT_CODE = '<result-code>'
25
+ RESULT_MESSAGE = '<result-message>'
26
+ ACTION = 'NOTIFICATION'
27
+ RESPONSE_CONTENT = '<response-content>'
28
+ CLIENT_ID = 12345
29
+ CLIENT_ID_ALIAS = '<client-id-alias>'
30
+ CLIENT_ID_ALIAS_USED = false
31
+ CLIENT_NAME = '<client-name>'
32
+ DELIVERY_METHOD = 'POLL'
33
+ CLIENT_NOTIFICATION_ENDPOINT = '<client-notification-endpoint>'
34
+ CLIENT_NOTIFICATION_TOKEN = '<client-notification-token>'
35
+ AUTH_REQ_ID = '<auth-req-id>'
36
+ ACCESS_TOKEN = '<access-token>'
37
+ REFRESH_TOKEN = '<refresh-token>'
38
+ ID_TOKEN = '<id-token>'
39
+ ACCESS_TOKEN_DURATION = 100
40
+ REFRESH_TOKEN_DURATION = 200
41
+ ID_TOKEN_DURATION = 300
42
+ JWT_ACCESS_TOKEN = '<jwt-access-token>'
43
+ RESOURCES = [ 'resource0', 'resource1' ]
44
+
45
+
46
+ def generate_json
47
+ return <<~JSON
48
+ {
49
+ "resultCode": "<result-code>",
50
+ "resultMessage": "<result-message>",
51
+ "action": "NOTIFICATION",
52
+ "responseContent": "<response-content>",
53
+ "clientId": 12345,
54
+ "clientIdAlias": "<client-id-alias>",
55
+ "clientIdAliasUsed": false,
56
+ "clientName": "<client-name>",
57
+ "deliveryMethod": "POLL",
58
+ "clientNotificationEndpoint": "<client-notification-endpoint>",
59
+ "clientNotificationToken": "<client-notification-token>",
60
+ "authReqId": "<auth-req-id>",
61
+ "accessToken": "<access-token>",
62
+ "refreshToken": "<refresh-token>",
63
+ "idToken": "<id-token>",
64
+ "accessTokenDuration": 100,
65
+ "refreshTokenDuration": 200,
66
+ "idTokenDuration": 300,
67
+ "jwtAccessToken": "<jwt-access-token>",
68
+ "resources": [ "resource0", "resource1" ]
69
+ }
70
+ JSON
71
+ end
72
+
73
+
74
+ def match(obj)
75
+ assert_equal RESULT_CODE, obj.resultCode
76
+ assert_equal RESULT_MESSAGE, obj.resultMessage
77
+ assert_equal ACTION, obj.action
78
+ assert_equal RESPONSE_CONTENT, obj.responseContent
79
+ assert_equal CLIENT_ID, obj.clientId
80
+ assert_equal CLIENT_ID_ALIAS, obj.clientIdAlias
81
+ assert_equal CLIENT_ID_ALIAS_USED, obj.clientIdAliasUsed
82
+ assert_equal CLIENT_NAME, obj.clientName
83
+ assert_equal DELIVERY_METHOD, obj.deliveryMethod
84
+ assert_equal CLIENT_NOTIFICATION_ENDPOINT, obj.clientNotificationEndpoint
85
+ assert_equal CLIENT_NOTIFICATION_TOKEN, obj.clientNotificationToken
86
+ assert_equal AUTH_REQ_ID, obj.authReqId
87
+ assert_equal ACCESS_TOKEN, obj.accessToken
88
+ assert_equal REFRESH_TOKEN, obj.refreshToken
89
+ assert_equal ID_TOKEN, obj.idToken
90
+ assert_equal ACCESS_TOKEN_DURATION, obj.accessTokenDuration
91
+ assert_equal REFRESH_TOKEN_DURATION, obj.refreshTokenDuration
92
+ assert_equal ID_TOKEN_DURATION, obj.idTokenDuration
93
+ assert_equal JWT_ACCESS_TOKEN, obj.jwtAccessToken
94
+ assert_equal RESOURCES, obj.resources
95
+ end
96
+
97
+
98
+ def test_from_json
99
+ jsn = generate_json
100
+ hsh = JSON.parse(jsn)
101
+ actual = Authlete::Model::Response::BackchannelAuthenticationCompleteResponse.new(hsh)
102
+
103
+ match(actual)
104
+ end
105
+
106
+
107
+ def test_setters
108
+ actual = Authlete::Model::Response::BackchannelAuthenticationCompleteResponse.new
109
+ actual.result_code = RESULT_CODE
110
+ actual.result_message = RESULT_MESSAGE
111
+ actual.action = ACTION
112
+ actual.response_content = RESPONSE_CONTENT
113
+ actual.client_id = CLIENT_ID
114
+ actual.client_id_alias = CLIENT_ID_ALIAS
115
+ actual.client_id_alias_used = CLIENT_ID_ALIAS_USED
116
+ actual.client_name = CLIENT_NAME
117
+ actual.delivery_method = DELIVERY_METHOD
118
+ actual.client_notification_endpoint = CLIENT_NOTIFICATION_ENDPOINT
119
+ actual.client_notification_token = CLIENT_NOTIFICATION_TOKEN
120
+ actual.auth_req_id = AUTH_REQ_ID
121
+ actual.access_token = ACCESS_TOKEN
122
+ actual.refresh_token = REFRESH_TOKEN
123
+ actual.id_token = ID_TOKEN
124
+ actual.access_token_duration = ACCESS_TOKEN_DURATION
125
+ actual.refresh_token_duration = REFRESH_TOKEN_DURATION
126
+ actual.id_token_duration = ID_TOKEN_DURATION
127
+ actual.jwt_access_token = JWT_ACCESS_TOKEN
128
+ actual.resources = RESOURCES
129
+
130
+ match(actual)
131
+ end
132
+ end
@@ -0,0 +1,68 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2020 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 BackchannelAuthenticationFailResponseTest < Minitest::Test
24
+ RESULT_CODE = '<result-code>'
25
+ RESULT_MESSAGE = '<result-message>'
26
+ ACTION = 'BAD_REQUEST'
27
+ RESPONSE_CONTENT = '<response-content>'
28
+
29
+
30
+ def generate_json
31
+ return <<~JSON
32
+ {
33
+ "resultCode": "<result-code>",
34
+ "resultMessage": "<result-message>",
35
+ "action": "BAD_REQUEST",
36
+ "responseContent": "<response-content>"
37
+ }
38
+ JSON
39
+ end
40
+
41
+
42
+ def match(obj)
43
+ assert_equal RESULT_CODE, obj.resultCode
44
+ assert_equal RESULT_MESSAGE, obj.resultMessage
45
+ assert_equal ACTION, obj.action
46
+ assert_equal RESPONSE_CONTENT, obj.responseContent
47
+ end
48
+
49
+
50
+ def test_from_json
51
+ jsn = generate_json
52
+ hsh = JSON.parse(jsn)
53
+ actual = Authlete::Model::Response::BackchannelAuthenticationFailResponse.new(hsh)
54
+
55
+ match(actual)
56
+ end
57
+
58
+
59
+ def test_setters
60
+ actual = Authlete::Model::Response::BackchannelAuthenticationFailResponse.new
61
+ actual.result_code = RESULT_CODE
62
+ actual.result_message = RESULT_MESSAGE
63
+ actual.action = ACTION
64
+ actual.response_content = RESPONSE_CONTENT
65
+
66
+ match(actual)
67
+ end
68
+ end
@@ -0,0 +1,80 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2020 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 BackchannelAuthenticationIssueResponseTest < Minitest::Test
24
+ RESULT_CODE = '<result-code>'
25
+ RESULT_MESSAGE = '<result-message>'
26
+ ACTION = 'OK'
27
+ RESPONSE_CONTENT = '<response-content>'
28
+ AUTH_REQ_ID = '<auth-req-id>'
29
+ EXPIRES_IN = 1000
30
+ INTERVAL = 100
31
+
32
+
33
+ def generate_json
34
+ return <<~JSON
35
+ {
36
+ "resultCode": "<result-code>",
37
+ "resultMessage": "<result-message>",
38
+ "action": "OK",
39
+ "responseContent": "<response-content>",
40
+ "authReqId": "<auth-req-id>",
41
+ "expiresIn": 1000,
42
+ "interval": 100
43
+ }
44
+ JSON
45
+ end
46
+
47
+
48
+ def match(obj)
49
+ assert_equal RESULT_CODE, obj.resultCode
50
+ assert_equal RESULT_MESSAGE, obj.resultMessage
51
+ assert_equal ACTION, obj.action
52
+ assert_equal RESPONSE_CONTENT, obj.responseContent
53
+ assert_equal AUTH_REQ_ID, obj.authReqId
54
+ assert_equal EXPIRES_IN, obj.expiresIn
55
+ assert_equal INTERVAL, obj.interval
56
+ end
57
+
58
+
59
+ def test_from_json
60
+ jsn = generate_json
61
+ hsh = JSON.parse(jsn)
62
+ actual = Authlete::Model::Response::BackchannelAuthenticationIssueResponse.new(hsh)
63
+
64
+ match(actual)
65
+ end
66
+
67
+
68
+ def test_setters
69
+ actual = Authlete::Model::Response::BackchannelAuthenticationIssueResponse.new
70
+ actual.result_code = RESULT_CODE
71
+ actual.result_message = RESULT_MESSAGE
72
+ actual.action = ACTION
73
+ actual.response_content = RESPONSE_CONTENT
74
+ actual.auth_req_id = AUTH_REQ_ID
75
+ actual.expires_in = EXPIRES_IN
76
+ actual.interval = INTERVAL
77
+
78
+ match(actual)
79
+ end
80
+ end
@@ -0,0 +1,156 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2020 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 BackchannelAuthenticationResponseTest < Minitest::Test
24
+ RESULT_CODE = '<result-code>'
25
+ RESULT_MESSAGE = '<result-message>'
26
+ ACTION = 'USER_IDENTIFICATION'
27
+ RESPONSE_CONTENT = '<response-content>'
28
+ CLIENT_ID = 12345
29
+ CLIENT_ID_ALIAS = '<client-id-alias>'
30
+ CLIENT_ID_ALIAS_USED = false
31
+ CLIENT_NAME = '<client-name>'
32
+ CLIENT_AUTH_METHOD = 'BASIC'
33
+ DELIVERY_METHOD = 'POLL'
34
+ SCOPE_NAME = "scope0"
35
+ SCOPE_DESCRIPTION = "<scope0-description>"
36
+ SCOPES = [ Authlete::Model::Scope.new(name: SCOPE_NAME, description: SCOPE_DESCRIPTION) ]
37
+ CLIENT_NAMES = [ 'client0', 'client1' ]
38
+ CLIENT_NOTIFICATION_TOKEN = '<client-notification-token>'
39
+ ACRS = [ 'acr0', 'acr1' ]
40
+ HINT_TYPE = 'LOGIN_HINT'
41
+ SUB = '<sub>'
42
+ BINDING_MESSAGE = '<binding-message>'
43
+ USER_CODE = '<user-code>'
44
+ USER_CODE_REQUIRED = true
45
+ REQUESTED_EXPIRY = 100
46
+ REQUEST_CONTEXT = '<request-context>'
47
+ RESOURCES = [ 'resource0', 'resource1' ]
48
+ WARNINGS = [ 'warning0', 'warning1' ]
49
+ TICKET = "<ticket>"
50
+
51
+
52
+ def generate_json
53
+ return <<~JSON
54
+ {
55
+ "resultCode": "<result-code>",
56
+ "resultMessage": "<result-message>",
57
+ "action": "USER_IDENTIFICATION",
58
+ "responseContent": "<response-content>",
59
+ "clientId": 12345,
60
+ "clientIdAlias": "<client-id-alias>",
61
+ "clientIdAliasUsed": false,
62
+ "clientName": "<client-name>",
63
+ "clientAuthMethod": "BASIC",
64
+ "deliveryMethod": "POLL",
65
+ "scopes": [
66
+ {
67
+ "name": "scope0",
68
+ "description": "<scope0-description>"
69
+ }
70
+ ],
71
+ "clientNames": [ "client0", "client1" ],
72
+ "clientNotificationToken": "<client-notification-token>",
73
+ "acrs": ["acr0", "acr1"],
74
+ "hintType": "LOGIN_HINT",
75
+ "sub": "<sub>",
76
+ "bindingMessage": "<binding-message>",
77
+ "userCode": "<user-code>",
78
+ "userCodeRequired": true,
79
+ "requestedExpiry": 100,
80
+ "requestContext": "<request-context>",
81
+ "resources": [ "resource0", "resource1" ],
82
+ "warnings": [ "warning0", "warning1" ],
83
+ "ticket": "<ticket>"
84
+ }
85
+ JSON
86
+ end
87
+
88
+
89
+ def match(obj)
90
+ assert_equal RESULT_CODE, obj.resultCode
91
+ assert_equal RESULT_MESSAGE, obj.resultMessage
92
+ assert_equal ACTION, obj.action
93
+ assert_equal RESPONSE_CONTENT, obj.responseContent
94
+ assert_equal CLIENT_ID, obj.clientId
95
+ assert_equal CLIENT_ID_ALIAS, obj.clientIdAlias
96
+ assert_equal CLIENT_ID_ALIAS_USED, obj.clientIdAliasUsed
97
+ assert_equal CLIENT_NAME, obj.clientName
98
+ assert_equal CLIENT_AUTH_METHOD, obj.clientAuthMethod
99
+ assert_equal DELIVERY_METHOD, obj.deliveryMethod
100
+ assert_equal SCOPE_NAME, obj.scopes[0].name
101
+ assert_equal SCOPE_DESCRIPTION, obj.scopes[0].description
102
+ assert_equal CLIENT_NAMES, obj.clientNames
103
+ assert_equal CLIENT_NOTIFICATION_TOKEN, obj.clientNotificationToken
104
+ assert_equal ACRS, obj.acrs
105
+ assert_equal HINT_TYPE, obj.hintType
106
+ assert_equal SUB, obj.sub
107
+ assert_equal BINDING_MESSAGE, obj.bindingMessage
108
+ assert_equal USER_CODE, obj.userCode
109
+ assert_equal USER_CODE_REQUIRED, obj.userCodeRequired
110
+ assert_equal REQUESTED_EXPIRY, obj.requestedExpiry
111
+ assert_equal REQUEST_CONTEXT, obj.requestContext
112
+ assert_equal RESOURCES, obj.resources
113
+ assert_equal WARNINGS, obj.warnings
114
+ assert_equal TICKET, obj.ticket
115
+ end
116
+
117
+
118
+ def test_from_json
119
+ jsn = generate_json
120
+ hsh = JSON.parse(jsn)
121
+ actual = Authlete::Model::Response::BackchannelAuthenticationResponse.new(hsh)
122
+
123
+ match(actual)
124
+ end
125
+
126
+
127
+ def test_setters
128
+ actual = Authlete::Model::Response::BackchannelAuthenticationResponse.new
129
+ actual.result_code = RESULT_CODE
130
+ actual.result_message = RESULT_MESSAGE
131
+ actual.action = ACTION
132
+ actual.response_content = RESPONSE_CONTENT
133
+ actual.client_id = CLIENT_ID
134
+ actual.client_id_alias = CLIENT_ID_ALIAS
135
+ actual.client_id_alias_used = CLIENT_ID_ALIAS_USED
136
+ actual.client_name = CLIENT_NAME
137
+ actual.client_auth_method = CLIENT_AUTH_METHOD
138
+ actual.delivery_method = DELIVERY_METHOD
139
+ actual.scopes = SCOPES
140
+ actual.client_names = CLIENT_NAMES
141
+ actual.client_notification_token = CLIENT_NOTIFICATION_TOKEN
142
+ actual.acrs = ACRS
143
+ actual.hint_type = HINT_TYPE
144
+ actual.sub = SUB
145
+ actual.binding_message = BINDING_MESSAGE
146
+ actual.user_code = USER_CODE
147
+ actual.user_code_required = USER_CODE_REQUIRED
148
+ actual.requested_expiry = REQUESTED_EXPIRY
149
+ actual.request_context = REQUEST_CONTEXT
150
+ actual.resources = RESOURCES
151
+ actual.warnings = WARNINGS
152
+ actual.ticket = TICKET
153
+
154
+ match(actual)
155
+ end
156
+ end
@@ -0,0 +1,79 @@
1
+ # :nodoc:
2
+ #
3
+ # Copyright (C) 2014-2020 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 ClientListResponseTest < Minitest::Test
24
+ START_PARAM = 0
25
+ END_PARAM = 2
26
+ DEVELOPER = '<developer>'
27
+ TOTAL_COUNT = 2
28
+ CLIENT0_NAME = 'client0'
29
+ CLIENT1_NAME = 'client1'
30
+ CLIENTS = [ Authlete::Model::Client.new(clientName: CLIENT0_NAME, developer: DEVELOPER),
31
+ Authlete::Model::Client.new(clientName: CLIENT1_NAME, developer: DEVELOPER) ]
32
+
33
+
34
+ def generate_json
35
+ return <<~JSON
36
+ {
37
+ "start": 0,
38
+ "end": 2,
39
+ "developer": "<developer>",
40
+ "totalCount": 2,
41
+ "clients": [ { "clientName": "client0", "developer": "<developer>" },
42
+ { "clientName": "client1", "developer": "<developer>" } ]
43
+ }
44
+ JSON
45
+ end
46
+
47
+
48
+ def match(obj)
49
+ assert_equal START_PARAM, obj.start
50
+ assert_equal END_PARAM, obj.end
51
+ assert_equal DEVELOPER, obj.developer
52
+ assert_equal TOTAL_COUNT, obj.totalCount
53
+ assert_equal CLIENT0_NAME, obj.clients[0].clientName
54
+ assert_equal DEVELOPER, obj.clients[0].developer
55
+ assert_equal CLIENT1_NAME, obj.clients[1].clientName
56
+ assert_equal DEVELOPER, obj.clients[1].developer
57
+ end
58
+
59
+
60
+ def test_from_json
61
+ jsn = generate_json
62
+ hsh = JSON.parse(jsn)
63
+ actual = Authlete::Model::Response::ClientListResponse.new(hsh)
64
+
65
+ match(actual)
66
+ end
67
+
68
+
69
+ def test_setters
70
+ actual = Authlete::Model::Response::ClientListResponse.new
71
+ actual.start = START_PARAM
72
+ actual.end = END_PARAM
73
+ actual.developer = DEVELOPER
74
+ actual.total_count = TOTAL_COUNT
75
+ actual.clients = CLIENTS
76
+
77
+ match(actual)
78
+ end
79
+ end