descope 1.0.7 → 1.2.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yaml +51 -12
  3. data/.github/workflows/publish-gem.yaml +6 -33
  4. data/.github/workflows/release-please.yaml +36 -0
  5. data/.gitignore +3 -2
  6. data/.release-please-manifest.json +1 -1
  7. data/.rubocop.yml +1 -1
  8. data/.rubocop_todo.yml +1 -1
  9. data/.ruby-version +1 -1
  10. data/CHANGELOG.md +31 -0
  11. data/Gemfile +7 -6
  12. data/Gemfile.lock +46 -45
  13. data/README.md +244 -1
  14. data/examples/ruby-on-rails-api/descope/package-lock.json +16 -10
  15. data/examples/ruby-on-rails-api/descope/yarn.lock +3 -3
  16. data/lib/descope/api/v1/auth/enchantedlink.rb +76 -9
  17. data/lib/descope/api/v1/management/access_key.rb +8 -7
  18. data/lib/descope/api/v1/management/analytics.rb +62 -0
  19. data/lib/descope/api/v1/management/audit.rb +2 -2
  20. data/lib/descope/api/v1/management/authz.rb +15 -15
  21. data/lib/descope/api/v1/management/common.rb +76 -0
  22. data/lib/descope/api/v1/management/descoper.rb +45 -0
  23. data/lib/descope/api/v1/management/engine.rb +44 -0
  24. data/lib/descope/api/v1/management/fga.rb +64 -0
  25. data/lib/descope/api/v1/management/flow.rb +5 -5
  26. data/lib/descope/api/v1/management/group.rb +42 -0
  27. data/lib/descope/api/v1/management/jwt_template.rb +49 -0
  28. data/lib/descope/api/v1/management/lists.rb +96 -0
  29. data/lib/descope/api/v1/management/management_key.rb +54 -0
  30. data/lib/descope/api/v1/management/outbound_app.rb +112 -0
  31. data/lib/descope/api/v1/management/password.rb +2 -2
  32. data/lib/descope/api/v1/management/permission.rb +4 -4
  33. data/lib/descope/api/v1/management/project.rb +5 -5
  34. data/lib/descope/api/v1/management/role.rb +5 -5
  35. data/lib/descope/api/v1/management/scim.rb +14 -14
  36. data/lib/descope/api/v1/management/scope_claim_mapping.rb +34 -0
  37. data/lib/descope/api/v1/management/sso_application.rb +7 -7
  38. data/lib/descope/api/v1/management/sso_settings.rb +5 -5
  39. data/lib/descope/api/v1/management/tenant.rb +8 -6
  40. data/lib/descope/api/v1/management/third_party_application.rb +190 -0
  41. data/lib/descope/api/v1/management/user.rb +36 -36
  42. data/lib/descope/api/v1/management.rb +22 -0
  43. data/lib/descope/http_client.rb +30 -0
  44. data/lib/descope/mixins/common.rb +1 -0
  45. data/lib/descope/mixins/http.rb +25 -18
  46. data/lib/descope/mixins/initializer.rb +23 -11
  47. data/lib/descope/mixins/requests.rb +24 -0
  48. data/lib/descope/mixins.rb +2 -1
  49. data/lib/descope/version.rb +1 -1
  50. data/spec/integration/lib.descope/api/v1/auth/enchantedlink_spec.rb +19 -21
  51. data/spec/integration/lib.descope/api/v1/auth/magiclink_spec.rb +5 -1
  52. data/spec/integration/lib.descope/api/v1/auth/otp_spec.rb +5 -1
  53. data/spec/integration/lib.descope/api/v1/auth/session_spec.rb +24 -5
  54. data/spec/integration/lib.descope/api/v1/auth/totp_spec.rb +5 -1
  55. data/spec/integration/lib.descope/api/v1/management/access_key_spec.rb +10 -2
  56. data/spec/integration/lib.descope/api/v1/management/authz_spec.rb +26 -5
  57. data/spec/integration/lib.descope/api/v1/management/permissions_spec.rb +20 -2
  58. data/spec/integration/lib.descope/api/v1/management/project_spec.rb +16 -2
  59. data/spec/integration/lib.descope/api/v1/management/roles_spec.rb +114 -36
  60. data/spec/integration/lib.descope/api/v1/management/user_spec.rb +21 -4
  61. data/spec/lib.descope/api/v1/auth/enchantedlink_spec.rb +163 -1
  62. data/spec/lib.descope/api/v1/management/access_key_spec.rb +7 -7
  63. data/spec/lib.descope/api/v1/management/analytics_spec.rb +82 -0
  64. data/spec/lib.descope/api/v1/management/audit_spec.rb +2 -2
  65. data/spec/lib.descope/api/v1/management/authz_spec.rb +16 -16
  66. data/spec/lib.descope/api/v1/management/descoper_spec.rb +101 -0
  67. data/spec/lib.descope/api/v1/management/engine_spec.rb +115 -0
  68. data/spec/lib.descope/api/v1/management/fga_spec.rb +169 -0
  69. data/spec/lib.descope/api/v1/management/flow_spec.rb +5 -5
  70. data/spec/lib.descope/api/v1/management/group_spec.rb +72 -0
  71. data/spec/lib.descope/api/v1/management/jwt_template_spec.rb +103 -0
  72. data/spec/lib.descope/api/v1/management/lists_spec.rb +285 -0
  73. data/spec/lib.descope/api/v1/management/management_key_spec.rb +109 -0
  74. data/spec/lib.descope/api/v1/management/outbound_app_spec.rb +236 -0
  75. data/spec/lib.descope/api/v1/management/password_spec.rb +2 -2
  76. data/spec/lib.descope/api/v1/management/permission_spec.rb +4 -4
  77. data/spec/lib.descope/api/v1/management/project_spec.rb +4 -4
  78. data/spec/lib.descope/api/v1/management/role_spec.rb +5 -5
  79. data/spec/lib.descope/api/v1/management/scim_spec.rb +14 -14
  80. data/spec/lib.descope/api/v1/management/scope_claim_mapping_spec.rb +59 -0
  81. data/spec/lib.descope/api/v1/management/sso_application_spec.rb +6 -6
  82. data/spec/lib.descope/api/v1/management/sso_settings_spec.rb +5 -5
  83. data/spec/lib.descope/api/v1/management/tenant_spec.rb +6 -6
  84. data/spec/lib.descope/api/v1/management/third_party_application_spec.rb +171 -0
  85. data/spec/lib.descope/api/v1/management/user_spec.rb +36 -36
  86. data/spec/lib.descope/auth_management_key_spec.rb +151 -0
  87. data/spec/lib.descope/mixins/http_spec.rb +17 -6
  88. data/spec/support/client_config.rb +1 -0
  89. data/spec/support/dummy_class.rb +12 -9
  90. data/spec/support/utils.rb +15 -0
  91. metadata +29 -3
@@ -15,7 +15,7 @@ describe Descope::Api::V1::Management::Project do
15
15
  end
16
16
 
17
17
  it 'is expected to rename the current project' do
18
- expect(@instance).to receive(:post).with(
18
+ expect(@instance).to receive(:mgmt_post).with(
19
19
  PROJECT_UPDATE_NAME, { name: 'test' }
20
20
  )
21
21
  expect { @instance.rename_project('test') }.not_to raise_error
@@ -28,7 +28,7 @@ describe Descope::Api::V1::Management::Project do
28
28
  end
29
29
 
30
30
  it 'is expected to export the current project' do
31
- expect(@instance).to receive(:post).with(PROJECT_EXPORT_PATH)
31
+ expect(@instance).to receive(:mgmt_post).with(PROJECT_EXPORT_PATH)
32
32
  expect do
33
33
  @instance.export_project
34
34
  end.not_to raise_error
@@ -41,7 +41,7 @@ describe Descope::Api::V1::Management::Project do
41
41
  end
42
42
 
43
43
  it 'is expected to import a project' do
44
- expect(@instance).to receive(:post).with(
44
+ expect(@instance).to receive(:mgmt_post).with(
45
45
  PROJECT_IMPORT_PATH, { files: 'files' }
46
46
  )
47
47
  expect do
@@ -56,7 +56,7 @@ describe Descope::Api::V1::Management::Project do
56
56
  end
57
57
 
58
58
  it 'is expected to clone the current project' do
59
- expect(@instance).to receive(:post).with(PROJECT_CLONE, { name: 'test', tag: 'test' })
59
+ expect(@instance).to receive(:mgmt_post).with(PROJECT_CLONE, { name: 'test', tag: 'test' })
60
60
  expect { @instance.clone_project(name: 'test', tag: 'test') }.not_to raise_error
61
61
  end
62
62
  end
@@ -15,7 +15,7 @@ describe Descope::Api::V1::Management::Role do
15
15
  end
16
16
 
17
17
  it 'is expected to create a new role' do
18
- expect(@instance).to receive(:post).with(
18
+ expect(@instance).to receive(:mgmt_post).with(
19
19
  ROLE_CREATE_PATH, {
20
20
  name: 'test',
21
21
  description: 'test',
@@ -40,7 +40,7 @@ describe Descope::Api::V1::Management::Role do
40
40
  end
41
41
 
42
42
  it 'is expected to update a role' do
43
- expect(@instance).to receive(:post).with(
43
+ expect(@instance).to receive(:mgmt_post).with(
44
44
  ROLE_UPDATE_PATH, {
45
45
  name: 'test',
46
46
  newName: 'production',
@@ -67,7 +67,7 @@ describe Descope::Api::V1::Management::Role do
67
67
  end
68
68
 
69
69
  it 'is expected to delete a role' do
70
- expect(@instance).to receive(:post).with(
70
+ expect(@instance).to receive(:mgmt_post).with(
71
71
  ROLE_DELETE_PATH, { name: 'test', tenantId: 'test' }
72
72
  )
73
73
  expect do
@@ -82,7 +82,7 @@ describe Descope::Api::V1::Management::Role do
82
82
  end
83
83
 
84
84
  it 'is expected to delete a role' do
85
- expect(@instance).to receive(:get).with(ROLE_LOAD_ALL_PATH)
85
+ expect(@instance).to receive(:mgmt_get).with(ROLE_LOAD_ALL_PATH)
86
86
  expect { @instance.load_all_roles }.not_to raise_error
87
87
  end
88
88
  end
@@ -93,7 +93,7 @@ describe Descope::Api::V1::Management::Role do
93
93
  end
94
94
 
95
95
  it 'is expected to search roles' do
96
- expect(@instance).to receive(:post).with(
96
+ expect(@instance).to receive(:mgmt_post).with(
97
97
  ROLE_SEARCH_PATH, {
98
98
  roleNames: %w[tester test2],
99
99
  tenantIds: %w[t1 t2],
@@ -24,7 +24,7 @@ describe Descope::Api::V1::Management::SCIM do
24
24
  start_index,
25
25
  count,
26
26
  excluded_attributes)
27
- expect(@instance).to receive(:get).with(url)
27
+ expect(@instance).to receive(:mgmt_get).with(url)
28
28
  expect do
29
29
  @instance.scim_search_groups(filter:, start_index:, count:, excluded_attributes:)
30
30
  end.not_to raise_error
@@ -48,7 +48,7 @@ describe Descope::Api::V1::Management::SCIM do
48
48
  members,
49
49
  external_id,
50
50
  excluded_attributes)
51
- expect(@instance).to receive(:post).with(Descope::Api::V1::Management::Common::SCIM_GROUPS_PATH, body)
51
+ expect(@instance).to receive(:mgmt_post).with(Descope::Api::V1::Management::Common::SCIM_GROUPS_PATH, body)
52
52
  expect do
53
53
  @instance.scim_create_group(group_id:,
54
54
  display_name:,
@@ -73,7 +73,7 @@ describe Descope::Api::V1::Management::SCIM do
73
73
  :compose_scim_create_group_url,
74
74
  group_id, display_name, external_id, excluded_attributes
75
75
  )
76
- expect(@instance).to receive(:get).with(url)
76
+ expect(@instance).to receive(:mgmt_get).with(url)
77
77
  expect do
78
78
  @instance.scim_load_group(group_id:, display_name:, external_id:, excluded_attributes:)
79
79
  end.not_to raise_error
@@ -96,7 +96,7 @@ describe Descope::Api::V1::Management::SCIM do
96
96
  group_id, display_name, members, external_id, excluded_attributes
97
97
  )
98
98
  url = "#{SCIM_GROUPS_PATH}/#{group_id}"
99
- expect(@instance).to receive(:patch).with(url, body)
99
+ expect(@instance).to receive(:mgmt_patch).with(url, body)
100
100
  expect do
101
101
  @instance.scim_update_group(group_id:, display_name:, members:, external_id:, excluded_attributes:)
102
102
  end.not_to raise_error
@@ -111,7 +111,7 @@ describe Descope::Api::V1::Management::SCIM do
111
111
  it 'is expected to delete scim group' do
112
112
  group_id = 'G123'
113
113
  url = "#{SCIM_GROUPS_PATH}/#{group_id}"
114
- expect(@instance).to receive(:delete).with(url)
114
+ expect(@instance).to receive(:mgmt_delete).with(url)
115
115
  expect { @instance.scim_delete_group(group_id) }.not_to raise_error
116
116
  end
117
117
  end
@@ -142,7 +142,7 @@ describe Descope::Api::V1::Management::SCIM do
142
142
 
143
143
  url = @instance.send(:compose_scim_patch_group_url, group_id, user_id, operations)
144
144
 
145
- expect(@instance).to receive(:patch).with(url)
145
+ expect(@instance).to receive(:mgmt_patch).with(url)
146
146
  expect do
147
147
  @instance.scim_patch_group(group_id:, user_id:, operations:)
148
148
  end.not_to raise_error
@@ -156,7 +156,7 @@ describe Descope::Api::V1::Management::SCIM do
156
156
 
157
157
  it 'is expected to load scim resource types' do
158
158
  url = "#{SCIM_RESOURCE_TYPES_PATH}"
159
- expect(@instance).to receive(:get).with(url)
159
+ expect(@instance).to receive(:mgmt_get).with(url)
160
160
  expect { @instance.scim_load_resource_types }.not_to raise_error
161
161
  end
162
162
  end
@@ -168,7 +168,7 @@ describe Descope::Api::V1::Management::SCIM do
168
168
 
169
169
  it 'is expected to load scim service provider config' do
170
170
  url = "#{SCIM_SERVICE_PROVIDER_CONFIG_PATH}"
171
- expect(@instance).to receive(:get).with(url)
171
+ expect(@instance).to receive(:mgmt_get).with(url)
172
172
  expect { @instance.scim_load_service_provider_config }.not_to raise_error
173
173
  end
174
174
  end
@@ -186,7 +186,7 @@ describe Descope::Api::V1::Management::SCIM do
186
186
  filter,
187
187
  start_index,
188
188
  count)
189
- expect(@instance).to receive(:get).with(url)
189
+ expect(@instance).to receive(:mgmt_get).with(url)
190
190
  expect do
191
191
  @instance.scim_search_users(filter:, start_index:, count:)
192
192
  end.not_to raise_error
@@ -219,7 +219,7 @@ describe Descope::Api::V1::Management::SCIM do
219
219
  active,
220
220
  name,
221
221
  user_name)
222
- expect(@instance).to receive(:post).with(SCIM_USERS_PATH, body)
222
+ expect(@instance).to receive(:mgmt_post).with(SCIM_USERS_PATH, body)
223
223
  expect do
224
224
  @instance.scim_create_user(
225
225
  user_id:,
@@ -242,7 +242,7 @@ describe Descope::Api::V1::Management::SCIM do
242
242
  it 'is expected to load scim user' do
243
243
  user_id = 'U123'
244
244
  url = "#{SCIM_USERS_PATH}/#{user_id}"
245
- expect(@instance).to receive(:get).with(url)
245
+ expect(@instance).to receive(:mgmt_get).with(url)
246
246
  expect do
247
247
  @instance.scim_load_user(user_id)
248
248
  end.not_to raise_error
@@ -257,7 +257,7 @@ describe Descope::Api::V1::Management::SCIM do
257
257
  it 'is expected to load scim user' do
258
258
  user_id = 'U123'
259
259
  url = "#{SCIM_USERS_PATH}/#{user_id}"
260
- expect(@instance).to receive(:patch).with(url)
260
+ expect(@instance).to receive(:mgmt_patch).with(url)
261
261
  expect do
262
262
  @instance.scim_update_user(user_id)
263
263
  end.not_to raise_error
@@ -272,7 +272,7 @@ describe Descope::Api::V1::Management::SCIM do
272
272
  it 'is expected to delete scim user' do
273
273
  user_id = 'U123'
274
274
  url = "#{SCIM_USERS_PATH}/#{user_id}"
275
- expect(@instance).to receive(:delete).with(url)
275
+ expect(@instance).to receive(:mgmt_delete).with(url)
276
276
  expect { @instance.scim_delete_user(user_id) }.not_to raise_error
277
277
  end
278
278
  end
@@ -303,7 +303,7 @@ describe Descope::Api::V1::Management::SCIM do
303
303
 
304
304
  body = @instance.send(:compose_scim_patch_user_body, user_id, group_id, operations)
305
305
 
306
- expect(@instance).to receive(:patch).with(SCIM_USERS_PATH, body)
306
+ expect(@instance).to receive(:mgmt_patch).with(SCIM_USERS_PATH, body)
307
307
  expect do
308
308
  @instance.scim_patch_user(user_id:, group_id:, operations:)
309
309
  end.not_to raise_error
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::ScopeClaimMapping do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::ScopeClaimMapping)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.get_scope_claim_mapping' do
13
+ it 'should respond to .get_scope_claim_mapping' do
14
+ expect(@instance).to respond_to :get_scope_claim_mapping
15
+ end
16
+
17
+ it 'is expected to get the project-wide OIDC scope-to-claim mappings' do
18
+ expect(@instance).to receive(:mgmt_post).with(SCOPE_CLAIM_MAPPING_GET_PATH)
19
+ expect do
20
+ @instance.get_scope_claim_mapping
21
+ end.not_to raise_error
22
+ end
23
+ end
24
+
25
+ context '.set_scope_claim_mapping' do
26
+ it 'should respond to .set_scope_claim_mapping' do
27
+ expect(@instance).to respond_to :set_scope_claim_mapping
28
+ end
29
+
30
+ it 'is expected to set the project-wide OIDC scope-to-claim mappings' do
31
+ mappings = [
32
+ {
33
+ scope: 'name-of-scope',
34
+ claims: %w[claim1 claim2]
35
+ }
36
+ ]
37
+ expect(@instance).to receive(:mgmt_post).with(
38
+ SCOPE_CLAIM_MAPPING_SET_PATH,
39
+ { mappings: mappings }
40
+ )
41
+ expect do
42
+ @instance.set_scope_claim_mapping(mappings: mappings)
43
+ end.not_to raise_error
44
+ end
45
+ end
46
+
47
+ context '.delete_scope_claim_mapping' do
48
+ it 'should respond to .delete_scope_claim_mapping' do
49
+ expect(@instance).to respond_to :delete_scope_claim_mapping
50
+ end
51
+
52
+ it 'is expected to delete the project-wide OIDC scope-to-claim mappings' do
53
+ expect(@instance).to receive(:mgmt_post).with(SCOPE_CLAIM_MAPPING_DELETE_PATH)
54
+ expect do
55
+ @instance.delete_scope_claim_mapping
56
+ end.not_to raise_error
57
+ end
58
+ end
59
+ end
@@ -15,7 +15,7 @@ describe Descope::Api::V1::Management::SSOApplication do
15
15
  end
16
16
 
17
17
  it 'is expected to create SAML application' do
18
- expect(@instance).to receive(:post).with(
18
+ expect(@instance).to receive(:mgmt_post).with(
19
19
  SSO_APPLICATION_OIDC_CREATE_PATH, {
20
20
  id: 'tenant1',
21
21
  name: 'test',
@@ -44,7 +44,7 @@ describe Descope::Api::V1::Management::SSOApplication do
44
44
  end
45
45
 
46
46
  it 'is expected to create SAML application' do
47
- expect(@instance).to receive(:post).with(
47
+ expect(@instance).to receive(:mgmt_post).with(
48
48
  SSO_APPLICATION_SAML_CREATE_PATH, {
49
49
  name: 'test',
50
50
  description: 'awesome tenant',
@@ -172,7 +172,7 @@ describe Descope::Api::V1::Management::SSOApplication do
172
172
  end
173
173
 
174
174
  it 'is expected to update sso oidc application' do
175
- expect(@instance).to receive(:post).with(
175
+ expect(@instance).to receive(:mgmt_post).with(
176
176
  SSO_APPLICATION_OIDC_UPDATE_PATH, {
177
177
  id: 'tenant1',
178
178
  name: 'test',
@@ -195,21 +195,21 @@ describe Descope::Api::V1::Management::SSOApplication do
195
195
  end
196
196
 
197
197
  it 'is expected to delete sso app' do
198
- expect(@instance).to receive(:delete).with(
198
+ expect(@instance).to receive(:mgmt_delete).with(
199
199
  SSO_APPLICATION_DELETE_PATH, { id: 'tenant1' }
200
200
  )
201
201
  expect { @instance.delete_sso_app('tenant1') }.not_to raise_error
202
202
  end
203
203
 
204
204
  it 'is expected to load sso app' do
205
- expect(@instance).to receive(:get).with(
205
+ expect(@instance).to receive(:mgmt_get).with(
206
206
  SSO_APPLICATION_LOAD_PATH, { id: 'tenant1' }
207
207
  )
208
208
  expect { @instance.load_sso_app('tenant1') }.not_to raise_error
209
209
  end
210
210
 
211
211
  it 'is expected to load all sso apps' do
212
- expect(@instance).to receive(:get).with(
212
+ expect(@instance).to receive(:mgmt_get).with(
213
213
  SSO_APPLICATION_LOAD_ALL_PATH, {}
214
214
  )
215
215
  expect { @instance.load_all_sso_apps }.not_to raise_error
@@ -15,7 +15,7 @@ describe Descope::Api::V1::Management::SSOSettings do
15
15
  end
16
16
 
17
17
  it 'is expected to get SSO settings' do
18
- expect(@instance).to receive(:get).with(
18
+ expect(@instance).to receive(:mgmt_get).with(
19
19
  SSO_SETTINGS_PATH, { tenantId: '123' }
20
20
  )
21
21
  expect { @instance.get_sso_settings('123') }.not_to raise_error
@@ -28,7 +28,7 @@ describe Descope::Api::V1::Management::SSOSettings do
28
28
  end
29
29
 
30
30
  it 'is expected to delete SSO settings' do
31
- expect(@instance).to receive(:delete).with(
31
+ expect(@instance).to receive(:mgmt_delete).with(
32
32
  SSO_SETTINGS_PATH, { tenantId: '123' }
33
33
  )
34
34
  expect { @instance.delete_sso_settings('123') }.not_to raise_error
@@ -40,7 +40,7 @@ describe Descope::Api::V1::Management::SSOSettings do
40
40
  end
41
41
 
42
42
  it 'is expected to configure SSO settings' do
43
- expect(@instance).to receive(:post).with(
43
+ expect(@instance).to receive(:mgmt_post).with(
44
44
  SSO_OIDC_PATH, {
45
45
  tenantId: '123',
46
46
  settings: {
@@ -86,7 +86,7 @@ describe Descope::Api::V1::Management::SSOSettings do
86
86
  end
87
87
 
88
88
  it 'is expected to configure SSO settings' do
89
- expect(@instance).to receive(:post).with(
89
+ expect(@instance).to receive(:mgmt_post).with(
90
90
  SSO_SETTINGS_PATH, {
91
91
  tenantId: '123',
92
92
  settings: {
@@ -131,7 +131,7 @@ describe Descope::Api::V1::Management::SSOSettings do
131
131
  end
132
132
 
133
133
  it 'is expected to configure SAML metadata' do
134
- expect(@instance).to receive(:post).with(
134
+ expect(@instance).to receive(:mgmt_post).with(
135
135
  SSO_METADATA_PATH, {
136
136
  tenantId: '123',
137
137
  settings: {
@@ -15,7 +15,7 @@ describe Descope::Api::V1::Management::Tenant do
15
15
  end
16
16
 
17
17
  it 'is expected to create a new tenant' do
18
- expect(@instance).to receive(:post).with(
18
+ expect(@instance).to receive(:mgmt_post).with(
19
19
  TENANT_CREATE_PATH, {
20
20
  name: 'test',
21
21
  id: 'test',
@@ -46,7 +46,7 @@ describe Descope::Api::V1::Management::Tenant do
46
46
  end
47
47
 
48
48
  it 'is expected to update a tenant' do
49
- expect(@instance).to receive(:post).with(
49
+ expect(@instance).to receive(:mgmt_post).with(
50
50
  TENANT_UPDATE_PATH, {
51
51
  name: 'test',
52
52
  id: 'test',
@@ -77,7 +77,7 @@ describe Descope::Api::V1::Management::Tenant do
77
77
  end
78
78
 
79
79
  it 'is expected to delete a tenant' do
80
- expect(@instance).to receive(:post).with(
80
+ expect(@instance).to receive(:mgmt_post).with(
81
81
  TENANT_DELETE_PATH, { id: 'test' }
82
82
  )
83
83
  expect { @instance.delete_tenant('test') }.not_to raise_error
@@ -90,7 +90,7 @@ describe Descope::Api::V1::Management::Tenant do
90
90
  end
91
91
 
92
92
  it 'is expected to load a tenant' do
93
- expect(@instance).to receive(:get).with(
93
+ expect(@instance).to receive(:mgmt_get).with(
94
94
  TENANT_LOAD_PATH, { id: 'test' }
95
95
  )
96
96
  expect { @instance.load_tenant('test') }.not_to raise_error
@@ -103,7 +103,7 @@ describe Descope::Api::V1::Management::Tenant do
103
103
  end
104
104
 
105
105
  it 'is expected to load all tenants' do
106
- expect(@instance).to receive(:get).with(TENANT_LOAD_ALL_PATH)
106
+ expect(@instance).to receive(:mgmt_get).with(TENANT_LOAD_ALL_PATH)
107
107
  expect { @instance.load_all_tenants }.not_to raise_error
108
108
  end
109
109
  end
@@ -114,7 +114,7 @@ describe Descope::Api::V1::Management::Tenant do
114
114
  end
115
115
 
116
116
  it 'is expected to search all tenants' do
117
- expect(@instance).to receive(:post).with(
117
+ expect(@instance).to receive(:mgmt_post).with(
118
118
  TENANT_SEARCH_ALL_PATH, {
119
119
  ids: %w[test1 test2],
120
120
  names: %w[test1 test2],
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::ThirdPartyApplication do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::ThirdPartyApplication)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context('.create_application') do
13
+ it 'should respond to .create_application' do
14
+ expect(@instance).to respond_to :create_application
15
+ end
16
+
17
+ it 'is expected to create a third party application' do
18
+ expect(@instance).to receive(:mgmt_post).with(
19
+ THIRD_PARTY_APP_CREATE_PATH, {
20
+ id: 'app1',
21
+ name: 'test',
22
+ description: 'awesome app',
23
+ logo: 'https://logo.com',
24
+ loginPageUrl: 'https://dummy.com/login',
25
+ approvedCallbackUrls: ['https://dummy.com/callback'],
26
+ permissionsScopes: [{ name: 'read' }],
27
+ attributesScopes: [{ name: 'email' }],
28
+ jwtBearerSettings: [{ tenantId: 'tenant1' }],
29
+ customAttributes: { key: 'value' },
30
+ forcePkce: true,
31
+ defaultAudience: 'aud1'
32
+ }
33
+ )
34
+ expect do
35
+ @instance.create_application(
36
+ id: 'app1',
37
+ name: 'test',
38
+ description: 'awesome app',
39
+ logo: 'https://logo.com',
40
+ login_page_url: 'https://dummy.com/login',
41
+ approved_callback_urls: ['https://dummy.com/callback'],
42
+ permissions_scopes: [{ name: 'read' }],
43
+ attributes_scopes: [{ name: 'email' }],
44
+ jwt_bearer_settings: [{ tenantId: 'tenant1' }],
45
+ custom_attributes: { key: 'value' },
46
+ force_pkce: true,
47
+ default_audience: 'aud1'
48
+ )
49
+ end.not_to raise_error
50
+ end
51
+ end
52
+
53
+ context('.update_application') do
54
+ it 'should respond to .update_application' do
55
+ expect(@instance).to respond_to :update_application
56
+ end
57
+
58
+ it 'is expected to update a third party application' do
59
+ expect(@instance).to receive(:mgmt_post).with(
60
+ THIRD_PARTY_APP_UPDATE_PATH, {
61
+ id: 'app1',
62
+ name: 'test',
63
+ description: 'awesome app',
64
+ logo: 'https://logo.com',
65
+ loginPageUrl: 'https://dummy.com/login'
66
+ }
67
+ )
68
+ expect do
69
+ @instance.update_application(
70
+ id: 'app1',
71
+ name: 'test',
72
+ description: 'awesome app',
73
+ logo: 'https://logo.com',
74
+ login_page_url: 'https://dummy.com/login'
75
+ )
76
+ end.not_to raise_error
77
+ end
78
+ end
79
+
80
+ context('.patch_application') do
81
+ it 'should respond to .patch_application' do
82
+ expect(@instance).to respond_to :patch_application
83
+ end
84
+
85
+ it 'is expected to patch a third party application' do
86
+ expect(@instance).to receive(:mgmt_post).with(
87
+ THIRD_PARTY_APP_PATCH_PATH, {
88
+ id: 'app1',
89
+ name: 'test'
90
+ }
91
+ )
92
+ expect do
93
+ @instance.patch_application(
94
+ id: 'app1',
95
+ name: 'test'
96
+ )
97
+ end.not_to raise_error
98
+ end
99
+ end
100
+
101
+ it 'is expected to delete a third party application' do
102
+ expect(@instance).to receive(:mgmt_post).with(
103
+ THIRD_PARTY_APP_DELETE_PATH, { id: 'app1' }
104
+ )
105
+ expect { @instance.delete_application('app1') }.not_to raise_error
106
+ end
107
+
108
+ it 'is expected to load a third party application' do
109
+ expect(@instance).to receive(:mgmt_get).with(
110
+ THIRD_PARTY_APP_LOAD_PATH, { id: 'app1' }
111
+ )
112
+ expect { @instance.load_application('app1') }.not_to raise_error
113
+ end
114
+
115
+ it 'is expected to load all third party applications' do
116
+ expect(@instance).to receive(:mgmt_get).with(
117
+ THIRD_PARTY_APP_LOAD_ALL_PATH, {}
118
+ )
119
+ expect { @instance.load_all_applications }.not_to raise_error
120
+ end
121
+
122
+ it 'is expected to get a third party application secret' do
123
+ expect(@instance).to receive(:mgmt_get).with(
124
+ THIRD_PARTY_APP_SECRET_PATH, { id: 'app1' }
125
+ )
126
+ expect { @instance.get_application_secret('app1') }.not_to raise_error
127
+ end
128
+
129
+ it 'is expected to rotate a third party application secret' do
130
+ expect(@instance).to receive(:mgmt_post).with(
131
+ THIRD_PARTY_APP_ROTATE_PATH, { id: 'app1' }
132
+ )
133
+ expect { @instance.rotate_application_secret('app1') }.not_to raise_error
134
+ end
135
+
136
+ it 'is expected to delete consents' do
137
+ expect(@instance).to receive(:mgmt_post).with(
138
+ THIRD_PARTY_APP_DELETE_CONSENTS_PATH, {
139
+ consentIds: %w[consent1 consent2],
140
+ appId: 'app1',
141
+ userIds: %w[user1 user2],
142
+ tenantId: 'tenant1'
143
+ }
144
+ )
145
+ expect do
146
+ @instance.delete_consents(
147
+ app_id: 'app1',
148
+ consent_ids: %w[consent1 consent2],
149
+ user_ids: %w[user1 user2],
150
+ tenant_id: 'tenant1'
151
+ )
152
+ end.not_to raise_error
153
+ end
154
+
155
+ it 'is expected to delete tenant consents' do
156
+ expect(@instance).to receive(:mgmt_post).with(
157
+ THIRD_PARTY_APP_DELETE_TENANT_CONSENTS_PATH, {
158
+ consentIds: %w[consent1 consent2],
159
+ appId: 'app1',
160
+ tenantId: 'tenant1'
161
+ }
162
+ )
163
+ expect do
164
+ @instance.delete_tenant_consents(
165
+ app_id: 'app1',
166
+ consent_ids: %w[consent1 consent2],
167
+ tenant_id: 'tenant1'
168
+ )
169
+ end.not_to raise_error
170
+ end
171
+ end