descope 1.0.4

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.
Files changed (197) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yaml +54 -0
  3. data/.gitignore +59 -0
  4. data/.release-please-manifest.json +3 -0
  5. data/.rubocop.yml +10 -0
  6. data/.rubocop_todo.yml +10 -0
  7. data/.ruby-version +1 -0
  8. data/CHANGELOG.md +90 -0
  9. data/Gemfile +22 -0
  10. data/Gemfile.lock +204 -0
  11. data/LICENSE +21 -0
  12. data/README.md +1171 -0
  13. data/Rakefile +31 -0
  14. data/descope.gemspec +34 -0
  15. data/examples/ruby/Gemfile +4 -0
  16. data/examples/ruby/Gemfile.lock +41 -0
  17. data/examples/ruby/access_key_app.rb +45 -0
  18. data/examples/ruby/enchantedlink_app.rb +65 -0
  19. data/examples/ruby/magiclink_app.rb +81 -0
  20. data/examples/ruby/management/Gemfile +5 -0
  21. data/examples/ruby/management/Gemfile.lock +38 -0
  22. data/examples/ruby/management/access_key_app.rb +71 -0
  23. data/examples/ruby/management/audit_app.rb +25 -0
  24. data/examples/ruby/management/authz_app.rb +135 -0
  25. data/examples/ruby/management/authz_files.json +229 -0
  26. data/examples/ruby/management/flow_app.rb +57 -0
  27. data/examples/ruby/management/permission_app.rb +56 -0
  28. data/examples/ruby/management/role_app.rb +58 -0
  29. data/examples/ruby/management/tenant_app.rb +60 -0
  30. data/examples/ruby/management/user_app.rb +60 -0
  31. data/examples/ruby/oauth_app.rb +39 -0
  32. data/examples/ruby/otp_app.rb +50 -0
  33. data/examples/ruby/password_app.rb +76 -0
  34. data/examples/ruby/saml_app.rb +38 -0
  35. data/examples/ruby-on-rails-api/descope/.dockerignore +37 -0
  36. data/examples/ruby-on-rails-api/descope/.gitattributes +9 -0
  37. data/examples/ruby-on-rails-api/descope/.gitignore +40 -0
  38. data/examples/ruby-on-rails-api/descope/.node-version +1 -0
  39. data/examples/ruby-on-rails-api/descope/.ruby-version +1 -0
  40. data/examples/ruby-on-rails-api/descope/Dockerfile +75 -0
  41. data/examples/ruby-on-rails-api/descope/Gemfile +67 -0
  42. data/examples/ruby-on-rails-api/descope/Gemfile.lock +284 -0
  43. data/examples/ruby-on-rails-api/descope/Procfile.dev +3 -0
  44. data/examples/ruby-on-rails-api/descope/README.md +54 -0
  45. data/examples/ruby-on-rails-api/descope/Rakefile +6 -0
  46. data/examples/ruby-on-rails-api/descope/app/assets/builds/.keep +0 -0
  47. data/examples/ruby-on-rails-api/descope/app/assets/config/manifest.js +3 -0
  48. data/examples/ruby-on-rails-api/descope/app/assets/images/.keep +0 -0
  49. data/examples/ruby-on-rails-api/descope/app/assets/images/descope.jpeg +0 -0
  50. data/examples/ruby-on-rails-api/descope/app/assets/images/favicon.ico +0 -0
  51. data/examples/ruby-on-rails-api/descope/app/assets/images/logo192.png +0 -0
  52. data/examples/ruby-on-rails-api/descope/app/assets/images/logo512.png +0 -0
  53. data/examples/ruby-on-rails-api/descope/app/assets/stylesheets/application.bootstrap.scss +67 -0
  54. data/examples/ruby-on-rails-api/descope/app/channels/application_cable/channel.rb +4 -0
  55. data/examples/ruby-on-rails-api/descope/app/channels/application_cable/connection.rb +4 -0
  56. data/examples/ruby-on-rails-api/descope/app/controllers/application_controller.rb +2 -0
  57. data/examples/ruby-on-rails-api/descope/app/controllers/concerns/.keep +0 -0
  58. data/examples/ruby-on-rails-api/descope/app/controllers/homepage_controller.rb +4 -0
  59. data/examples/ruby-on-rails-api/descope/app/controllers/session_controller.rb +66 -0
  60. data/examples/ruby-on-rails-api/descope/app/helpers/application_helper.rb +2 -0
  61. data/examples/ruby-on-rails-api/descope/app/helpers/homepage_helper.rb +2 -0
  62. data/examples/ruby-on-rails-api/descope/app/helpers/session_helper.rb +2 -0
  63. data/examples/ruby-on-rails-api/descope/app/javascript/App.css +53 -0
  64. data/examples/ruby-on-rails-api/descope/app/javascript/application.js +5 -0
  65. data/examples/ruby-on-rails-api/descope/app/javascript/components/App.jsx +4 -0
  66. data/examples/ruby-on-rails-api/descope/app/javascript/components/Dashboard.jsx +60 -0
  67. data/examples/ruby-on-rails-api/descope/app/javascript/components/Home.jsx +27 -0
  68. data/examples/ruby-on-rails-api/descope/app/javascript/components/Login.jsx +45 -0
  69. data/examples/ruby-on-rails-api/descope/app/javascript/components/Profile.jsx +81 -0
  70. data/examples/ruby-on-rails-api/descope/app/javascript/components/index.html +11 -0
  71. data/examples/ruby-on-rails-api/descope/app/javascript/components/index.jsx +24 -0
  72. data/examples/ruby-on-rails-api/descope/app/javascript/controllers/application.js +9 -0
  73. data/examples/ruby-on-rails-api/descope/app/javascript/controllers/index.js +5 -0
  74. data/examples/ruby-on-rails-api/descope/app/javascript/reportWebVitals.js +13 -0
  75. data/examples/ruby-on-rails-api/descope/app/javascript/routes/index.jsx +17 -0
  76. data/examples/ruby-on-rails-api/descope/app/jobs/application_job.rb +7 -0
  77. data/examples/ruby-on-rails-api/descope/app/mailers/application_mailer.rb +4 -0
  78. data/examples/ruby-on-rails-api/descope/app/models/application_record.rb +3 -0
  79. data/examples/ruby-on-rails-api/descope/app/models/concerns/.keep +0 -0
  80. data/examples/ruby-on-rails-api/descope/app/views/homepage/index.html.erb +2 -0
  81. data/examples/ruby-on-rails-api/descope/app/views/layouts/application.html.erb +16 -0
  82. data/examples/ruby-on-rails-api/descope/app/views/layouts/mailer.html.erb +13 -0
  83. data/examples/ruby-on-rails-api/descope/app/views/layouts/mailer.text.erb +1 -0
  84. data/examples/ruby-on-rails-api/descope/app/views/session/index.html.erb +2 -0
  85. data/examples/ruby-on-rails-api/descope/bin/bundle +109 -0
  86. data/examples/ruby-on-rails-api/descope/bin/dev +11 -0
  87. data/examples/ruby-on-rails-api/descope/bin/docker-entrypoint +8 -0
  88. data/examples/ruby-on-rails-api/descope/bin/rails +4 -0
  89. data/examples/ruby-on-rails-api/descope/bin/rake +4 -0
  90. data/examples/ruby-on-rails-api/descope/bin/setup +36 -0
  91. data/examples/ruby-on-rails-api/descope/build.js +30 -0
  92. data/examples/ruby-on-rails-api/descope/config/application.rb +42 -0
  93. data/examples/ruby-on-rails-api/descope/config/boot.rb +4 -0
  94. data/examples/ruby-on-rails-api/descope/config/cable.yml +10 -0
  95. data/examples/ruby-on-rails-api/descope/config/config.yml +9 -0
  96. data/examples/ruby-on-rails-api/descope/config/credentials.yml.enc +1 -0
  97. data/examples/ruby-on-rails-api/descope/config/database.yml +25 -0
  98. data/examples/ruby-on-rails-api/descope/config/environment.rb +5 -0
  99. data/examples/ruby-on-rails-api/descope/config/environments/development.rb +76 -0
  100. data/examples/ruby-on-rails-api/descope/config/environments/production.rb +97 -0
  101. data/examples/ruby-on-rails-api/descope/config/environments/test.rb +64 -0
  102. data/examples/ruby-on-rails-api/descope/config/initializers/assets.rb +13 -0
  103. data/examples/ruby-on-rails-api/descope/config/initializers/content_security_policy.rb +25 -0
  104. data/examples/ruby-on-rails-api/descope/config/initializers/filter_parameter_logging.rb +8 -0
  105. data/examples/ruby-on-rails-api/descope/config/initializers/inflections.rb +16 -0
  106. data/examples/ruby-on-rails-api/descope/config/initializers/load_config.rb +12 -0
  107. data/examples/ruby-on-rails-api/descope/config/initializers/permissions_policy.rb +13 -0
  108. data/examples/ruby-on-rails-api/descope/config/locales/en.yml +31 -0
  109. data/examples/ruby-on-rails-api/descope/config/puma.rb +35 -0
  110. data/examples/ruby-on-rails-api/descope/config/routes.rb +18 -0
  111. data/examples/ruby-on-rails-api/descope/config/storage.yml +34 -0
  112. data/examples/ruby-on-rails-api/descope/config.ru +6 -0
  113. data/examples/ruby-on-rails-api/descope/db/seeds.rb +9 -0
  114. data/examples/ruby-on-rails-api/descope/lib/assets/.keep +0 -0
  115. data/examples/ruby-on-rails-api/descope/lib/tasks/.keep +0 -0
  116. data/examples/ruby-on-rails-api/descope/log/.keep +0 -0
  117. data/examples/ruby-on-rails-api/descope/package-lock.json +19680 -0
  118. data/examples/ruby-on-rails-api/descope/package.json +51 -0
  119. data/examples/ruby-on-rails-api/descope/public/404.html +67 -0
  120. data/examples/ruby-on-rails-api/descope/public/422.html +67 -0
  121. data/examples/ruby-on-rails-api/descope/public/500.html +66 -0
  122. data/examples/ruby-on-rails-api/descope/public/apple-touch-icon-precomposed.png +0 -0
  123. data/examples/ruby-on-rails-api/descope/public/apple-touch-icon.png +0 -0
  124. data/examples/ruby-on-rails-api/descope/public/favicon.ico +0 -0
  125. data/examples/ruby-on-rails-api/descope/public/robots.txt +1 -0
  126. data/examples/ruby-on-rails-api/descope/storage/.keep +0 -0
  127. data/examples/ruby-on-rails-api/descope/tmp/.keep +0 -0
  128. data/examples/ruby-on-rails-api/descope/tmp/pids/.keep +0 -0
  129. data/examples/ruby-on-rails-api/descope/tmp/storage/.keep +0 -0
  130. data/examples/ruby-on-rails-api/descope/vendor/.keep +0 -0
  131. data/examples/ruby-on-rails-api/descope/yarn.lock +10780 -0
  132. data/lib/descope/api/v1/auth/enchantedlink.rb +156 -0
  133. data/lib/descope/api/v1/auth/magiclink.rb +170 -0
  134. data/lib/descope/api/v1/auth/oauth.rb +72 -0
  135. data/lib/descope/api/v1/auth/otp.rb +186 -0
  136. data/lib/descope/api/v1/auth/password.rb +100 -0
  137. data/lib/descope/api/v1/auth/saml.rb +48 -0
  138. data/lib/descope/api/v1/auth/totp.rb +72 -0
  139. data/lib/descope/api/v1/auth.rb +452 -0
  140. data/lib/descope/api/v1/management/access_key.rb +81 -0
  141. data/lib/descope/api/v1/management/audit.rb +82 -0
  142. data/lib/descope/api/v1/management/authz.rb +165 -0
  143. data/lib/descope/api/v1/management/common.rb +147 -0
  144. data/lib/descope/api/v1/management/flow.rb +55 -0
  145. data/lib/descope/api/v1/management/password.rb +58 -0
  146. data/lib/descope/api/v1/management/permission.rb +48 -0
  147. data/lib/descope/api/v1/management/project.rb +53 -0
  148. data/lib/descope/api/v1/management/role.rb +48 -0
  149. data/lib/descope/api/v1/management/scim.rb +206 -0
  150. data/lib/descope/api/v1/management/sso_settings.rb +153 -0
  151. data/lib/descope/api/v1/management/tenant.rb +71 -0
  152. data/lib/descope/api/v1/management/user.rb +619 -0
  153. data/lib/descope/api/v1/management.rb +38 -0
  154. data/lib/descope/api/v1/session.rb +84 -0
  155. data/lib/descope/api/v1.rb +13 -0
  156. data/lib/descope/client.rb +6 -0
  157. data/lib/descope/exception.rb +50 -0
  158. data/lib/descope/mixins/common.rb +129 -0
  159. data/lib/descope/mixins/headers.rb +15 -0
  160. data/lib/descope/mixins/http.rb +133 -0
  161. data/lib/descope/mixins/initializer.rb +80 -0
  162. data/lib/descope/mixins/logging.rb +30 -0
  163. data/lib/descope/mixins/validation.rb +79 -0
  164. data/lib/descope/mixins.rb +22 -0
  165. data/lib/descope/version.rb +7 -0
  166. data/lib/descope.rb +9 -0
  167. data/lib/descope_client.rb +5 -0
  168. data/release-please-config.json +18 -0
  169. data/renovate.json +6 -0
  170. data/spec/factories/user.rb +16 -0
  171. data/spec/lib.descope/api/v1/auth/enchantedlink_spec.rb +159 -0
  172. data/spec/lib.descope/api/v1/auth/magiclink_spec.rb +282 -0
  173. data/spec/lib.descope/api/v1/auth/oauth_spec.rb +117 -0
  174. data/spec/lib.descope/api/v1/auth/otp_spec.rb +285 -0
  175. data/spec/lib.descope/api/v1/auth/password_spec.rb +124 -0
  176. data/spec/lib.descope/api/v1/auth/saml_spec.rb +55 -0
  177. data/spec/lib.descope/api/v1/auth/totp_spec.rb +70 -0
  178. data/spec/lib.descope/api/v1/auth_spec.rb +372 -0
  179. data/spec/lib.descope/api/v1/management/access_key_spec.rb +118 -0
  180. data/spec/lib.descope/api/v1/management/audit_spec.rb +78 -0
  181. data/spec/lib.descope/api/v1/management/authz_spec.rb +336 -0
  182. data/spec/lib.descope/api/v1/management/flow_spec.rb +78 -0
  183. data/spec/lib.descope/api/v1/management/password_spec.rb +25 -0
  184. data/spec/lib.descope/api/v1/management/permission_spec.rb +81 -0
  185. data/spec/lib.descope/api/v1/management/project_spec.rb +63 -0
  186. data/spec/lib.descope/api/v1/management/role_spec.rb +85 -0
  187. data/spec/lib.descope/api/v1/management/scim_spec.rb +312 -0
  188. data/spec/lib.descope/api/v1/management/sso_settings_spec.rb +172 -0
  189. data/spec/lib.descope/api/v1/management/tenant_spec.rb +141 -0
  190. data/spec/lib.descope/api/v1/management/user_spec.rb +667 -0
  191. data/spec/lib.descope/api/v1/session_spec.rb +117 -0
  192. data/spec/lib.descope/client_spec.rb +40 -0
  193. data/spec/spec_helper.rb +72 -0
  194. data/spec/support/client_config.rb +14 -0
  195. data/spec/support/dummy_class.rb +36 -0
  196. data/spec/support/utils.rb +32 -0
  197. metadata +420 -0
@@ -0,0 +1,336 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::Authz do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::Authz)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.save_schema' do
13
+ it 'should respond to .save_schema' do
14
+ expect(@instance).to respond_to :authz_save_schema
15
+ end
16
+
17
+ it 'is expected to create or update ReBac schema' do
18
+ schema = {
19
+ name: 'name-of-schema',
20
+ namespaces: [
21
+ {
22
+ name: 'name-of-namespace',
23
+ relationDefinitions: [
24
+ {
25
+ name: 'name-of-relation-definition',
26
+ complexDefinition: {
27
+ nType: 'child',
28
+ expression: {
29
+ neType: 'self'
30
+ }
31
+ }
32
+ }
33
+ ]
34
+ }
35
+ ]
36
+ }
37
+ expect(@instance).to receive(:post).with(
38
+ AUTHZ_SCHEMA_SAVE,
39
+ {
40
+ schema: schema,
41
+ upgrade: true
42
+ }
43
+ )
44
+ expect do
45
+ @instance.authz_save_schema(schema: schema, upgrade: true)
46
+ end.not_to raise_error
47
+ end
48
+ end
49
+
50
+ context '.delete_schema' do
51
+ it 'should respond to .delete_schema' do
52
+ expect(@instance).to respond_to :authz_delete_schema
53
+ end
54
+
55
+ it 'is expected to delete the schema for the project which will also delete all relations' do
56
+ expect(@instance).to receive(:post).with(AUTHZ_SCHEMA_DELETE)
57
+ expect do
58
+ @instance.authz_delete_schema
59
+ end.not_to raise_error
60
+ end
61
+ end
62
+
63
+ context '.load_schema' do
64
+ it 'should respond to .load_schema' do
65
+ expect(@instance).to respond_to :authz_load_schema
66
+ end
67
+
68
+ it 'is expected to load the schema for the project' do
69
+ expect(@instance).to receive(:post).with(AUTHZ_SCHEMA_LOAD)
70
+ expect do
71
+ @instance.authz_load_schema
72
+ end.not_to raise_error
73
+ end
74
+ end
75
+
76
+ context '.save_namespace' do
77
+ it 'should respond to .save_namespace' do
78
+ expect(@instance).to respond_to :authz_save_namespace
79
+ end
80
+
81
+ it 'is expected to create or update the given namespace' do
82
+ expect(@instance).to receive(:post).with(
83
+ AUTHZ_NS_SAVE,
84
+ {
85
+ namespace: 'test-namespace',
86
+ oldName: 'old-namespace',
87
+ schemaName: 'schema-name'
88
+ }
89
+ )
90
+ expect do
91
+ @instance.authz_save_namespace(namespace: 'test-namespace', old_name: 'old-namespace', schema_name: 'schema-name')
92
+ end.not_to raise_error
93
+ end
94
+ end
95
+
96
+ context '.delete_namespace' do
97
+ it 'should respond to .delete_namespace' do
98
+ expect(@instance).to respond_to :authz_delete_namespace
99
+ end
100
+
101
+ it 'is expected to delete the given namespace' do
102
+ expect(@instance).to receive(:post).with(
103
+ AUTHZ_NS_DELETE,
104
+ {
105
+ name: 'test-namespace',
106
+ schemaName: 'schema-name'
107
+ }
108
+ )
109
+ expect do
110
+ @instance.authz_delete_namespace(name: 'test-namespace', schema_name: 'schema-name')
111
+ end.not_to raise_error
112
+ end
113
+ end
114
+
115
+ context '.save_relation_definition' do
116
+ it 'should respond to .save_relation_definition' do
117
+ expect(@instance).to respond_to :authz_save_relation_definition
118
+ end
119
+
120
+ it 'is expected to create or update the given relation definition' do
121
+ expect(@instance).to receive(:post).with(
122
+ AUTHZ_RD_SAVE,
123
+ {
124
+ relationDefinition: 'test-relation-definition',
125
+ namespace: 'test-namespace',
126
+ old_name: 'old-relation-definition',
127
+ schemaName: 'schema-name'
128
+ }
129
+ )
130
+ expect do
131
+ @instance.authz_save_relation_definition(
132
+ relation_definition: 'test-relation-definition',
133
+ namespace: 'test-namespace',
134
+ old_name: 'old-relation-definition',
135
+ schema_name: 'schema-name'
136
+ )
137
+ end.not_to raise_error
138
+ end
139
+ end
140
+
141
+ context '.delete_relation_definition' do
142
+ it 'should respond to .delete_relation_definition' do
143
+ expect(@instance).to respond_to :authz_delete_relation_definition
144
+ end
145
+
146
+ it 'is expected to delete the given relation definition' do
147
+ expect(@instance).to receive(:post).with(
148
+ AUTHZ_RD_DELETE,
149
+ {
150
+ name: 'test-relation-definition',
151
+ namespace: 'test-namespace',
152
+ schemaName: 'schema-name'
153
+ }
154
+ )
155
+ expect do
156
+ @instance.authz_delete_relation_definition(
157
+ name: 'test-relation-definition',
158
+ namespace: 'test-namespace',
159
+ schema_name: 'schema-name'
160
+ )
161
+ end.not_to raise_error
162
+ end
163
+ end
164
+
165
+ context '.create_relation' do
166
+ it 'should respond to .create_relation' do
167
+ expect(@instance).to respond_to :authz_create_relations
168
+ end
169
+
170
+ it 'is expected to create the given relation' do
171
+ expect(@instance).to receive(:post).with(
172
+ AUTHZ_RE_CREATE,
173
+ {
174
+ relations: 'test-relations'
175
+ }
176
+ )
177
+ expect do
178
+ @instance.authz_create_relations('test-relations')
179
+ end.not_to raise_error
180
+ end
181
+ end
182
+
183
+ context '.delete_relation' do
184
+ it 'should respond to .delete_relation' do
185
+ expect(@instance).to respond_to :authz_delete_relations
186
+ end
187
+
188
+ it 'is expected to delete the given relation' do
189
+ expect(@instance).to receive(:post).with(
190
+ AUTHZ_RE_DELETE,
191
+ { relations: [{ resource: 'some-note', relationDefinition: 'owner', namespace: 'note', target: 'some-user' }] }
192
+ )
193
+ expect do
194
+ @instance.authz_delete_relations(
195
+ [{ resource: 'some-note', relationDefinition: 'owner', namespace: 'note', target: 'some-user' }]
196
+ )
197
+ end.not_to raise_error
198
+ end
199
+ end
200
+
201
+ context '.delete_relations_for_resources' do
202
+ it 'should respond to .delete_relations_for_resources' do
203
+ expect(@instance).to respond_to :authz_delete_relations_for_resources
204
+ end
205
+
206
+ it 'is expected to delete the given relations for resources' do
207
+ expect(@instance).to receive(:post).with(
208
+ AUTHZ_RE_DELETE_RESOURCES,
209
+ {
210
+ resources: 'test-resources'
211
+ }
212
+ )
213
+ expect do
214
+ @instance.authz_delete_relations_for_resources('test-resources')
215
+ end.not_to raise_error
216
+ end
217
+ end
218
+
219
+ context 'has_relations?' do
220
+ it 'should respond to .has_relations?' do
221
+ expect(@instance).to respond_to :authz_has_relations?
222
+ end
223
+
224
+ it 'is expected to return true if the given resource has relations' do
225
+ expect(@instance).to receive(:post).with(
226
+ AUTHZ_RE_HAS_RELATIONS,
227
+ {
228
+ relationQueries: ['some-query']
229
+ }
230
+ )
231
+ expect do
232
+ @instance.authz_has_relations?(['some-query'])
233
+ end.not_to raise_error
234
+ end
235
+ end
236
+
237
+ context 'who_can_access?' do
238
+ it 'should respond to .who_can_access?' do
239
+ expect(@instance).to respond_to :authz_who_can_access?
240
+ end
241
+
242
+ it 'is expected to return the list of targets who can access the given resource with the given RD' do
243
+ expect(@instance).to receive(:post).with(
244
+ AUTHZ_RE_WHO,
245
+ {
246
+ resource: 'test-resource',
247
+ relationDefinition: 'test-relation-definition',
248
+ namespace: 'test-namespace'
249
+ }
250
+ )
251
+ expect do
252
+ @instance.authz_who_can_access?(resource: 'test-resource', relation_definition: 'test-relation-definition',
253
+ namespace: 'test-namespace')
254
+ end.not_to raise_error
255
+ end
256
+ end
257
+
258
+ context 'resource_relations' do
259
+ it 'should respond to .resource_relations' do
260
+ expect(@instance).to respond_to :authz_resource_relations
261
+ end
262
+
263
+ it 'is expected to return the list of relations for the given resources' do
264
+ expect(@instance).to receive(:post).with(
265
+ AUTHZ_RE_RESOURCE,
266
+ {
267
+ resources: ['test-resources']
268
+ }
269
+ )
270
+ expect do
271
+ @instance.authz_resource_relations(resources: ['test-resources'])
272
+ end.not_to raise_error
273
+ end
274
+ end
275
+
276
+ context 'target_relations' do
277
+ it 'should respond to .target_relations' do
278
+ expect(@instance).to respond_to :authz_target_relations
279
+ end
280
+
281
+ it 'is expected to return the list of relations for the given targets' do
282
+ expect(@instance).to receive(:post).with(
283
+ AUTHZ_RE_TARGETS,
284
+ {
285
+ targets: ['test-targets']
286
+ }
287
+ )
288
+ expect do
289
+ @instance.authz_target_relations(targets: ['test-targets'])
290
+ end.not_to raise_error
291
+ end
292
+ end
293
+
294
+ context 'what_can_target_access?' do
295
+ let(:mock_response) do
296
+ {
297
+ 'relations' => [
298
+ {
299
+ 'relationDefinition' => 'test-relation-definition',
300
+ 'namespace' => 'test-namespace',
301
+ 'targets' => ['test-targets'],
302
+ 'resources' => ['test-resources']
303
+ }
304
+ ]
305
+ }
306
+ end
307
+
308
+ before do
309
+ allow(@instance).to receive(:post).with(
310
+ AUTHZ_RE_TARGET_ALL,
311
+ {
312
+ target: 'test-target'
313
+ }
314
+ ).and_return(mock_response)
315
+ end
316
+
317
+ it 'should respond to .what_can_target_access?' do
318
+ expect(@instance).to respond_to :authz_what_can_target_access?
319
+ end
320
+
321
+ it 'is expected to return the list of relations for the given target' do
322
+ expect(@instance).to receive(:post).with(
323
+ AUTHZ_RE_TARGET_ALL,
324
+ {
325
+ target: 'test-target'
326
+ }
327
+ )
328
+ res = nil
329
+ expect do
330
+ res = @instance.authz_what_can_target_access?(target: 'test-target')
331
+ end.not_to raise_error
332
+ expect(res).to be_a(Array)
333
+ expect(res.size).to eq(1)
334
+ end
335
+ end
336
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::Flow do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::Flow)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.list_or_search_flows' do
13
+ it 'should respond to .list_or_search_flows' do
14
+ expect(@instance).to respond_to :list_or_search_flows
15
+ end
16
+
17
+ it 'is expected to get flows' do
18
+ expect(@instance).to receive(:post).with(FLOW_LIST_PATH, { ids: %w[123 456] })
19
+ expect { @instance.list_or_search_flows(%w[123 456]) }.not_to raise_error
20
+ end
21
+ end
22
+
23
+ context '.export_flow' do
24
+ it 'should respond to .export_flow' do
25
+ expect(@instance).to respond_to :export_flow
26
+ end
27
+
28
+ it 'is expected to export flow' do
29
+ expect(@instance).to receive(:post).with(FLOW_EXPORT_PATH, { flowId: '123' })
30
+ expect { @instance.export_flow('123') }.not_to raise_error
31
+ end
32
+ end
33
+
34
+ context '.import_flow' do
35
+ it 'should respond to .import_flow' do
36
+ expect(@instance).to respond_to :import_flow
37
+ end
38
+
39
+ it 'is expected to import flow' do
40
+ expect(@instance).to receive(:post).with(
41
+ FLOW_IMPORT_PATH, {
42
+ flowId: '123',
43
+ flow: 'flow',
44
+ screens: %w[sign_up sign_in]
45
+ }
46
+ )
47
+ expect do
48
+ @instance.import_flow(
49
+ flow_id: '123',
50
+ flow: 'flow',
51
+ screens: %w[sign_up sign_in]
52
+ )
53
+ end.not_to raise_error
54
+ end
55
+ end
56
+
57
+ context '.export_theme' do
58
+ it 'should respond to .export_theme' do
59
+ expect(@instance).to respond_to :export_theme
60
+ end
61
+
62
+ it 'is expected to export theme' do
63
+ expect(@instance).to receive(:post).with(THEME_EXPORT_PATH)
64
+ expect { @instance.export_theme }.not_to raise_error
65
+ end
66
+ end
67
+
68
+ context '.import_theme' do
69
+ it 'should respond to .import_theme' do
70
+ expect(@instance).to respond_to :import_theme
71
+ end
72
+
73
+ it 'is expected to import theme' do
74
+ expect(@instance).to receive(:post).with(THEME_IMPORT_PATH, { theme: 'theme123' })
75
+ expect { @instance.import_theme('theme123') }.not_to raise_error
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::Password do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::Password)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.get_password_settings' do
13
+ it 'should get password settings' do
14
+ expect(@instance).to receive(:get).with('/v1/mgmt/password/settings', { tenantId: 'tenant_id' })
15
+ @instance.get_password_settings('tenant_id')
16
+ end
17
+ end
18
+
19
+ context '.update_password_settings' do
20
+ it 'should update password settings' do
21
+ expect(@instance).to receive(:post).with('/v1/mgmt/password/settings', { 'minLength' => 10 })
22
+ @instance.update_password_settings({ min_length: 10 })
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::Permission do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::Permission)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.create_permission' do
13
+ it 'should respond to .create_permission' do
14
+ expect(@instance).to respond_to :create_permission
15
+ end
16
+
17
+ it 'is expected to create a new permission' do
18
+ expect(@instance).to receive(:post).with(
19
+ PERMISSION_CREATE_PATH, {
20
+ name: 'test',
21
+ description: 'test'
22
+ }
23
+ )
24
+ expect do
25
+ @instance.create_permission(
26
+ name: 'test',
27
+ description: 'test'
28
+ )
29
+ end.not_to raise_error
30
+ end
31
+ end
32
+
33
+ context '.update_permission' do
34
+ it 'should respond to .update_permission' do
35
+ expect(@instance).to respond_to :update_permission
36
+ end
37
+
38
+ it 'is expected to update a permission' do
39
+ expect(@instance).to receive(:post).with(
40
+ PERMISSION_UPDATE_PATH, {
41
+ name: 'test',
42
+ newName: 'production',
43
+ description: 'test'
44
+ }
45
+ )
46
+ expect do
47
+ @instance.update_permission(
48
+ name: 'test',
49
+ new_name: 'production',
50
+ description: 'test'
51
+ )
52
+ end.not_to raise_error
53
+ end
54
+ end
55
+
56
+ context '.delete_permission' do
57
+ it 'should respond to .delete_permission' do
58
+ expect(@instance).to respond_to :delete_permission
59
+ end
60
+
61
+ it 'is expected to delete a permission' do
62
+ expect(@instance).to receive(:post).with(
63
+ PERMISSION_DELETE_PATH, { name: 'test' }
64
+ )
65
+ expect do
66
+ @instance.delete_permission('test')
67
+ end.not_to raise_error
68
+ end
69
+ end
70
+
71
+ context '.load_all_permissions' do
72
+ it 'should respond to .load_all_permissions' do
73
+ expect(@instance).to respond_to :load_all_permissions
74
+ end
75
+
76
+ it 'is expected to delete a permission' do
77
+ expect(@instance).to receive(:get).with(PERMISSION_LOAD_ALL_PATH)
78
+ expect { @instance.load_all_permissions }.not_to raise_error
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::Project do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::Project)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.rename_project' do
13
+ it 'should respond to .rename_project' do
14
+ expect(@instance).to respond_to :rename_project
15
+ end
16
+
17
+ it 'is expected to rename the current project' do
18
+ expect(@instance).to receive(:post).with(
19
+ PROJECT_UPDATE_NAME, { name: 'test' }
20
+ )
21
+ expect { @instance.rename_project('test') }.not_to raise_error
22
+ end
23
+ end
24
+
25
+ context '.export_project' do
26
+ it 'should respond to .export_project' do
27
+ expect(@instance).to respond_to :export_project
28
+ end
29
+
30
+ it 'is expected to export the current project' do
31
+ expect(@instance).to receive(:post).with(PROJECT_EXPORT_PATH)
32
+ expect do
33
+ @instance.export_project
34
+ end.not_to raise_error
35
+ end
36
+ end
37
+
38
+ context '.import_project' do
39
+ it 'should respond to .import_project' do
40
+ expect(@instance).to respond_to :import_project
41
+ end
42
+
43
+ it 'is expected to import a project' do
44
+ expect(@instance).to receive(:post).with(
45
+ PROJECT_IMPORT_PATH, { files: 'files' }
46
+ )
47
+ expect do
48
+ @instance.import_project(files: 'files')
49
+ end.not_to raise_error
50
+ end
51
+ end
52
+
53
+ context '.clone_project' do
54
+ it 'should respond to .clone_project' do
55
+ expect(@instance).to respond_to :clone_project
56
+ end
57
+
58
+ it 'is expected to clone the current project' do
59
+ expect(@instance).to receive(:post).with(PROJECT_CLONE, { name: 'test', tag: 'test' })
60
+ expect { @instance.clone_project(name: 'test', tag: 'test') }.not_to raise_error
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::Role do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::Role)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.create_role' do
13
+ it 'should respond to .create_role' do
14
+ expect(@instance).to respond_to :create_role
15
+ end
16
+
17
+ it 'is expected to create a new role' do
18
+ expect(@instance).to receive(:post).with(
19
+ ROLE_CREATE_PATH, {
20
+ name: 'test',
21
+ description: 'test',
22
+ permissionNames: ['test']
23
+ }
24
+ )
25
+ expect do
26
+ @instance.create_role(
27
+ name: 'test',
28
+ description: 'test',
29
+ permission_names: ['test']
30
+ )
31
+ end.not_to raise_error
32
+ end
33
+ end
34
+
35
+ context '.update_role' do
36
+ it 'should respond to .update_role' do
37
+ expect(@instance).to respond_to :update_role
38
+ end
39
+
40
+ it 'is expected to update a role' do
41
+ expect(@instance).to receive(:post).with(
42
+ ROLE_UPDATE_PATH, {
43
+ name: 'test',
44
+ newName: 'production',
45
+ description: 'test',
46
+ permissionNames: ['test']
47
+ }
48
+ )
49
+ expect do
50
+ @instance.update_role(
51
+ name: 'test',
52
+ new_name: 'production',
53
+ description: 'test',
54
+ permission_names: ['test']
55
+ )
56
+ end.not_to raise_error
57
+ end
58
+ end
59
+
60
+ context '.delete_role' do
61
+ it 'should respond to .delete_role' do
62
+ expect(@instance).to respond_to :delete_role
63
+ end
64
+
65
+ it 'is expected to delete a role' do
66
+ expect(@instance).to receive(:post).with(
67
+ ROLE_DELETE_PATH, { name: 'test' }
68
+ )
69
+ expect do
70
+ @instance.delete_role('test')
71
+ end.not_to raise_error
72
+ end
73
+ end
74
+
75
+ context '.load_all_roles' do
76
+ it 'should respond to .load_all_roles' do
77
+ expect(@instance).to respond_to :load_all_roles
78
+ end
79
+
80
+ it 'is expected to delete a role' do
81
+ expect(@instance).to receive(:get).with(ROLE_LOAD_ALL_PATH)
82
+ expect { @instance.load_all_roles }.not_to raise_error
83
+ end
84
+ end
85
+ end