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
@@ -0,0 +1,285 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::Lists do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::Lists)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.create_list' do
13
+ it 'should respond to .create_list' do
14
+ expect(@instance).to respond_to :create_list
15
+ end
16
+
17
+ it 'is expected to create a new list' do
18
+ expect(@instance).to receive(:mgmt_post).with(
19
+ LIST_CREATE_PATH,
20
+ {
21
+ name: 'test-list',
22
+ type: 'ip',
23
+ description: 'test description',
24
+ data: { 'foo' => 'bar' }
25
+ }
26
+ )
27
+ expect do
28
+ @instance.create_list(
29
+ name: 'test-list',
30
+ type: 'ip',
31
+ description: 'test description',
32
+ data: { 'foo' => 'bar' }
33
+ )
34
+ end.not_to raise_error
35
+ end
36
+
37
+ it 'is expected to create a new list without optional fields' do
38
+ expect(@instance).to receive(:mgmt_post).with(
39
+ LIST_CREATE_PATH,
40
+ { name: 'test-list', type: 'ip' }
41
+ )
42
+ expect do
43
+ @instance.create_list(name: 'test-list', type: 'ip')
44
+ end.not_to raise_error
45
+ end
46
+ end
47
+
48
+ context '.update_list' do
49
+ it 'should respond to .update_list' do
50
+ expect(@instance).to respond_to :update_list
51
+ end
52
+
53
+ it 'is expected to update an existing list' do
54
+ expect(@instance).to receive(:mgmt_post).with(
55
+ LIST_UPDATE_PATH,
56
+ {
57
+ id: 'test-id',
58
+ name: 'test-list',
59
+ type: 'ip',
60
+ description: 'test description',
61
+ data: { 'foo' => 'bar' }
62
+ }
63
+ )
64
+ expect do
65
+ @instance.update_list(
66
+ id: 'test-id',
67
+ name: 'test-list',
68
+ type: 'ip',
69
+ description: 'test description',
70
+ data: { 'foo' => 'bar' }
71
+ )
72
+ end.not_to raise_error
73
+ end
74
+ end
75
+
76
+ context '.delete_list' do
77
+ it 'should respond to .delete_list' do
78
+ expect(@instance).to respond_to :delete_list
79
+ end
80
+
81
+ it 'is expected to delete an existing list' do
82
+ expect(@instance).to receive(:mgmt_post).with(
83
+ LIST_DELETE_PATH,
84
+ { id: 'test-id' }
85
+ )
86
+ expect do
87
+ @instance.delete_list(id: 'test-id')
88
+ end.not_to raise_error
89
+ end
90
+ end
91
+
92
+ context '.load_list' do
93
+ it 'should respond to .load_list' do
94
+ expect(@instance).to respond_to :load_list
95
+ end
96
+
97
+ it 'is expected to load a list by id' do
98
+ expect(@instance).to receive(:mgmt_get).with("#{LIST_LOAD_PATH}/test-id")
99
+ expect do
100
+ @instance.load_list(id: 'test-id')
101
+ end.not_to raise_error
102
+ end
103
+ end
104
+
105
+ context '.load_list_by_name' do
106
+ it 'should respond to .load_list_by_name' do
107
+ expect(@instance).to respond_to :load_list_by_name
108
+ end
109
+
110
+ it 'is expected to load a list by name' do
111
+ expect(@instance).to receive(:mgmt_get).with("#{LIST_LOAD_BY_NAME_PATH}/test-list")
112
+ expect do
113
+ @instance.load_list_by_name(name: 'test-list')
114
+ end.not_to raise_error
115
+ end
116
+ end
117
+
118
+ context '.load_all_lists' do
119
+ it 'should respond to .load_all_lists' do
120
+ expect(@instance).to respond_to :load_all_lists
121
+ end
122
+
123
+ it 'is expected to load all lists' do
124
+ expect(@instance).to receive(:mgmt_get).with(LIST_LOAD_ALL_PATH)
125
+ expect do
126
+ @instance.load_all_lists
127
+ end.not_to raise_error
128
+ end
129
+ end
130
+
131
+ context '.import_lists' do
132
+ it 'should respond to .import_lists' do
133
+ expect(@instance).to respond_to :import_lists
134
+ end
135
+
136
+ it 'is expected to import the given lists' do
137
+ lists = [{ name: 'test-list', type: 'ip' }]
138
+ expect(@instance).to receive(:mgmt_post).with(
139
+ LIST_IMPORT_PATH,
140
+ { lists: }
141
+ )
142
+ expect do
143
+ @instance.import_lists(lists:)
144
+ end.not_to raise_error
145
+ end
146
+ end
147
+
148
+ context '.list_add_ips' do
149
+ it 'should respond to .list_add_ips' do
150
+ expect(@instance).to respond_to :list_add_ips
151
+ end
152
+
153
+ it 'is expected to add the given IPs to the list' do
154
+ expect(@instance).to receive(:mgmt_post).with(
155
+ LIST_ADD_IPS_PATH,
156
+ { id: 'test-id', ips: ['1.2.3.4'] }
157
+ )
158
+ expect do
159
+ @instance.list_add_ips(id: 'test-id', ips: ['1.2.3.4'])
160
+ end.not_to raise_error
161
+ end
162
+ end
163
+
164
+ context '.list_remove_ips' do
165
+ it 'should respond to .list_remove_ips' do
166
+ expect(@instance).to respond_to :list_remove_ips
167
+ end
168
+
169
+ it 'is expected to remove the given IPs from the list' do
170
+ expect(@instance).to receive(:mgmt_post).with(
171
+ LIST_REMOVE_IPS_PATH,
172
+ { id: 'test-id', ips: ['1.2.3.4'] }
173
+ )
174
+ expect do
175
+ @instance.list_remove_ips(id: 'test-id', ips: ['1.2.3.4'])
176
+ end.not_to raise_error
177
+ end
178
+ end
179
+
180
+ context '.list_check_ip' do
181
+ it 'should respond to .list_check_ip' do
182
+ expect(@instance).to respond_to :list_check_ip
183
+ end
184
+
185
+ it 'is expected to check whether the given IP exists in the list' do
186
+ expect(@instance).to receive(:mgmt_post).with(
187
+ LIST_CHECK_IP_PATH,
188
+ { id: 'test-id', ip: '1.2.3.4' }
189
+ )
190
+ expect do
191
+ @instance.list_check_ip(id: 'test-id', ip: '1.2.3.4')
192
+ end.not_to raise_error
193
+ end
194
+ end
195
+
196
+ context '.list_add_texts' do
197
+ it 'should respond to .list_add_texts' do
198
+ expect(@instance).to respond_to :list_add_texts
199
+ end
200
+
201
+ it 'is expected to add the given texts to the list' do
202
+ expect(@instance).to receive(:mgmt_post).with(
203
+ LIST_ADD_TEXTS_PATH,
204
+ { id: 'test-id', texts: ['some-text'] }
205
+ )
206
+ expect do
207
+ @instance.list_add_texts(id: 'test-id', texts: ['some-text'])
208
+ end.not_to raise_error
209
+ end
210
+ end
211
+
212
+ context '.list_remove_texts' do
213
+ it 'should respond to .list_remove_texts' do
214
+ expect(@instance).to respond_to :list_remove_texts
215
+ end
216
+
217
+ it 'is expected to remove the given texts from the list' do
218
+ expect(@instance).to receive(:mgmt_post).with(
219
+ LIST_REMOVE_TEXTS_PATH,
220
+ { id: 'test-id', texts: ['some-text'] }
221
+ )
222
+ expect do
223
+ @instance.list_remove_texts(id: 'test-id', texts: ['some-text'])
224
+ end.not_to raise_error
225
+ end
226
+ end
227
+
228
+ context '.list_check_text' do
229
+ it 'should respond to .list_check_text' do
230
+ expect(@instance).to respond_to :list_check_text
231
+ end
232
+
233
+ it 'is expected to check whether the given text exists in the list' do
234
+ expect(@instance).to receive(:mgmt_post).with(
235
+ LIST_CHECK_TEXT_PATH,
236
+ { id: 'test-id', text: 'some-text' }
237
+ )
238
+ expect do
239
+ @instance.list_check_text(id: 'test-id', text: 'some-text')
240
+ end.not_to raise_error
241
+ end
242
+ end
243
+
244
+ context '.list_check_texts' do
245
+ it 'should respond to .list_check_texts' do
246
+ expect(@instance).to respond_to :list_check_texts
247
+ end
248
+
249
+ it 'is expected to check whether any of the given texts exist in the list by default' do
250
+ expect(@instance).to receive(:mgmt_post).with(
251
+ LIST_CHECK_TEXT_PATH,
252
+ { id: 'test-id', texts: %w[text-1 text-2], matchAll: false }
253
+ )
254
+ expect do
255
+ @instance.list_check_texts(id: 'test-id', texts: %w[text-1 text-2])
256
+ end.not_to raise_error
257
+ end
258
+
259
+ it 'is expected to check whether all of the given texts exist in the list when match_all is set' do
260
+ expect(@instance).to receive(:mgmt_post).with(
261
+ LIST_CHECK_TEXT_PATH,
262
+ { id: 'test-id', texts: %w[text-1 text-2], matchAll: true }
263
+ )
264
+ expect do
265
+ @instance.list_check_texts(id: 'test-id', texts: %w[text-1 text-2], match_all: true)
266
+ end.not_to raise_error
267
+ end
268
+ end
269
+
270
+ context '.clear_list' do
271
+ it 'should respond to .clear_list' do
272
+ expect(@instance).to respond_to :clear_list
273
+ end
274
+
275
+ it 'is expected to clear all entries from the list' do
276
+ expect(@instance).to receive(:mgmt_post).with(
277
+ LIST_CLEAR_PATH,
278
+ { id: 'test-id' }
279
+ )
280
+ expect do
281
+ @instance.clear_list(id: 'test-id')
282
+ end.not_to raise_error
283
+ end
284
+ end
285
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::ManagementKey do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::ManagementKey)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ context '.create_management_key' do
13
+ it 'should respond to .create_management_key' do
14
+ expect(@instance).to respond_to :create_management_key
15
+ end
16
+
17
+ it 'is expected to create a management key' do
18
+ expect(@instance).to receive(:mgmt_put).with(
19
+ MGMT_KEY_CREATE_PATH, {
20
+ name: 'test',
21
+ description: 'test key',
22
+ expiresIn: 0,
23
+ permittedIps: ['1.2.3.4'],
24
+ reBac: { 'k1': 'v1' }
25
+ }
26
+ )
27
+ expect do
28
+ @instance.create_management_key(
29
+ name: 'test',
30
+ description: 'test key',
31
+ expires_in: 0,
32
+ permitted_ips: ['1.2.3.4'],
33
+ re_bac: { 'k1': 'v1' }
34
+ )
35
+ end.not_to raise_error
36
+ end
37
+ end
38
+
39
+ context '.update_management_key' do
40
+ it 'should respond to .update_management_key' do
41
+ expect(@instance).to respond_to :update_management_key
42
+ end
43
+
44
+ it 'is expected to update a management key' do
45
+ expect(@instance).to receive(:mgmt_patch).with(
46
+ MGMT_KEY_UPDATE_PATH, {
47
+ id: '123',
48
+ name: 'test1',
49
+ description: 'updated',
50
+ permittedIps: ['1.2.3.4'],
51
+ status: 'active'
52
+ }
53
+ )
54
+ expect do
55
+ @instance.update_management_key(
56
+ id: '123',
57
+ name: 'test1',
58
+ description: 'updated',
59
+ permitted_ips: ['1.2.3.4'],
60
+ status: 'active'
61
+ )
62
+ end.not_to raise_error
63
+ end
64
+ end
65
+
66
+ context '.get_management_key' do
67
+ it 'should respond to .get_management_key' do
68
+ expect(@instance).to respond_to :get_management_key
69
+ end
70
+
71
+ it 'is expected to get a management key' do
72
+ expect(@instance).to receive(:mgmt_get).with(
73
+ MGMT_KEY_GET_PATH, { id: '123' }
74
+ )
75
+ expect { @instance.get_management_key(id: '123') }.not_to raise_error
76
+ end
77
+ end
78
+
79
+ context '.delete_management_key' do
80
+ it 'should respond to .delete_management_key' do
81
+ expect(@instance).to respond_to :delete_management_key
82
+ end
83
+
84
+ it 'is expected to delete a management key' do
85
+ expect(@instance).to receive(:mgmt_post).with(
86
+ MGMT_KEY_DELETE_PATH, { ids: ['123'] }
87
+ )
88
+ expect { @instance.delete_management_key(id: '123') }.not_to raise_error
89
+ end
90
+ end
91
+
92
+ context '.search_management_keys' do
93
+ it 'should respond to .search_management_keys' do
94
+ expect(@instance).to respond_to :search_management_keys
95
+ end
96
+
97
+ it 'is expected to search management keys' do
98
+ expect(@instance).to receive(:mgmt_get).with(
99
+ MGMT_KEY_SEARCH_PATH, {
100
+ tenantIds: %w[123 456],
101
+ status: 'active'
102
+ }
103
+ )
104
+ expect do
105
+ @instance.search_management_keys(tenant_ids: %w[123 456], status: 'active')
106
+ end.not_to raise_error
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,236 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Descope::Api::V1::Management::OutboundApp do
6
+ before(:all) do
7
+ dummy_instance = DummyClass.new
8
+ dummy_instance.extend(Descope::Api::V1::Management::OutboundApp)
9
+ @instance = dummy_instance
10
+ end
11
+
12
+ describe '.fetch_outbound_app_user_token' do
13
+ let(:mock_response) do
14
+ {
15
+ 'token' => {
16
+ 'id' => 'token-123',
17
+ 'appId' => 'app-123',
18
+ 'userId' => 'user-123',
19
+ 'tokenSub' => 'sub-123',
20
+ 'accessToken' => 'access-token-value',
21
+ 'accessTokenType' => 'Bearer',
22
+ 'accessTokenExpiry' => '2025-12-31T23:59:59Z',
23
+ 'hasRefreshToken' => true,
24
+ 'refreshToken' => 'refresh-token-value',
25
+ 'scopes' => %w[read write],
26
+ 'tenantId' => 'tenant-123'
27
+ }
28
+ }
29
+ end
30
+
31
+ it 'responds to fetch_outbound_app_user_token' do
32
+ expect(@instance).to respond_to :fetch_outbound_app_user_token
33
+ end
34
+
35
+ it 'raises an error when app_id is empty' do
36
+ expect do
37
+ @instance.fetch_outbound_app_user_token(app_id: '', user_id: 'user-123')
38
+ end.to raise_error(Descope::ArgumentException, 'app_id cannot be empty')
39
+ end
40
+
41
+ it 'raises an error when app_id is nil' do
42
+ expect do
43
+ @instance.fetch_outbound_app_user_token(app_id: nil, user_id: 'user-123')
44
+ end.to raise_error(Descope::ArgumentException, 'app_id cannot be empty')
45
+ end
46
+
47
+ it 'raises an error when user_id is empty' do
48
+ expect do
49
+ @instance.fetch_outbound_app_user_token(app_id: 'app-123', user_id: '')
50
+ end.to raise_error(Descope::ArgumentException, 'Missing user id')
51
+ end
52
+
53
+ it 'raises an error when user_id is nil' do
54
+ expect do
55
+ @instance.fetch_outbound_app_user_token(app_id: 'app-123', user_id: nil)
56
+ end.to raise_error(Descope::ArgumentException, 'Missing user id')
57
+ end
58
+
59
+ it 'fetches token with required parameters only' do
60
+ expect(@instance).to receive(:mgmt_post).with(
61
+ '/v1/mgmt/outbound/app/user/token',
62
+ {
63
+ appId: 'app-123',
64
+ userId: 'user-123'
65
+ }
66
+ ).and_return(mock_response)
67
+
68
+ result = @instance.fetch_outbound_app_user_token(app_id: 'app-123', user_id: 'user-123')
69
+ expect(result['token']['accessToken']).to eq('access-token-value')
70
+ end
71
+
72
+ it 'fetches token with scopes' do
73
+ expect(@instance).to receive(:mgmt_post).with(
74
+ '/v1/mgmt/outbound/app/user/token',
75
+ {
76
+ appId: 'app-123',
77
+ userId: 'user-123',
78
+ scopes: %w[read write]
79
+ }
80
+ ).and_return(mock_response)
81
+
82
+ result = @instance.fetch_outbound_app_user_token(
83
+ app_id: 'app-123',
84
+ user_id: 'user-123',
85
+ scopes: %w[read write]
86
+ )
87
+ expect(result['token']['scopes']).to eq(%w[read write])
88
+ end
89
+
90
+ it 'fetches token with options' do
91
+ expect(@instance).to receive(:mgmt_post).with(
92
+ '/v1/mgmt/outbound/app/user/token',
93
+ {
94
+ appId: 'app-123',
95
+ userId: 'user-123',
96
+ options: {
97
+ withRefreshToken: true,
98
+ forceRefresh: true
99
+ }
100
+ }
101
+ ).and_return(mock_response)
102
+
103
+ result = @instance.fetch_outbound_app_user_token(
104
+ app_id: 'app-123',
105
+ user_id: 'user-123',
106
+ with_refresh_token: true,
107
+ force_refresh: true
108
+ )
109
+ expect(result['token']['hasRefreshToken']).to be(true)
110
+ end
111
+
112
+ it 'fetches token with tenant_id' do
113
+ expect(@instance).to receive(:mgmt_post).with(
114
+ '/v1/mgmt/outbound/app/user/token',
115
+ {
116
+ appId: 'app-123',
117
+ userId: 'user-123',
118
+ tenantId: 'tenant-123'
119
+ }
120
+ ).and_return(mock_response)
121
+
122
+ result = @instance.fetch_outbound_app_user_token(
123
+ app_id: 'app-123',
124
+ user_id: 'user-123',
125
+ tenant_id: 'tenant-123'
126
+ )
127
+ expect(result['token']['tenantId']).to eq('tenant-123')
128
+ end
129
+
130
+ it 'fetches token with all parameters' do
131
+ expect(@instance).to receive(:mgmt_post).with(
132
+ '/v1/mgmt/outbound/app/user/token',
133
+ {
134
+ appId: 'app-123',
135
+ userId: 'user-123',
136
+ scopes: %w[read write],
137
+ tenantId: 'tenant-123',
138
+ options: {
139
+ withRefreshToken: true,
140
+ forceRefresh: false
141
+ }
142
+ }
143
+ ).and_return(mock_response)
144
+
145
+ result = @instance.fetch_outbound_app_user_token(
146
+ app_id: 'app-123',
147
+ user_id: 'user-123',
148
+ scopes: %w[read write],
149
+ tenant_id: 'tenant-123',
150
+ with_refresh_token: true,
151
+ force_refresh: false
152
+ )
153
+ expect(result['token']['id']).to eq('token-123')
154
+ end
155
+ end
156
+
157
+ describe '.delete_outbound_app_user_tokens' do
158
+ it 'responds to delete_outbound_app_user_tokens' do
159
+ expect(@instance).to respond_to :delete_outbound_app_user_tokens
160
+ end
161
+
162
+ it 'raises an error when both app_id and user_id are empty' do
163
+ expect do
164
+ @instance.delete_outbound_app_user_tokens(app_id: '', user_id: '')
165
+ end.to raise_error(Descope::ArgumentException, 'At least one of app_id or user_id must be provided')
166
+ end
167
+
168
+ it 'raises an error when both app_id and user_id are nil' do
169
+ expect do
170
+ @instance.delete_outbound_app_user_tokens
171
+ end.to raise_error(Descope::ArgumentException, 'At least one of app_id or user_id must be provided')
172
+ end
173
+
174
+ it 'deletes tokens by app_id only' do
175
+ expect(@instance).to receive(:mgmt_delete).with(
176
+ '/v1/mgmt/outbound/user/tokens',
177
+ { appId: 'app-123' }
178
+ )
179
+
180
+ expect do
181
+ @instance.delete_outbound_app_user_tokens(app_id: 'app-123')
182
+ end.not_to raise_error
183
+ end
184
+
185
+ it 'deletes tokens by user_id only' do
186
+ expect(@instance).to receive(:mgmt_delete).with(
187
+ '/v1/mgmt/outbound/user/tokens',
188
+ { userId: 'user-123' }
189
+ )
190
+
191
+ expect do
192
+ @instance.delete_outbound_app_user_tokens(user_id: 'user-123')
193
+ end.not_to raise_error
194
+ end
195
+
196
+ it 'deletes tokens by both app_id and user_id' do
197
+ expect(@instance).to receive(:mgmt_delete).with(
198
+ '/v1/mgmt/outbound/user/tokens',
199
+ { appId: 'app-123', userId: 'user-123' }
200
+ )
201
+
202
+ expect do
203
+ @instance.delete_outbound_app_user_tokens(app_id: 'app-123', user_id: 'user-123')
204
+ end.not_to raise_error
205
+ end
206
+ end
207
+
208
+ describe '.delete_outbound_app_token_by_id' do
209
+ it 'responds to delete_outbound_app_token_by_id' do
210
+ expect(@instance).to respond_to :delete_outbound_app_token_by_id
211
+ end
212
+
213
+ it 'raises an error when token_id is empty' do
214
+ expect do
215
+ @instance.delete_outbound_app_token_by_id(token_id: '')
216
+ end.to raise_error(Descope::ArgumentException, 'token_id cannot be empty')
217
+ end
218
+
219
+ it 'raises an error when token_id is nil' do
220
+ expect do
221
+ @instance.delete_outbound_app_token_by_id(token_id: nil)
222
+ end.to raise_error(Descope::ArgumentException, 'token_id cannot be empty')
223
+ end
224
+
225
+ it 'deletes token by id' do
226
+ expect(@instance).to receive(:mgmt_delete).with(
227
+ '/v1/mgmt/outbound/token',
228
+ { id: 'token-123' }
229
+ )
230
+
231
+ expect do
232
+ @instance.delete_outbound_app_token_by_id(token_id: 'token-123')
233
+ end.not_to raise_error
234
+ end
235
+ end
236
+ end
@@ -11,14 +11,14 @@ describe Descope::Api::V1::Management::Password do
11
11
 
12
12
  context '.get_password_settings' do
13
13
  it 'should get password settings' do
14
- expect(@instance).to receive(:get).with('/v1/mgmt/password/settings', { tenantId: 'tenant_id' })
14
+ expect(@instance).to receive(:mgmt_get).with('/v1/mgmt/password/settings', { tenantId: 'tenant_id' })
15
15
  @instance.get_password_settings('tenant_id')
16
16
  end
17
17
  end
18
18
 
19
19
  context '.update_password_settings' do
20
20
  it 'should update password settings' do
21
- expect(@instance).to receive(:post).with('/v1/mgmt/password/settings', { 'minLength' => 10 })
21
+ expect(@instance).to receive(:mgmt_post).with('/v1/mgmt/password/settings', { 'minLength' => 10 })
22
22
  @instance.update_password_settings({ min_length: 10 })
23
23
  end
24
24
  end
@@ -15,7 +15,7 @@ describe Descope::Api::V1::Management::Permission do
15
15
  end
16
16
 
17
17
  it 'is expected to create a new permission' do
18
- expect(@instance).to receive(:post).with(
18
+ expect(@instance).to receive(:mgmt_post).with(
19
19
  PERMISSION_CREATE_PATH, {
20
20
  name: 'test',
21
21
  description: 'test'
@@ -36,7 +36,7 @@ describe Descope::Api::V1::Management::Permission do
36
36
  end
37
37
 
38
38
  it 'is expected to update a permission' do
39
- expect(@instance).to receive(:post).with(
39
+ expect(@instance).to receive(:mgmt_post).with(
40
40
  PERMISSION_UPDATE_PATH, {
41
41
  name: 'test',
42
42
  newName: 'production',
@@ -59,7 +59,7 @@ describe Descope::Api::V1::Management::Permission do
59
59
  end
60
60
 
61
61
  it 'is expected to delete a permission' do
62
- expect(@instance).to receive(:post).with(
62
+ expect(@instance).to receive(:mgmt_post).with(
63
63
  PERMISSION_DELETE_PATH, { name: 'test' }
64
64
  )
65
65
  expect do
@@ -74,7 +74,7 @@ describe Descope::Api::V1::Management::Permission do
74
74
  end
75
75
 
76
76
  it 'is expected to delete a permission' do
77
- expect(@instance).to receive(:get).with(PERMISSION_LOAD_ALL_PATH)
77
+ expect(@instance).to receive(:mgmt_get).with(PERMISSION_LOAD_ALL_PATH)
78
78
  expect { @instance.load_all_permissions }.not_to raise_error
79
79
  end
80
80
  end