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
@@ -102,7 +102,17 @@ describe Descope::Api::V1::Management::User do
102
102
  created_user = @client.create_user(**user)['user']
103
103
  loaded_user = @client.load_user(created_user['loginIds'][0])['user']
104
104
  expect(loaded_user['loginIds']).to eq(created_user['loginIds'])
105
- sleep 10
105
+
106
+ # Wait for user to be fully propagated before deletion
107
+ SpecUtils.wait_for_condition(max_wait: 15, interval: 2, description: 'user to be ready for deletion') do
108
+ begin
109
+ @client.load_user(created_user['loginIds'][0])
110
+ true
111
+ rescue StandardError => e
112
+ @client.logger.info("Waiting for user propagation: #{e.message}")
113
+ false
114
+ end
115
+ end
106
116
 
107
117
  @client.delete_user(created_user['loginIds'][0])
108
118
  begin
@@ -115,8 +125,10 @@ describe Descope::Api::V1::Management::User do
115
125
  it 'should search all users' do
116
126
  users = FactoryBot.build_list(:user, 5)
117
127
  @client.create_batch_users(users)
128
+ # Wait for batch creation to propagate
129
+ sleep 1.0
118
130
  all_users = @client.search_all_users
119
- sdk_users = all_users['users'].select { |user| user['middleName'] == "#{SpecUtils.build_prefix}Ruby-SDK-User" }
131
+ sdk_users = all_users['users'].select { |user| user['middleName']&.include?('Ruby-SDK-User') }
120
132
  expect(sdk_users.length).to be >= 5
121
133
  end
122
134
 
@@ -128,7 +140,12 @@ describe Descope::Api::V1::Management::User do
128
140
  all_roles['roles'].each do |role|
129
141
  @client.delete_role(name: role['name']) if role['name'] == role_name
130
142
  end
131
- sleep 5
143
+
144
+ # Wait for role deletion to propagate
145
+ SpecUtils.wait_for_condition(max_wait: 10, interval: 1, description: 'role deletion to propagate') do
146
+ all_roles = @client.load_all_roles
147
+ all_roles['roles'].none? { |role| role['name'] == role_name }
148
+ end
132
149
 
133
150
  user_args = build(:user)
134
151
  test_user = @client.create_test_user(**user_args)['user']
@@ -225,7 +242,7 @@ describe Descope::Api::V1::Management::User do
225
242
  begin
226
243
  @client.expire_password(user['loginIds'][0])
227
244
  @client.password_sign_in(login_id: user['loginIds'][0], password:)
228
- rescue Descope::ServerError => e
245
+ rescue Descope::Unauthorized => e
229
246
  expect(e.message).to match(/"errorCode":"E062909"/)
230
247
  end
231
248
  end
@@ -30,7 +30,7 @@ describe Descope::Api::V1::EnchantedLink do
30
30
  expect(@instance).to receive(:post).with(
31
31
  enchanted_link_compose_signin_url,
32
32
  request_params,
33
- nil,
33
+ {},
34
34
  'refresh_token'
35
35
  )
36
36
 
@@ -60,6 +60,48 @@ describe Descope::Api::V1::EnchantedLink do
60
60
  @instance.send(:validate_refresh_token_provided, { mfa: true, stepup: true }, '')
61
61
  end.to raise_error(Descope::AuthException, 'Missing refresh token for stepup/mfa')
62
62
  end
63
+
64
+ it 'is expected to respond to sign in with phone' do
65
+ expect(@instance).to respond_to(:enchanted_link_sign_in_with_phone)
66
+ end
67
+
68
+ it 'is expected to sign in with enchanted link via sms' do
69
+ request_params = {
70
+ loginId: '+1234567890',
71
+ redirectUrl: 'https://some-uri/sms',
72
+ loginOptions: {
73
+ stepup: false,
74
+ customClaims: { 'abc': '123' },
75
+ mfa: false,
76
+ ssoAppId: 'sso-id'
77
+ },
78
+ providerId: 'provider-id',
79
+ templateId: 'template-id'
80
+ }
81
+
82
+ expect(@instance).to receive(:post).with(
83
+ '/v1/auth/enchantedlink/signin/sms',
84
+ request_params,
85
+ {},
86
+ 'refresh_token'
87
+ ).and_return({ 'linkId' => '1', 'pendingRef' => 'ref', 'maskedPhone' => '+1******890' })
88
+
89
+ res = @instance.enchanted_link_sign_in_with_phone(
90
+ login_id: '+1234567890',
91
+ uri: 'https://some-uri/sms',
92
+ login_options: {
93
+ stepup: false,
94
+ custom_claims: { 'abc': '123' },
95
+ mfa: false,
96
+ sso_app_id: 'sso-id'
97
+ },
98
+ provider_id: 'provider-id',
99
+ template_id: 'template-id',
100
+ refresh_token: 'refresh_token'
101
+ )
102
+
103
+ expect(res['maskedPhone']).to eq('+1******890')
104
+ end
63
105
  end
64
106
 
65
107
  context '.sign_up' do
@@ -88,6 +130,36 @@ describe Descope::Api::V1::EnchantedLink do
88
130
  )
89
131
  end.not_to raise_error
90
132
  end
133
+
134
+ it 'is expected to respond to sign up with phone' do
135
+ expect(@instance).to respond_to(:enchanted_link_sign_up_with_phone)
136
+ end
137
+
138
+ it 'is expected to sign up with enchanted link via sms' do
139
+ request_params = {
140
+ loginId: '+1234567890',
141
+ redirectUrl: 'https://some-uri/sms',
142
+ user: { loginId: 'user1', phone: '+1234567890' },
143
+ phone: '+1234567890',
144
+ providerId: 'provider-id',
145
+ templateId: 'template-id'
146
+ }
147
+
148
+ expect(@instance).to receive(:post).with(
149
+ '/v1/auth/enchantedlink/signup/sms',
150
+ request_params
151
+ ).and_return({ 'linkId' => '1', 'pendingRef' => 'ref', 'maskedPhone' => '+1******890' })
152
+
153
+ res = @instance.enchanted_link_sign_up_with_phone(
154
+ login_id: '+1234567890',
155
+ uri: 'https://some-uri/sms',
156
+ user: { login_id: 'user1', phone: '+1234567890' },
157
+ provider_id: 'provider-id',
158
+ template_id: 'template-id'
159
+ )
160
+
161
+ expect(res['maskedPhone']).to eq('+1******890')
162
+ end
91
163
  end
92
164
 
93
165
  context '.sign_up_or_in' do
@@ -125,6 +197,96 @@ describe Descope::Api::V1::EnchantedLink do
125
197
  )
126
198
  end.not_to raise_error
127
199
  end
200
+
201
+ it 'is expected to respond to sign up or in with phone' do
202
+ expect(@instance).to respond_to(:enchanted_link_sign_up_or_in_with_phone)
203
+ end
204
+
205
+ it 'is expected to sign up or in with enchanted link via sms' do
206
+ request_params = {
207
+ loginId: '+1234567890',
208
+ redirectUrl: 'https://some-uri/sms',
209
+ loginOptions: {
210
+ stepup: false,
211
+ customClaims: { 'abc': '123' },
212
+ mfa: false,
213
+ ssoAppId: 'sso-id'
214
+ },
215
+ providerId: 'provider-id',
216
+ templateId: 'template-id'
217
+ }
218
+
219
+ expect(@instance).to receive(:post).with(
220
+ '/v1/auth/enchantedlink/signup-in/sms',
221
+ request_params
222
+ ).and_return({ 'linkId' => '1', 'pendingRef' => 'ref', 'maskedPhone' => '+1******890' })
223
+
224
+ res = @instance.enchanted_link_sign_up_or_in_with_phone(
225
+ login_id: '+1234567890',
226
+ uri: 'https://some-uri/sms',
227
+ login_options: {
228
+ stepup: false,
229
+ custom_claims: { 'abc': '123' },
230
+ mfa: false,
231
+ sso_app_id: 'sso-id'
232
+ },
233
+ provider_id: 'provider-id',
234
+ template_id: 'template-id'
235
+ )
236
+
237
+ expect(res['maskedPhone']).to eq('+1******890')
238
+ end
239
+ end
240
+
241
+ context '.update_user_phone' do
242
+ it 'is expected to respond to update user phone' do
243
+ expect(@instance).to respond_to(:enchanted_link_update_user_phone)
244
+ end
245
+
246
+ it 'is expected to update user phone with enchanted link via sms' do
247
+ request_params = {
248
+ loginId: 'test',
249
+ phone: '+1234567890',
250
+ addToLoginIDs: true,
251
+ onMergeUseExisting: true,
252
+ redirectUrl: 'https://some-uri/sms',
253
+ providerId: 'provider-id',
254
+ templateId: 'template-id',
255
+ templateOptions: { 'abc': '123' }
256
+ }
257
+
258
+ expect(@instance).to receive(:post).with(
259
+ '/v1/auth/enchantedlink/update/phone/sms',
260
+ request_params,
261
+ {},
262
+ 'refresh_token'
263
+ ).and_return({ 'linkId' => '1', 'pendingRef' => 'ref', 'maskedPhone' => '+1******890' })
264
+
265
+ res = @instance.enchanted_link_update_user_phone(
266
+ login_id: 'test',
267
+ phone: '+1234567890',
268
+ uri: 'https://some-uri/sms',
269
+ add_to_login_ids: true,
270
+ on_merge_use_existing: true,
271
+ provider_id: 'provider-id',
272
+ template_id: 'template-id',
273
+ template_options: { 'abc': '123' },
274
+ refresh_token: 'refresh_token'
275
+ )
276
+
277
+ expect(res['maskedPhone']).to eq('+1******890')
278
+ end
279
+
280
+ it 'is expected to raise an error on an invalid phone number' do
281
+ expect do
282
+ @instance.enchanted_link_update_user_phone(
283
+ login_id: 'test',
284
+ phone: 'not-a-phone',
285
+ uri: 'https://some-uri/sms',
286
+ refresh_token: 'refresh_token'
287
+ )
288
+ end.to raise_error(Descope::AuthException)
289
+ end
128
290
  end
129
291
 
130
292
  context '.enchanted_link_verify_token' do
@@ -15,7 +15,7 @@ describe Descope::Api::V1::Management::AccessKey do
15
15
  end
16
16
 
17
17
  it 'is expected to create access key' do
18
- expect(@instance).to receive(:post).with(
18
+ expect(@instance).to receive(:mgmt_post).with(
19
19
  ACCESS_KEY_CREATE_PATH, {
20
20
  name: 'test',
21
21
  expireTime: 0,
@@ -46,7 +46,7 @@ describe Descope::Api::V1::Management::AccessKey do
46
46
  end
47
47
 
48
48
  it 'is expected to load an access key' do
49
- expect(@instance).to receive(:get).with(
49
+ expect(@instance).to receive(:mgmt_get).with(
50
50
  ACCESS_KEY_LOAD_PATH, { id: '123' }
51
51
  )
52
52
  expect { @instance.load_access_key('123') }.not_to raise_error
@@ -59,7 +59,7 @@ describe Descope::Api::V1::Management::AccessKey do
59
59
  end
60
60
 
61
61
  it 'is expected to search all access keys' do
62
- expect(@instance).to receive(:post).with(
62
+ expect(@instance).to receive(:mgmt_post).with(
63
63
  ACCESS_KEYS_SEARCH_PATH, { tenantIds: %w[123 456] }
64
64
  )
65
65
  expect { @instance.search_all_access_keys(%w[123 456]) }.not_to raise_error
@@ -72,7 +72,7 @@ describe Descope::Api::V1::Management::AccessKey do
72
72
  end
73
73
 
74
74
  it 'is expected to update an access keys' do
75
- expect(@instance).to receive(:post).with(
75
+ expect(@instance).to receive(:mgmt_post).with(
76
76
  ACCESS_KEY_UPDATE_PATH, { id: '123', name: 'test1' }
77
77
  )
78
78
  expect { @instance.update_access_key(id: '123', name: 'test1') }.not_to raise_error
@@ -85,7 +85,7 @@ describe Descope::Api::V1::Management::AccessKey do
85
85
  end
86
86
 
87
87
  it 'is expected to deactivate an access keys' do
88
- expect(@instance).to receive(:post).with(
88
+ expect(@instance).to receive(:mgmt_post).with(
89
89
  ACCESS_KEY_DEACTIVATE_PATH, { id: '123' }
90
90
  )
91
91
  expect { @instance.deactivate_access_key('123') }.not_to raise_error
@@ -98,7 +98,7 @@ describe Descope::Api::V1::Management::AccessKey do
98
98
  end
99
99
 
100
100
  it 'is expected to activate an access keys' do
101
- expect(@instance).to receive(:post).with(
101
+ expect(@instance).to receive(:mgmt_post).with(
102
102
  ACCESS_KEY_ACTIVATE_PATH, { id: '123' }
103
103
  )
104
104
  expect { @instance.activate_access_key('123') }.not_to raise_error
@@ -111,7 +111,7 @@ describe Descope::Api::V1::Management::AccessKey do
111
111
  end
112
112
 
113
113
  it 'is expected to delete an access keys' do
114
- expect(@instance).to receive(:post).with(
114
+ expect(@instance).to receive(:mgmt_post).with(
115
115
  ACCESS_KEY_DELETE_PATH, { id: '123' }
116
116
  )
117
117
  expect { @instance.delete_access_key('123') }.not_to raise_error
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::Analytics do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::Analytics)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.search' do
13
+ let(:mock_response) do
14
+ {
15
+ 'analytics' => [
16
+ {
17
+ 'projectId' => 'abc',
18
+ 'action' => 'get',
19
+ 'created' => '1234567000',
20
+ 'device' => 'mobile',
21
+ 'method' => 'post',
22
+ 'geo' => 'US',
23
+ 'tenant' => 'tenant1',
24
+ 'referrer' => 'referrer1',
25
+ 'cnt' => '5'
26
+ }
27
+ ]
28
+ }
29
+ end
30
+
31
+ before do
32
+ allow(@instance).to receive(:mgmt_post).with(
33
+ ANALYTICS_SEARCH_PATH,
34
+ {
35
+ from: 1_234_567_000,
36
+ to: 123_456_789_000,
37
+ groupByAction: true,
38
+ groupByDevice: true,
39
+ groupByMethod: true,
40
+ groupByGeo: true,
41
+ groupByTenant: true,
42
+ groupByReferrer: true,
43
+ groupByCreated: true,
44
+ actions: %w[action1 action2],
45
+ excludedActions: %w[exclude1 exclude2],
46
+ devices: %w[Bot Mobile Desktop Tablet Unknown],
47
+ methods: %w[otp totp magiclink oauth saml password],
48
+ geos: %w[US IL],
49
+ tenants: %w[tenant1 tenant2]
50
+ }
51
+ ).and_return(mock_response)
52
+ end
53
+
54
+ it 'should respond to .analytics_search' do
55
+ expect(@instance).to respond_to :analytics_search
56
+ end
57
+
58
+ it 'is expected to search analytics and get records' do
59
+ res = nil # define res outside the block
60
+ expect do
61
+ res = @instance.analytics_search(
62
+ from_ts: 1_234_567_000,
63
+ to_ts: 123_456_789_000,
64
+ group_by_action: true,
65
+ group_by_device: true,
66
+ group_by_method: true,
67
+ group_by_geo: true,
68
+ group_by_tenant: true,
69
+ group_by_referrer: true,
70
+ group_by_created: true,
71
+ actions: %w[action1 action2],
72
+ excluded_actions: %w[exclude1 exclude2],
73
+ devices: %w[Bot Mobile Desktop Tablet Unknown],
74
+ methods: %w[otp totp magiclink oauth saml password],
75
+ geos: %w[US IL],
76
+ tenants: %w[tenant1 tenant2]
77
+ )
78
+ end.not_to raise_error
79
+ expect(res['analytics'][0]['projectId']).to eq('abc')
80
+ end
81
+ end
82
+ end
@@ -31,7 +31,7 @@ describe Descope::Api::V1::Management::Audit do
31
31
  end
32
32
 
33
33
  before do
34
- allow(@instance).to receive(:post).twice.with(
34
+ allow(@instance).to receive(:mgmt_post).twice.with(
35
35
  AUDIT_SEARCH,
36
36
  {
37
37
  noTenants: true,
@@ -144,7 +144,7 @@ describe Descope::Api::V1::Management::Audit do
144
144
  end
145
145
 
146
146
  it 'is expected to create an audit event' do
147
- expect(@instance).to receive(:post).with(
147
+ expect(@instance).to receive(:mgmt_post).with(
148
148
  '/v1/mgmt/audit/event',
149
149
  {
150
150
  action: 'get',
@@ -34,7 +34,7 @@ describe Descope::Api::V1::Management::Authz do
34
34
  }
35
35
  ]
36
36
  }
37
- expect(@instance).to receive(:post).with(
37
+ expect(@instance).to receive(:mgmt_post).with(
38
38
  AUTHZ_SCHEMA_SAVE,
39
39
  {
40
40
  schema: schema,
@@ -53,7 +53,7 @@ describe Descope::Api::V1::Management::Authz do
53
53
  end
54
54
 
55
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)
56
+ expect(@instance).to receive(:mgmt_post).with(AUTHZ_SCHEMA_DELETE)
57
57
  expect do
58
58
  @instance.authz_delete_schema
59
59
  end.not_to raise_error
@@ -66,7 +66,7 @@ describe Descope::Api::V1::Management::Authz do
66
66
  end
67
67
 
68
68
  it 'is expected to load the schema for the project' do
69
- expect(@instance).to receive(:post).with(AUTHZ_SCHEMA_LOAD)
69
+ expect(@instance).to receive(:mgmt_post).with(AUTHZ_SCHEMA_LOAD)
70
70
  expect do
71
71
  @instance.authz_load_schema
72
72
  end.not_to raise_error
@@ -79,7 +79,7 @@ describe Descope::Api::V1::Management::Authz do
79
79
  end
80
80
 
81
81
  it 'is expected to create or update the given namespace' do
82
- expect(@instance).to receive(:post).with(
82
+ expect(@instance).to receive(:mgmt_post).with(
83
83
  AUTHZ_NS_SAVE,
84
84
  {
85
85
  namespace: 'test-namespace',
@@ -99,7 +99,7 @@ describe Descope::Api::V1::Management::Authz do
99
99
  end
100
100
 
101
101
  it 'is expected to delete the given namespace' do
102
- expect(@instance).to receive(:post).with(
102
+ expect(@instance).to receive(:mgmt_post).with(
103
103
  AUTHZ_NS_DELETE,
104
104
  {
105
105
  name: 'test-namespace',
@@ -118,7 +118,7 @@ describe Descope::Api::V1::Management::Authz do
118
118
  end
119
119
 
120
120
  it 'is expected to create or update the given relation definition' do
121
- expect(@instance).to receive(:post).with(
121
+ expect(@instance).to receive(:mgmt_post).with(
122
122
  AUTHZ_RD_SAVE,
123
123
  {
124
124
  relationDefinition: 'test-relation-definition',
@@ -144,7 +144,7 @@ describe Descope::Api::V1::Management::Authz do
144
144
  end
145
145
 
146
146
  it 'is expected to delete the given relation definition' do
147
- expect(@instance).to receive(:post).with(
147
+ expect(@instance).to receive(:mgmt_post).with(
148
148
  AUTHZ_RD_DELETE,
149
149
  {
150
150
  name: 'test-relation-definition',
@@ -168,7 +168,7 @@ describe Descope::Api::V1::Management::Authz do
168
168
  end
169
169
 
170
170
  it 'is expected to create the given relation' do
171
- expect(@instance).to receive(:post).with(
171
+ expect(@instance).to receive(:mgmt_post).with(
172
172
  AUTHZ_RE_CREATE,
173
173
  {
174
174
  relations: 'test-relations'
@@ -186,7 +186,7 @@ describe Descope::Api::V1::Management::Authz do
186
186
  end
187
187
 
188
188
  it 'is expected to delete the given relation' do
189
- expect(@instance).to receive(:post).with(
189
+ expect(@instance).to receive(:mgmt_post).with(
190
190
  AUTHZ_RE_DELETE,
191
191
  { relations: [{ resource: 'some-note', relationDefinition: 'owner', namespace: 'note', target: 'some-user' }] }
192
192
  )
@@ -204,7 +204,7 @@ describe Descope::Api::V1::Management::Authz do
204
204
  end
205
205
 
206
206
  it 'is expected to delete the given relations for resources' do
207
- expect(@instance).to receive(:post).with(
207
+ expect(@instance).to receive(:mgmt_post).with(
208
208
  AUTHZ_RE_DELETE_RESOURCES,
209
209
  {
210
210
  resources: 'test-resources'
@@ -222,7 +222,7 @@ describe Descope::Api::V1::Management::Authz do
222
222
  end
223
223
 
224
224
  it 'is expected to return true if the given resource has relations' do
225
- expect(@instance).to receive(:post).with(
225
+ expect(@instance).to receive(:mgmt_post).with(
226
226
  AUTHZ_RE_HAS_RELATIONS,
227
227
  {
228
228
  relationQueries: ['some-query']
@@ -240,7 +240,7 @@ describe Descope::Api::V1::Management::Authz do
240
240
  end
241
241
 
242
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(
243
+ expect(@instance).to receive(:mgmt_post).with(
244
244
  AUTHZ_RE_WHO,
245
245
  {
246
246
  resource: 'test-resource',
@@ -261,7 +261,7 @@ describe Descope::Api::V1::Management::Authz do
261
261
  end
262
262
 
263
263
  it 'is expected to return the list of relations for the given resources' do
264
- expect(@instance).to receive(:post).with(
264
+ expect(@instance).to receive(:mgmt_post).with(
265
265
  AUTHZ_RE_RESOURCE,
266
266
  {
267
267
  resources: ['test-resources']
@@ -279,7 +279,7 @@ describe Descope::Api::V1::Management::Authz do
279
279
  end
280
280
 
281
281
  it 'is expected to return the list of relations for the given targets' do
282
- expect(@instance).to receive(:post).with(
282
+ expect(@instance).to receive(:mgmt_post).with(
283
283
  AUTHZ_RE_TARGETS,
284
284
  {
285
285
  targets: ['test-targets']
@@ -306,7 +306,7 @@ describe Descope::Api::V1::Management::Authz do
306
306
  end
307
307
 
308
308
  before do
309
- allow(@instance).to receive(:post).with(
309
+ allow(@instance).to receive(:mgmt_post).with(
310
310
  AUTHZ_RE_TARGET_ALL,
311
311
  {
312
312
  target: 'test-target'
@@ -319,7 +319,7 @@ describe Descope::Api::V1::Management::Authz do
319
319
  end
320
320
 
321
321
  it 'is expected to return the list of relations for the given target' do
322
- expect(@instance).to receive(:post).with(
322
+ expect(@instance).to receive(:mgmt_post).with(
323
323
  AUTHZ_RE_TARGET_ALL,
324
324
  {
325
325
  target: 'test-target'
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::Descoper do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::Descoper)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.create_descoper' do
13
+ it 'should respond to .create_descoper' do
14
+ expect(@instance).to respond_to :create_descoper
15
+ end
16
+
17
+ it 'is expected to create the given descopers' do
18
+ expect(@instance).to receive(:mgmt_put).with(
19
+ DESCOPER_CREATE_PATH,
20
+ {
21
+ descopers: [{ name: 'test-descoper' }]
22
+ }
23
+ )
24
+ expect do
25
+ @instance.create_descoper([{ name: 'test-descoper' }])
26
+ end.not_to raise_error
27
+ end
28
+ end
29
+
30
+ context '.update_descoper' do
31
+ it 'should respond to .update_descoper' do
32
+ expect(@instance).to respond_to :update_descoper
33
+ end
34
+
35
+ it 'is expected to update the given descoper' do
36
+ expect(@instance).to receive(:mgmt_patch).with(
37
+ DESCOPER_UPDATE_PATH,
38
+ {
39
+ id: 'test-id',
40
+ attributes: { key: 'value' },
41
+ rbac: { roles: ['admin'] }
42
+ }
43
+ )
44
+ expect do
45
+ @instance.update_descoper(id: 'test-id', attributes: { key: 'value' }, rbac: { roles: ['admin'] })
46
+ end.not_to raise_error
47
+ end
48
+ end
49
+
50
+ context '.get_descoper' do
51
+ it 'should respond to .get_descoper' do
52
+ expect(@instance).to respond_to :get_descoper
53
+ end
54
+
55
+ it 'is expected to get the given descoper by id' do
56
+ expect(@instance).to receive(:mgmt_get).with(
57
+ DESCOPER_GET_PATH,
58
+ {
59
+ id: 'test-id'
60
+ }
61
+ )
62
+ expect do
63
+ @instance.get_descoper(id: 'test-id')
64
+ end.not_to raise_error
65
+ end
66
+ end
67
+
68
+ context '.delete_descoper' do
69
+ it 'should respond to .delete_descoper' do
70
+ expect(@instance).to respond_to :delete_descoper
71
+ end
72
+
73
+ it 'is expected to delete the given descoper by id' do
74
+ expect(@instance).to receive(:mgmt_delete).with(
75
+ DESCOPER_DELETE_PATH,
76
+ {
77
+ id: 'test-id'
78
+ }
79
+ )
80
+ expect do
81
+ @instance.delete_descoper(id: 'test-id')
82
+ end.not_to raise_error
83
+ end
84
+ end
85
+
86
+ context '.search_descopers' do
87
+ it 'should respond to .search_descopers' do
88
+ expect(@instance).to respond_to :search_descopers
89
+ end
90
+
91
+ it 'is expected to search (list) all descopers' do
92
+ expect(@instance).to receive(:mgmt_post).with(
93
+ DESCOPER_SEARCH_PATH,
94
+ {}
95
+ )
96
+ expect do
97
+ @instance.search_descopers
98
+ end.not_to raise_error
99
+ end
100
+ end
101
+ end