auth0 4.4.0 → 4.5.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.
@@ -45,6 +45,30 @@ describe Auth0::Api::V2::Users do
45
45
  client.users(per_page: 1, fields: [:email].join(','), include_fields: false).first
46
46
  ).to include('user_id', 'picture')
47
47
  end
48
+
49
+ it 'is expected to find a user with a v2 search engine query' do
50
+ sleep 1
51
+ expect(
52
+ client.users(
53
+ per_page: 1,
54
+ fields: 'user_id',
55
+ q: "updated_at:{2016-01-01 TO *}",
56
+ search_engine: 'v2'
57
+ ).first
58
+ ).to include('user_id')
59
+ end
60
+
61
+ it 'is expected to find a user with a v3 search engine query' do
62
+ sleep 1
63
+ expect(
64
+ client.users(
65
+ per_page: 1,
66
+ fields: 'user_id',
67
+ q: "updated_at:[2016-01-01 TO *]",
68
+ search_engine: 'v3'
69
+ ).first
70
+ ).to include('user_id')
71
+ end
48
72
  end
49
73
  end
50
74
 
@@ -150,19 +174,6 @@ describe Auth0::Api::V2::Users do
150
174
  end
151
175
 
152
176
  let(:body_link) { { 'provider' => 'auth0', 'user_id' => link_user['user_id'] } }
153
- skip 'Link user account examples are skipped to avoid errors on users deletion' do
154
- it do
155
- expect(
156
- client.link_user_account(primary_user['user_id'], body_link).first
157
- ).to include('provider' => 'auth0', 'user_id' => primary_user['identities'].first['user_id'])
158
- end
159
-
160
- it do
161
- expect(
162
- client.unlink_users_account(primary_user['user_id'], 'auth0', link_user['user_id']).first
163
- ).to include('provider' => 'auth0', 'user_id' => primary_user['identities'].first['user_id'])
164
- end
165
- end
166
177
  end
167
178
 
168
179
  end
@@ -1,5 +1,8 @@
1
+ # rubocop:disable Metrics/BlockLength
1
2
  require 'spec_helper'
2
3
  describe Auth0::Api::AuthenticationEndpoints do
4
+ UP_AUTH = 'Username-Password-Authentication'.freeze
5
+
3
6
  before :all do
4
7
  dummy_instance = DummyClass.new
5
8
  dummy_instance.extend(Auth0::Api::AuthenticationEndpoints)
@@ -13,7 +16,7 @@ describe Auth0::Api::AuthenticationEndpoints do
13
16
  allow(@instance).to receive(:post).with(
14
17
  '/oauth/token', client_id: @instance.client_id, client_secret: nil, grant_type: 'client_credentials'
15
18
  )
16
- .and_return('access_token' => 'AccessToken')
19
+ .and_return('access_token' => 'AccessToken')
17
20
  expect(@instance).to receive(:post).with(
18
21
  '/oauth/token', client_id: @instance.client_id, client_secret: nil, grant_type: 'client_credentials'
19
22
  )
@@ -28,7 +31,7 @@ describe Auth0::Api::AuthenticationEndpoints do
28
31
  '/oauth/access_token', client_id: @instance.client_id, access_token: 'access_token', connection: 'facebook',
29
32
  scope: 'openid'
30
33
  )
31
- .and_return('access_token' => 'AccessToken')
34
+ .and_return('access_token' => 'AccessToken')
32
35
  expect(@instance).to receive(:post).with(
33
36
  '/oauth/access_token', client_id: @instance.client_id, access_token: 'access_token', connection: 'facebook',
34
37
  scope: 'openid'
@@ -44,7 +47,7 @@ describe Auth0::Api::AuthenticationEndpoints do
44
47
  '/oauth/token', client_id: @instance.client_id, client_secret: nil, grant_type: 'authorization_code',
45
48
  connection: 'facebook', code: 'code', scope: 'openid', redirect_uri: 'uri'
46
49
  )
47
- .and_return('user_tokens' => 'UserToken')
50
+ .and_return('user_tokens' => 'UserToken')
48
51
  expect(@instance).to receive(:post).with(
49
52
  '/oauth/token', client_id: @instance.client_id, client_secret: nil, grant_type: 'authorization_code',
50
53
  connection: 'facebook', code: 'code', scope: 'openid', redirect_uri: 'uri'
@@ -63,64 +66,102 @@ describe Auth0::Api::AuthenticationEndpoints do
63
66
  client_id: @instance.client_id,
64
67
  username: 'test@test.com',
65
68
  client_secret: @instance.client_secret,
66
- password: 'password', scope: 'openid', connection: 'Username-Password-Authentication',
69
+ password: 'test12345', scope: 'openid', connection: 'Username-Password-Authentication',
67
70
  grant_type: 'password', id_token: nil, device: nil
68
71
  )
69
- @instance.login('test@test.com', 'password')
72
+ @instance.login('test@test.com', 'test12345')
70
73
  end
71
74
  it { expect { @instance.login('', '') }.to raise_error 'Must supply a valid username' }
72
75
  it { expect { @instance.login('username', '') }.to raise_error 'Must supply a valid password' }
73
76
  end
74
77
 
78
+ # Auth0::API::AuthenticationEndpoints.signup
75
79
  context '.signup' do
76
80
  it { expect(@instance).to respond_to(:signup) }
77
- it 'is expected to make post to /dbconnections/signup' do
81
+
82
+ it 'is expected to make a post request to /dbconnections/signup' do
78
83
  expect(@instance).to receive(:post).with(
79
84
  '/dbconnections/signup',
80
- client_id: @instance.client_id, email: 'test@test.com',
81
- password: 'password', connection: 'User'
85
+ client_id: @instance.client_id,
86
+ email: 'test@test.com',
87
+ password: 'password',
88
+ connection: 'User'
82
89
  )
83
90
  @instance.signup('test@test.com', 'password', 'User')
84
91
  end
85
- it { expect { @instance.signup('', '') }.to raise_error 'Must supply a valid email' }
86
- it { expect { @instance.signup('email', '') }.to raise_error 'Must supply a valid password' }
92
+
93
+ it 'is expected to raise an error with an empty email' do
94
+ expect do
95
+ @instance.signup('', '')
96
+ end.to raise_error 'Must supply a valid email'
97
+ end
98
+
99
+ it 'is expected to raise an error with an empty password' do
100
+ expect do
101
+ @instance.signup('email', '')
102
+ end.to raise_error 'Must supply a valid password'
103
+ end
87
104
  end
88
105
 
106
+ # Auth0::API::AuthenticationEndpoints.change_password
89
107
  context '.change_password' do
90
108
  it { expect(@instance).to respond_to(:change_password) }
109
+
91
110
  it 'is expected to make post to /dbconnections/change_password' do
92
111
  expect(@instance).to receive(:post).with(
93
112
  '/dbconnections/change_password',
94
- client_id: @instance.client_id, email: 'test@test.com',
95
- password: 'password', connection: 'User'
113
+ client_id: @instance.client_id,
114
+ email: 'test@test.com',
115
+ password: 'password',
116
+ connection: 'User'
96
117
  )
97
118
  @instance.change_password('test@test.com', 'password', 'User')
98
119
  end
99
- it { expect { @instance.change_password('', '', '') }.to raise_error 'Must supply a valid email' }
120
+
121
+ it 'is expected to raise an error with an empty email' do
122
+ expect do
123
+ @instance.change_password('', '', '')
124
+ end.to raise_error 'Must supply a valid email'
125
+ end
100
126
  end
101
127
 
128
+ # Auth0::API::AuthenticationEndpoints.start_passwordless_email_flow
102
129
  context '.start_passwordless_email_flow' do
103
130
  it { expect(@instance).to respond_to(:start_passwordless_email_flow) }
131
+
104
132
  it 'is expected to make post to /passwordless/start' do
105
133
  expect(@instance).to receive(:post).with(
106
134
  '/passwordless/start',
107
135
  client_id: @instance.client_id,
108
136
  connection: 'email',
109
137
  email: 'test@test.com',
110
- send: 'link',
138
+ send: 'code',
111
139
  authParams: {
112
140
  scope: 'scope',
113
141
  protocol: 'protocol'
114
142
  }
115
143
  )
116
- @instance.start_passwordless_email_flow('test@test.com', 'link', scope: 'scope', protocol: 'protocol')
144
+ @instance.start_passwordless_email_flow(
145
+ 'test@test.com',
146
+ 'code',
147
+ scope: 'scope',
148
+ protocol: 'protocol'
149
+ )
150
+ end
151
+
152
+ it 'is expected to raise an error with an empty email' do
153
+ expect do
154
+ @instance.start_passwordless_email_flow('', '', '')
155
+ end.to raise_error 'Must supply a valid email'
117
156
  end
118
- it { expect { @instance.start_passwordless_email_flow('', '', '') }.to raise_error 'Must supply a valid email' }
119
157
  end
120
158
 
159
+ # Auth0::API::AuthenticationEndpoints.start_passwordless_sms_flow
121
160
  context '.start_passwordless_sms_flow' do
122
161
  let(:phone_number) { Faker::PhoneNumber.cell_phone }
162
+
123
163
  it { expect(@instance).to respond_to(:start_passwordless_sms_flow) }
164
+
124
165
  it 'is expected to make post to /passwordless/start' do
125
166
  expect(@instance).to receive(:post).with(
126
167
  '/passwordless/start',
@@ -130,7 +171,12 @@ describe Auth0::Api::AuthenticationEndpoints do
130
171
  )
131
172
  @instance.start_passwordless_sms_flow(phone_number)
132
173
  end
133
- it { expect { @instance.start_passwordless_sms_flow('') }.to raise_error 'Must supply a valid phone number' }
174
+
175
+ it 'is expected to raise an error with an empty phone number' do
176
+ expect do
177
+ @instance.start_passwordless_sms_flow('')
178
+ end.to raise_error 'Must supply a valid phone number'
179
+ end
134
180
  end
135
181
 
136
182
  context '.phone_login' do
@@ -150,54 +196,30 @@ describe Auth0::Api::AuthenticationEndpoints do
150
196
  it { expect { @instance.phone_login('phone', '') }.to raise_error 'Must supply a valid code' }
151
197
  end
152
198
 
199
+ # Auth0::API::AuthenticationEndpoints.saml_metadata
153
200
  context '.saml_metadata' do
154
201
  it { expect(@instance).to respond_to(:saml_metadata) }
155
- it 'is expected to make post to /samlp/metadata/client-id' do
156
- expect(@instance).to receive(:get).with("/samlp/metadata/#{@instance.client_id}")
202
+
203
+ it 'is expected to make post to SAMLP metadata endpoint' do
204
+ expect(@instance).to receive(:get).with(
205
+ "/samlp/metadata/#{@instance.client_id}"
206
+ )
157
207
  @instance.saml_metadata
158
208
  end
159
209
  end
160
210
 
211
+ # Auth0::API::AuthenticationEndpoints.wsfed_metadata
161
212
  context '.wsfed_metadata' do
162
213
  it { expect(@instance).to respond_to(:wsfed_metadata) }
163
- it 'is expected to make post to /wsfed/FederationMetadata/2007-06/FederationMetadata.xml' do
164
- expect(@instance).to receive(:get).with('/wsfed/FederationMetadata/2007-06/FederationMetadata.xml')
165
- @instance.wsfed_metadata
166
- end
167
- end
168
214
 
169
- context '.authorization_url' do
170
- let(:redirect_uri) { 'http://redirect.com' }
171
- it { expect(@instance).to respond_to(:authorization_url) }
172
- it 'is expected to return an authorization url' do
173
- expect(@instance.authorization_url(redirect_uri).to_s).to eq(
174
- "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
175
- "redirect_uri=#{redirect_uri}"
176
- )
177
- end
178
- let(:additional_parameters) { { additional_parameters: { aparam1: 'test1' } } }
179
- it 'is expected to return an authorization url with additionalParameters' do
180
- expect(@instance.authorization_url(redirect_uri, additional_parameters).to_s).to eq(
181
- "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
182
- "redirect_uri=#{redirect_uri}&aparam1=test1"
183
- )
184
- end
185
- let(:state) { { state: 'state1' } }
186
- it 'is expected to return an authorization url with additionalParameters' do
187
- expect(@instance.authorization_url(redirect_uri, state).to_s).to eq(
188
- "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
189
- "redirect_uri=#{redirect_uri}&state=state1"
190
- )
191
- end
192
- let(:connection) { { connection: 'connection-1' } }
193
- it 'is expected to return an authorization url with additionalParameters' do
194
- expect(@instance.authorization_url(redirect_uri, connection).to_s).to eq(
195
- "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
196
- "connection=connection-1&redirect_uri=#{redirect_uri}"
215
+ it 'is expected to make post to WS-Fed metadata endpoint' do
216
+ expect(@instance).to receive(:get).with(
217
+ '/wsfed/FederationMetadata/2007-06/FederationMetadata.xml'
197
218
  )
219
+ @instance.wsfed_metadata
198
220
  end
199
- it { expect { @instance.authorization_url('', '') }.to raise_error 'Must supply a valid redirect_uri' }
200
221
  end
222
+
201
223
  context '.token_info' do
202
224
  it { expect(@instance).to respond_to(:token_info) }
203
225
  it 'is expected to make post to /tokeinfo' do
@@ -308,41 +330,122 @@ describe Auth0::Api::AuthenticationEndpoints do
308
330
  end
309
331
  end
310
332
 
333
+ context '.authorization_url' do
334
+ let(:redirect_uri) { 'http://redirect.com' }
335
+ it { expect(@instance).to respond_to(:authorization_url) }
336
+ it 'is expected to return an authorization url' do
337
+ expect(@instance.authorization_url(redirect_uri).to_s).to eq(
338
+ "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
339
+ 'redirect_uri=http%3A%2F%2Fredirect.com'
340
+ )
341
+ end
342
+ let(:additional_parameters) { { additional_parameters: { aparam1: 'test1' } } }
343
+ it 'is expected to return an authorization url with additionalParameters' do
344
+ expect(@instance.authorization_url(redirect_uri, additional_parameters).to_s).to eq(
345
+ "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
346
+ 'redirect_uri=http%3A%2F%2Fredirect.com&aparam1=test1'
347
+ )
348
+ end
349
+ let(:state) { { state: 'state1' } }
350
+ it 'is expected to return an authorization url with additionalParameters' do
351
+ expect(@instance.authorization_url(redirect_uri, state).to_s).to eq(
352
+ "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
353
+ 'redirect_uri=http%3A%2F%2Fredirect.com&state=state1'
354
+ )
355
+ end
356
+ let(:connection) { { connection: 'connection-1' } }
357
+ it 'is expected to return an authorization url with additionalParameters' do
358
+ expect(@instance.authorization_url(redirect_uri, connection).to_s).to eq(
359
+ "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
360
+ 'connection=connection-1&redirect_uri=http%3A%2F%2Fredirect.com'
361
+ )
362
+ end
363
+ it { expect { @instance.authorization_url('', '') }.to raise_error 'Must supply a valid redirect_uri' }
364
+ end
365
+
366
+ # Auth0::API::AuthenticationEndpoints.logout_url
311
367
  context '.logout_url' do
312
368
  let(:return_to) { 'http://returnto.com' }
369
+
313
370
  it { expect(@instance).to respond_to(:logout_url) }
371
+
314
372
  it 'is expected to return a logout url' do
315
373
  expect(@instance.logout_url(return_to).to_s).to eq(
316
- "https://#{@instance.domain}/logout?returnTo=#{return_to}"
374
+ "https://#{@instance.domain}/v2/logout?" \
375
+ 'returnTo=http%3A%2F%2Freturnto.com'
376
+ )
377
+ end
378
+
379
+ it 'is expected to return a logout url with a client ID' do
380
+ expect(@instance.logout_url(return_to, include_client: true).to_s).to eq(
381
+ "https://#{@instance.domain}/v2/logout" +
382
+ "?returnTo=http%3A%2F%2Freturnto.com&client_id=#{@instance.client_id}"
383
+ )
384
+ end
385
+
386
+ it 'is expected to return a logout url with federated parameter' do
387
+ expect(@instance.logout_url(return_to, federated: true).to_s).to eq(
388
+ "https://#{@instance.domain}/v2/logout?" \
389
+ 'returnTo=http%3A%2F%2Freturnto.com&federated=1'
317
390
  )
318
391
  end
319
392
  end
320
393
 
394
+ # Auth0::API::AuthenticationEndpoints.samlp_url
321
395
  context '.samlp_url' do
322
396
  it { expect(@instance).to respond_to(:samlp_url) }
397
+
323
398
  it 'is expected to get the samlp url' do
324
399
  expect(@instance.samlp_url.to_s).to eq(
325
- "https://#{@instance.domain}/samlp/#{@instance.client_id}?connection=Username-Password-Authentication"
400
+ "https://#{@instance.domain}/samlp/#{@instance.client_id}" \
401
+ '?connection=Username-Password-Authentication'
326
402
  )
327
403
  end
404
+
328
405
  it 'is expected to get the samlp url with fb connection' do
329
406
  expect(@instance.samlp_url('facebook').to_s).to eq(
330
- "https://#{@instance.domain}/samlp/#{@instance.client_id}?connection=facebook"
407
+ "https://#{@instance.domain}/samlp/#{@instance.client_id}" \
408
+ '?connection=facebook'
331
409
  )
332
410
  end
333
411
  end
334
412
 
413
+ # Auth0::API::AuthenticationEndpoints.wsfed_url
335
414
  context '.wsfed_url' do
336
415
  it { expect(@instance).to respond_to(:wsfed_url) }
416
+
337
417
  it 'is expected to get the wsfed url' do
338
418
  expect(@instance.wsfed_url.to_s).to eq(
339
- "https://#{@instance.domain}/wsfed/#{@instance.client_id}?whr=Username-Password-Authentication"
419
+ "https://#{@instance.domain}/wsfed/#{@instance.client_id}" \
420
+ "?whr=#{UP_AUTH}"
340
421
  )
341
422
  end
423
+
342
424
  it 'is expected to get the wsfed url with fb connection' do
343
425
  expect(@instance.wsfed_url('facebook').to_s).to eq(
344
426
  "https://#{@instance.domain}/wsfed/#{@instance.client_id}?whr=facebook"
345
427
  )
346
428
  end
429
+
430
+ it 'is expected to get the wsfed url with wctx' do
431
+ expect(@instance.wsfed_url(UP_AUTH, {wctx: 'wctx_test'}).to_s).to eq(
432
+ "https://#{@instance.domain}/wsfed/#{@instance.client_id}" \
433
+ "?whr=#{UP_AUTH}&wctx=wctx_test"
434
+ )
435
+ end
436
+
437
+ it 'is expected to get the wsfed url with wtrealm and wreply' do
438
+ expect(@instance.wsfed_url(
439
+ UP_AUTH,
440
+ {
441
+ wtrealm: 'wtrealm_test',
442
+ wreply: 'wreply_test'
443
+ }
444
+ ).to_s).to eq(
445
+ "https://#{@instance.domain}/wsfed/?whr=#{UP_AUTH}" \
446
+ '&wtrealm=wtrealm_test&wreply=wreply_test'
447
+ )
448
+ end
347
449
  end
348
450
  end
451
+ # rubocop:enable Metrics/BlockLength
@@ -5,13 +5,28 @@ describe Auth0::Api::V2::ClientGrants do
5
5
  dummy_instance.extend(Auth0::Api::V2::ClientGrants)
6
6
  @instance = dummy_instance
7
7
  end
8
+
8
9
  context '.client_grants' do
9
10
  it { expect(@instance).to respond_to(:client_grants) }
10
11
  it { expect(@instance).to respond_to(:get_all_client_grants) }
11
- it 'is expected to send get request to /api/v2/client_grants/' do
12
- expect(@instance).to receive(:get).with('/api/v2/client-grants')
12
+
13
+ it 'is expected to get /api/v2/client-grants/' do
14
+ expect(@instance).to receive(:get).with(
15
+ '/api/v2/client-grants',
16
+ page: nil,
17
+ per_page: nil
18
+ )
13
19
  expect { @instance.client_grants }.not_to raise_error
14
20
  end
21
+
22
+ it 'is expected to send get /api/v2/client-grants/ with pagination' do
23
+ expect(@instance).to receive(:get).with(
24
+ '/api/v2/client-grants',
25
+ page: 1,
26
+ per_page: 2
27
+ )
28
+ expect { @instance.client_grants(page: 1, per_page: 2) }.not_to raise_error
29
+ end
15
30
  end
16
31
 
17
32
  context '.create_client_grant' do
@@ -5,18 +5,62 @@ describe Auth0::Api::V2::Clients do
5
5
  dummy_instance.extend(Auth0::Api::V2::Clients)
6
6
  @instance = dummy_instance
7
7
  end
8
+
8
9
  context '.clients' do
9
10
  it { expect(@instance).to respond_to(:clients) }
10
11
  it { expect(@instance).to respond_to(:get_clients) }
11
- it 'is expected to send get request to /api/v2/clients/' do
12
- expect(@instance).to receive(:get).with('/api/v2/clients', fields: nil, include_fields: nil)
12
+
13
+ it 'is expected to send get request to the Clients endpoint' do
14
+ expect(@instance).to receive(:get).with(
15
+ '/api/v2/clients',
16
+ fields: nil,
17
+ include_fields: nil,
18
+ page: nil,
19
+ per_page: nil
20
+ )
13
21
  expect { @instance.clients }.not_to raise_error
14
22
  end
15
- it 'is expected to send get request to /api/v2/clients?fields=name' do
16
- expect(@instance).to receive(:get).with('/api/v2/clients', include_fields: true, fields: [:name])
17
- expect { @instance.clients(fields: [:name], include_fields: true) }.not_to raise_error
23
+
24
+ it 'is expected to send get request to the Clients endpoint with a name parameter' do
25
+ expect(@instance).to receive(:get).with(
26
+ '/api/v2/clients',
27
+ include_fields: true,
28
+ fields: 'name',
29
+ page: nil,
30
+ per_page: nil
31
+ )
32
+ expect {
33
+ @instance.clients(fields: 'name', include_fields: true)
34
+ }.not_to raise_error
35
+ end
36
+
37
+ it 'is expected to send get request to Clients endpoint using an array of fields' do
38
+ expect(@instance).to receive(:get).with(
39
+ '/api/v2/clients',
40
+ include_fields: true,
41
+ fields: 'name,app_type',
42
+ page: nil,
43
+ per_page: nil
44
+ )
45
+ expect {
46
+ @instance.clients(fields: ['name','app_type'], include_fields: true)
47
+ }.not_to raise_error
48
+ end
49
+
50
+ it 'is expected to send get request to Clients endpoint with pagination' do
51
+ expect(@instance).to receive(:get).with(
52
+ '/api/v2/clients',
53
+ page: 1,
54
+ per_page: 10,
55
+ fields: nil,
56
+ include_fields: nil
57
+ )
58
+ expect {
59
+ @instance.clients(page: 1, per_page: 10)
60
+ }.not_to raise_error
18
61
  end
19
62
  end
63
+
20
64
  context '.client' do
21
65
  it { expect(@instance).to respond_to(:client) }
22
66
  it 'is expected to send get request to /api/v2/clients/1' do
@@ -38,6 +82,7 @@ describe Auth0::Api::V2::Clients do
38
82
  end
39
83
  it { expect { @instance.create_client('') }.to raise_error 'Must specify a valid client name' }
40
84
  end
85
+
41
86
  context '.delete_client' do
42
87
  it { expect(@instance).to respond_to(:delete_client) }
43
88
  it 'is expected to send delete to /api/v2/clients/1' do