auth0 3.6.1 → 4.0.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.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +7 -0
- data/.travis.yml +12 -7
- data/CHANGELOG.md +10 -0
- data/Gemfile +4 -2
- data/Guardfile +13 -10
- data/LICENSE +2 -2
- data/README.md +9 -11
- data/Rakefile +33 -7
- data/auth0.gemspec +12 -12
- data/deploy_documentation.sh +29 -0
- data/doc_config/templates/default/fulldoc/html/css/full_list.css +79 -0
- data/doc_config/templates/default/fulldoc/html/css/style.css +546 -0
- data/doc_config/templates/default/layout/html/breadcrumb.erb +11 -0
- data/doc_config/templates/default/layout/html/footer.erb +115 -0
- data/doc_config/templates/default/layout/html/headers.erb +17 -0
- data/doc_config/templates/default/layout/html/layout.erb +27 -0
- data/lib/auth0.rb +5 -5
- data/lib/auth0/api/authentication_endpoints.rb +264 -46
- data/lib/auth0/api/v1.rb +5 -5
- data/lib/auth0/api/v1/clients.rb +7 -7
- data/lib/auth0/api/v1/connections.rb +9 -10
- data/lib/auth0/api/v1/logs.rb +9 -16
- data/lib/auth0/api/v1/rules.rb +5 -5
- data/lib/auth0/api/v1/users.rb +28 -27
- data/lib/auth0/api/v2.rb +17 -9
- data/lib/auth0/api/v2/blacklists.rb +30 -9
- data/lib/auth0/api/v2/clients.rb +60 -19
- data/lib/auth0/api/v2/connections.rb +63 -10
- data/lib/auth0/api/v2/emails.rb +58 -0
- data/lib/auth0/api/v2/jobs.rb +44 -7
- data/lib/auth0/api/v2/rules.rb +104 -0
- data/lib/auth0/api/v2/stats.rb +22 -5
- data/lib/auth0/api/v2/tenants.rb +39 -0
- data/lib/auth0/api/v2/tickets.rb +58 -0
- data/lib/auth0/api/v2/users.rb +128 -39
- data/lib/auth0/client.rb +8 -6
- data/lib/auth0/exception.rb +29 -23
- data/lib/auth0/mixins.rb +12 -10
- data/lib/auth0/mixins/httparty_proxy.rb +13 -10
- data/lib/auth0/mixins/initializer.rb +25 -27
- data/lib/auth0/version.rb +2 -2
- data/spec/integration/lib/auth0/api/v1/api_clients_spec.rb +2 -4
- data/spec/integration/lib/auth0/api/v1/api_users_spec.rb +25 -32
- data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +14 -0
- data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +61 -6
- data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +68 -42
- data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +71 -0
- data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +69 -0
- data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +83 -0
- data/spec/integration/lib/auth0/api/v2/api_stats_spec.rb +16 -0
- data/spec/integration/lib/auth0/api/v2/api_tenants_spec.rb +37 -0
- data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +33 -0
- data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +88 -36
- data/spec/integration/lib/auth0/auth0_client_spec.rb +43 -35
- data/spec/lib/auth0/api/authentication_endpoints_spec.rb +253 -47
- data/spec/lib/auth0/api/v1/clients_spec.rb +37 -38
- data/spec/lib/auth0/api/v1/connections_spec.rb +44 -38
- data/spec/lib/auth0/api/v1/logs_spec.rb +24 -24
- data/spec/lib/auth0/api/v1/rules_spec.rb +23 -22
- data/spec/lib/auth0/api/v1/users_spec.rb +153 -130
- data/spec/lib/auth0/api/v2/blacklists_spec.rb +12 -11
- data/spec/lib/auth0/api/v2/clients_spec.rb +38 -33
- data/spec/lib/auth0/api/v2/connections_spec.rb +59 -34
- data/spec/lib/auth0/api/v2/emails_spec.rb +47 -0
- data/spec/lib/auth0/api/v2/jobs_spec.rb +24 -10
- data/spec/lib/auth0/api/v2/rules_spec.rb +69 -0
- data/spec/lib/auth0/api/v2/stats_spec.rb +11 -11
- data/spec/lib/auth0/api/v2/tenants_spec.rb +25 -0
- data/spec/lib/auth0/api/v2/tickets_spec.rb +31 -0
- data/spec/lib/auth0/api/v2/users_spec.rb +101 -39
- data/spec/lib/auth0/client_spec.rb +46 -58
- data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +98 -69
- data/spec/lib/auth0/mixins/initializer_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/spec_helper_full.rb +16 -15
- data/spec/spec_helper_unit.rb +5 -5
- data/spec/support/credentials.rb +9 -3
- data/spec/support/dummy_class.rb +7 -1
- data/spec/support/dummy_class_for_proxy.rb +2 -2
- data/spec/support/import_users.json +13 -0
- data/spec/support/stub_response.rb +1 -2
- metadata +78 -41
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
describe Auth0::Api::V2::Tenants do
|
|
3
|
+
before :all do
|
|
4
|
+
@instance = DummyClass.new.extend(Auth0::Api::V2::Tenants)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
context '.get_tenant_settings' do
|
|
8
|
+
it { expect(@instance).to respond_to(:get_tenant_settings) }
|
|
9
|
+
it 'expect client to send post to /api/v2/tenants/settings with fields' do
|
|
10
|
+
expect(@instance).to receive(:get).with('/api/v2/tenants/settings', fields: 'field', include_fields: true)
|
|
11
|
+
expect { @instance.get_tenant_settings(fields: 'field') }.not_to raise_error
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
context '.update_tenant_settings' do
|
|
15
|
+
it { expect(@instance).to respond_to(:update_tenant_settings) }
|
|
16
|
+
it 'expect client to send post to /api/v2/tenants/settings with body' do
|
|
17
|
+
expect(@instance).to receive(:patch).with('/api/v2/tenants/settings', 'test body')
|
|
18
|
+
expect { @instance.update_tenant_settings('test body') }.not_to raise_error
|
|
19
|
+
end
|
|
20
|
+
it 'expect client to rasie error when calling with empty body' do
|
|
21
|
+
expect { @instance.update_tenant_settings(nil) }.to raise_error(
|
|
22
|
+
'Must supply a valid body to update tenant settings')
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
describe Auth0::Api::V2::Tickets do
|
|
3
|
+
before :all do
|
|
4
|
+
@instance = DummyClass.new.extend(Auth0::Api::V2::Tickets)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
context '.post_email_verification' do
|
|
8
|
+
it { expect(@instance).to respond_to(:post_email_verification) }
|
|
9
|
+
it 'expect client to send post to /api/v2/tickets/email-verification with body' do
|
|
10
|
+
expect(@instance).to receive(:post).with('/api/v2/tickets/email-verification', user_id: 'user_id', result_url: nil)
|
|
11
|
+
expect { @instance.post_email_verification('user_id') }.not_to raise_error
|
|
12
|
+
end
|
|
13
|
+
it 'expect client to rasie error when calling with empty body' do
|
|
14
|
+
expect { @instance.post_email_verification(nil) }.to raise_error(
|
|
15
|
+
'Must supply a valid user id to post an email verification')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
context '.post_password_change' do
|
|
19
|
+
it { expect(@instance).to respond_to(:post_password_change) }
|
|
20
|
+
it 'expect client to send post to /api/v2/tickets/password-change with body' do
|
|
21
|
+
expect(@instance).to receive(:post).with('/api/v2/tickets/password-change', user_id: nil, result_url: nil,
|
|
22
|
+
new_password: 'new_pass',
|
|
23
|
+
connection_id: nil, email: nil)
|
|
24
|
+
expect { @instance.post_password_change('new_pass') }.not_to raise_error
|
|
25
|
+
end
|
|
26
|
+
it 'expect client to rasie error when calling with empty body' do
|
|
27
|
+
expect { @instance.post_password_change(nil) }.to raise_error(
|
|
28
|
+
'Must supply a valid new password to post a password-change')
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
describe Auth0::Api::V2::Users do
|
|
3
3
|
before :all do
|
|
4
4
|
dummy_instance = DummyClass.new
|
|
@@ -6,67 +6,129 @@ describe Auth0::Api::V2::Users do
|
|
|
6
6
|
@instance = dummy_instance
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
context
|
|
10
|
-
it {expect(@instance).to respond_to(:users)}
|
|
11
|
-
it {expect(@instance).to respond_to(:get_users)}
|
|
12
|
-
it
|
|
13
|
-
expect(@instance).to receive(:get).with(
|
|
14
|
-
|
|
9
|
+
context '.users' do
|
|
10
|
+
it { expect(@instance).to respond_to(:users) }
|
|
11
|
+
it { expect(@instance).to respond_to(:get_users) }
|
|
12
|
+
it 'is expected to call /api/v2/users' do
|
|
13
|
+
expect(@instance).to receive(:get).with(
|
|
14
|
+
'/api/v2/users',
|
|
15
|
+
per_page: nil,
|
|
16
|
+
page: nil,
|
|
17
|
+
include_totals: nil,
|
|
18
|
+
sort: nil,
|
|
19
|
+
connection: nil,
|
|
20
|
+
fields: nil,
|
|
21
|
+
include_fields: nil,
|
|
22
|
+
q: nil)
|
|
23
|
+
expect { @instance.users }.not_to raise_error
|
|
15
24
|
end
|
|
16
25
|
end
|
|
17
26
|
|
|
18
|
-
context
|
|
19
|
-
it {expect(@instance).to respond_to(:user)}
|
|
20
|
-
it
|
|
21
|
-
expect(@instance).to receive(:get).with(
|
|
22
|
-
expect{@instance.user(
|
|
27
|
+
context '.user' do
|
|
28
|
+
it { expect(@instance).to respond_to(:user) }
|
|
29
|
+
it 'is expected to call get request to /api/v2/users/USER_ID' do
|
|
30
|
+
expect(@instance).to receive(:get).with('/api/v2/users/USER_ID', fields: nil, include_fields: true)
|
|
31
|
+
expect { @instance.user('USER_ID') }.not_to raise_error
|
|
23
32
|
end
|
|
33
|
+
it { expect { @instance.user('') }.to raise_error 'Must supply a valid user_id' }
|
|
24
34
|
end
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
it
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
context '.create_user' do
|
|
37
|
+
it { expect(@instance).to respond_to(:create_user) }
|
|
38
|
+
it 'is expected to call post to /api/v2/users' do
|
|
39
|
+
expect(@instance).to receive(:post).with(
|
|
40
|
+
'/api/v2/users',
|
|
41
|
+
email: 'test@test.com',
|
|
42
|
+
password: 'password',
|
|
43
|
+
connection: 'conn',
|
|
44
|
+
name: 'name')
|
|
45
|
+
@instance.create_user(
|
|
46
|
+
'name',
|
|
47
|
+
email: 'test@test.com',
|
|
48
|
+
password: 'password',
|
|
49
|
+
connection: 'conn')
|
|
32
50
|
end
|
|
33
51
|
end
|
|
34
52
|
|
|
35
|
-
context
|
|
36
|
-
it {expect(@instance).to respond_to :delete_users}
|
|
37
|
-
it
|
|
38
|
-
expect(@instance).to receive(:delete).with(
|
|
53
|
+
context '.delete_users' do
|
|
54
|
+
it { expect(@instance).to respond_to :delete_users }
|
|
55
|
+
it 'is expected to call delete to /api/v2/users' do
|
|
56
|
+
expect(@instance).to receive(:delete).with('/api/v2/users')
|
|
39
57
|
@instance.delete_users
|
|
40
58
|
end
|
|
41
59
|
end
|
|
42
60
|
|
|
43
|
-
context
|
|
44
|
-
it {expect(@instance).to respond_to(:delete_user)}
|
|
45
|
-
it
|
|
46
|
-
expect(@instance).to receive(:delete).with(
|
|
47
|
-
@instance.delete_user(
|
|
61
|
+
context '.delete_user' do
|
|
62
|
+
it { expect(@instance).to respond_to(:delete_user) }
|
|
63
|
+
it 'is expected to call delete to /api/v2/users/userId' do
|
|
64
|
+
expect(@instance).to receive(:delete).with('/api/v2/users/userId')
|
|
65
|
+
@instance.delete_user('userId')
|
|
48
66
|
end
|
|
49
67
|
|
|
50
|
-
it
|
|
68
|
+
it 'is expected not to call delete to /api/v2/users if user_id is blank' do
|
|
51
69
|
expect(@instance).not_to receive(:delete)
|
|
52
|
-
expect{@instance.delete_user(
|
|
70
|
+
expect { @instance.delete_user('') }.to raise_exception(
|
|
71
|
+
Auth0::MissingUserId)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context '.delete_user_provider' do
|
|
76
|
+
it { expect(@instance).to respond_to(:delete_user_provider) }
|
|
77
|
+
it 'is expected to call delete to /api/v2/users/userId/multifactor/provider' do
|
|
78
|
+
expect(@instance).to receive(:delete).with('/api/v2/users/userId/multifactor/provider')
|
|
79
|
+
@instance.delete_user_provider('userId', 'provider')
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context '.patch_user' do
|
|
84
|
+
it { expect(@instance).to respond_to(:patch_user) }
|
|
85
|
+
it 'is expected to call patch to /api/v2/users/userID' do
|
|
86
|
+
expect(@instance).to receive(:patch).with(
|
|
87
|
+
'/api/v2/users/UserID',
|
|
88
|
+
email: 'test@test.com',
|
|
89
|
+
password: 'password',
|
|
90
|
+
connection: 'conn',
|
|
91
|
+
name: 'name')
|
|
92
|
+
@instance.patch_user(
|
|
93
|
+
'UserID',
|
|
94
|
+
email: 'test@test.com',
|
|
95
|
+
password: 'password',
|
|
96
|
+
connection: 'conn',
|
|
97
|
+
name: 'name')
|
|
53
98
|
end
|
|
99
|
+
it { expect { @instance.patch_user('', 'body') }.to raise_error 'Must supply a valid user_id' }
|
|
100
|
+
it { expect { @instance.patch_user('UserId', '') }.to raise_error 'Must supply a valid body' }
|
|
54
101
|
end
|
|
55
102
|
|
|
56
|
-
context
|
|
57
|
-
it {expect(@instance).to respond_to(:
|
|
58
|
-
it
|
|
59
|
-
expect(@instance).to receive(:
|
|
60
|
-
@instance.
|
|
103
|
+
context '.link_user_account' do
|
|
104
|
+
it { expect(@instance).to respond_to(:link_user_account) }
|
|
105
|
+
it 'is expected to call post to /api/v2/users/UserId/identities' do
|
|
106
|
+
expect(@instance).to receive(:post).with('/api/v2/users/UserID/identities', body: 'json body')
|
|
107
|
+
@instance.link_user_account('UserID', body: 'json body')
|
|
61
108
|
end
|
|
109
|
+
it { expect { @instance.link_user_account('', 'body') }.to raise_error 'Must supply a valid user_id' }
|
|
110
|
+
it { expect { @instance.link_user_account('UserId', '') }.to raise_error 'Must supply a valid body' }
|
|
62
111
|
end
|
|
63
112
|
|
|
64
|
-
context
|
|
65
|
-
it {expect(@instance).to respond_to(:
|
|
66
|
-
it
|
|
67
|
-
expect(@instance).to receive(:
|
|
68
|
-
@instance.
|
|
113
|
+
context '.unlink_users_account' do
|
|
114
|
+
it { expect(@instance).to respond_to(:unlink_users_account) }
|
|
115
|
+
it 'is expected to call delete to /api/v2/users/UserId/identities' do
|
|
116
|
+
expect(@instance).to receive(:delete).with('/api/v2/users/UserID/identities/provider_name/Secondary_User_ID')
|
|
117
|
+
@instance.unlink_users_account('UserID', 'provider_name', 'Secondary_User_ID')
|
|
118
|
+
end
|
|
119
|
+
it { expect { @instance.unlink_users_account('', 'pro', 'SUserID') }.to raise_error 'Must supply a valid user_id' }
|
|
120
|
+
it { expect { @instance.unlink_users_account('UID', nil, 'SUID') }.to raise_error 'Must supply a valid provider' }
|
|
121
|
+
it do
|
|
122
|
+
expect { @instance.unlink_users_account('UID', 'pro', nil) }.to raise_error 'Must supply a valid secondary user_id'
|
|
69
123
|
end
|
|
70
124
|
end
|
|
71
125
|
|
|
126
|
+
context '.delete_user_provider' do
|
|
127
|
+
it { expect(@instance).to respond_to(:delete_user_provider) }
|
|
128
|
+
it 'is expected to call delete to /api/v2/users/User_ID/multifactor/provider_name' do
|
|
129
|
+
expect(@instance).to receive(:delete).with('/api/v2/users/User_ID/multifactor/provider_name')
|
|
130
|
+
@instance.delete_user_provider('User_ID', 'provider_name')
|
|
131
|
+
end
|
|
132
|
+
it { expect { @instance.delete_user_provider(nil, 'test') }.to raise_error 'Must supply a valid user_id' }
|
|
133
|
+
end
|
|
72
134
|
end
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Auth0::Client do
|
|
4
|
-
|
|
5
|
-
shared_examples_for "v1 API client" do
|
|
4
|
+
shared_examples_for 'v1 API client' do
|
|
6
5
|
it { should be_a Auth0::Api::V1 }
|
|
7
6
|
it { should be_a Auth0::Api::V1::Users }
|
|
8
7
|
it { should be_a Auth0::Api::V1::Connections }
|
|
@@ -17,7 +16,7 @@ describe Auth0::Client do
|
|
|
17
16
|
it { should_not be_a Auth0::Api::V2::Blacklists }
|
|
18
17
|
end
|
|
19
18
|
|
|
20
|
-
shared_examples_for
|
|
19
|
+
shared_examples_for 'v2 API client' do
|
|
21
20
|
it { should be_a Auth0::Api::V2 }
|
|
22
21
|
it { should be_a Auth0::Api::V2::Clients }
|
|
23
22
|
it { should be_a Auth0::Api::V2::Users }
|
|
@@ -32,84 +31,73 @@ describe Auth0::Client do
|
|
|
32
31
|
it { should_not be_a Auth0::Api::V1::Logs }
|
|
33
32
|
end
|
|
34
33
|
|
|
35
|
-
shared_examples_for
|
|
34
|
+
shared_examples_for 'authentication API client' do
|
|
36
35
|
it { should be_a Auth0::Api::AuthenticationEndpoints }
|
|
37
36
|
end
|
|
38
37
|
|
|
39
|
-
let(:domain) {
|
|
40
|
-
let(:client_id) {
|
|
41
|
-
let(:client_secret) {
|
|
42
|
-
let(:jwt) {
|
|
43
|
-
let(:access_token) {
|
|
44
|
-
|
|
45
|
-
describe "V1 client" do
|
|
38
|
+
let(:domain) { 'samples.auth0.com' }
|
|
39
|
+
let(:client_id) { 'client_id' }
|
|
40
|
+
let(:client_secret) { 'client_secret' }
|
|
41
|
+
let(:jwt) { 'Header.Payload.Signature' }
|
|
42
|
+
let(:access_token) { 'token' }
|
|
46
43
|
|
|
44
|
+
describe 'V1 client' do
|
|
47
45
|
before :each do
|
|
48
|
-
allow_any_instance_of(Auth0::Api::AuthenticationEndpoints).to receive(:obtain_access_token).and_return
|
|
46
|
+
allow_any_instance_of(Auth0::Api::AuthenticationEndpoints).to receive(:obtain_access_token).and_return 'token'
|
|
49
47
|
end
|
|
50
48
|
|
|
51
|
-
context
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
it_should_behave_like "v1 API client"
|
|
56
|
-
it_should_behave_like "authentication API client"
|
|
49
|
+
context 'with namespace' do
|
|
50
|
+
let(:subject) do
|
|
51
|
+
Auth0::Client.new(client_id: 'client_id', client_secret: 'client_secret', namespace: 'samples.auth0.com')
|
|
52
|
+
end
|
|
57
53
|
|
|
54
|
+
it_should_behave_like 'v1 API client'
|
|
55
|
+
it_should_behave_like 'authentication API client'
|
|
58
56
|
end
|
|
59
57
|
|
|
60
|
-
context
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
it_should_behave_like "v1 API client"
|
|
65
|
-
it_should_behave_like "authentication API client"
|
|
58
|
+
context 'with domain' do
|
|
59
|
+
let(:subject) do
|
|
60
|
+
Auth0::Client.new(client_id: 'client_id', client_secret: 'client_secret', domain: 'samples.auth0.com')
|
|
61
|
+
end
|
|
66
62
|
|
|
63
|
+
it_should_behave_like 'v1 API client'
|
|
64
|
+
it_should_behave_like 'authentication API client'
|
|
67
65
|
end
|
|
68
66
|
|
|
69
|
-
context
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
context 'with version' do
|
|
68
|
+
let(:subject) do
|
|
69
|
+
Auth0::Client.new(
|
|
70
|
+
client_id: 'client_id',
|
|
71
|
+
client_secret: 'client_secret',
|
|
72
|
+
domain: 'samples.auth0.com',
|
|
73
|
+
api_version: 1)
|
|
74
|
+
end
|
|
75
|
+
it_should_behave_like 'v1 API client'
|
|
76
|
+
it_should_behave_like 'authentication API client'
|
|
76
77
|
end
|
|
77
|
-
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
describe
|
|
81
|
-
|
|
80
|
+
describe 'V2 client' do
|
|
82
81
|
before :each do
|
|
83
82
|
expect_any_instance_of(Auth0::Api::AuthenticationEndpoints).not_to receive(:obtain_access_token)
|
|
84
83
|
end
|
|
85
84
|
|
|
86
|
-
context
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
it_should_behave_like "v2 API client"
|
|
91
|
-
it_should_behave_like "authentication API client"
|
|
92
|
-
|
|
85
|
+
context 'with namespace' do
|
|
86
|
+
let(:subject) { Auth0::Client.new(protocols: 'v2', access_token: 'access_token', namespace: 'samples.auth0.com') }
|
|
87
|
+
it_should_behave_like 'v2 API client'
|
|
88
|
+
it_should_behave_like 'authentication API client'
|
|
93
89
|
end
|
|
94
90
|
|
|
95
|
-
context
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
it_should_behave_like "v2 API client"
|
|
100
|
-
it_should_behave_like "authentication API client"
|
|
101
|
-
|
|
91
|
+
context 'with domain' do
|
|
92
|
+
let(:subject) { Auth0::Client.new(protocols: 'v2', access_token: 'access_token', domain: 'samples.auth0.com') }
|
|
93
|
+
it_should_behave_like 'v2 API client'
|
|
94
|
+
it_should_behave_like 'authentication API client'
|
|
102
95
|
end
|
|
103
96
|
|
|
104
|
-
context
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
it_should_behave_like "v2 API client"
|
|
109
|
-
it_should_behave_like "authentication API client"
|
|
110
|
-
|
|
97
|
+
context 'with version' do
|
|
98
|
+
let(:subject) { Auth0::Client.new(api_version: 2, access_token: 'access_token', domain: 'samples.auth0.com') }
|
|
99
|
+
it_should_behave_like 'v2 API client'
|
|
100
|
+
it_should_behave_like 'authentication API client'
|
|
111
101
|
end
|
|
112
|
-
|
|
113
102
|
end
|
|
114
|
-
|
|
115
103
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
describe Auth0::Mixins::HTTPartyProxy do
|
|
3
3
|
before :all do
|
|
4
4
|
dummy_instance = DummyClassForProxy.new
|
|
@@ -8,111 +8,140 @@ describe Auth0::Mixins::HTTPartyProxy do
|
|
|
8
8
|
|
|
9
9
|
%i(get).each do |http_method|
|
|
10
10
|
context ".#{http_method}" do
|
|
11
|
-
it {expect(@instance).to respond_to(http_method.to_sym)}
|
|
11
|
+
it { expect(@instance).to respond_to(http_method.to_sym) }
|
|
12
12
|
it "should call send http #{http_method} method to path defined through HTTParty" do
|
|
13
|
-
allow(DummyClassForProxy).to receive(http_method).with(
|
|
14
|
-
expect(DummyClassForProxy).to receive(http_method).with(
|
|
15
|
-
|
|
13
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', query: {})
|
|
14
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', query: {})
|
|
15
|
+
.and_return(StubResponse.new({}, true, 200))
|
|
16
|
+
expect { @instance.send(http_method, '/test') }.not_to raise_error
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
it
|
|
19
|
-
allow(DummyClassForProxy).to receive(http_method).with(
|
|
20
|
-
|
|
21
|
-
expect
|
|
19
|
+
it 'should not raise exception if data returned not in json format (should be fixed in v2)' do
|
|
20
|
+
allow(DummyClassForProxy).to receive(http_method).with('/test', query: {})
|
|
21
|
+
.and_return(StubResponse.new('Some random text here', true, 200))
|
|
22
|
+
expect { @instance.send(http_method, '/test') }.not_to raise_error
|
|
23
|
+
expect(@instance.send(http_method, '/test')).to eql('Some random text here')
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
it "should raise Auth0::Unauthorized on send http #{http_method}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
expect
|
|
26
|
+
it "should raise Auth0::Unauthorized on send http #{http_method}
|
|
27
|
+
method to path defined through HTTParty when 401 status received" do
|
|
28
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', query: {})
|
|
29
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', query: {})
|
|
30
|
+
.and_return(StubResponse.new({}, false, 401))
|
|
31
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unauthorized)
|
|
28
32
|
end
|
|
29
33
|
|
|
30
|
-
it "should raise Auth0::NotFound on send http #{http_method} method
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
expect
|
|
34
|
+
it "should raise Auth0::NotFound on send http #{http_method} method
|
|
35
|
+
to path defined through HTTParty when 404 status received" do
|
|
36
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', query: {})
|
|
37
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', query: {})
|
|
38
|
+
.and_return(StubResponse.new({}, false, 404))
|
|
39
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::NotFound)
|
|
34
40
|
end
|
|
35
41
|
|
|
36
|
-
it "should raise Auth0::Unsupported on send http #{http_method} method
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
expect
|
|
42
|
+
it "should raise Auth0::Unsupported on send http #{http_method} method
|
|
43
|
+
to path defined through HTTParty when 418 or other unknown status received" do
|
|
44
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', query: {})
|
|
45
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', query: {})
|
|
46
|
+
.and_return(StubResponse.new({}, false, 418))
|
|
47
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unsupported)
|
|
40
48
|
end
|
|
41
49
|
|
|
42
|
-
it "should raise Auth0::BadRequest on send http #{http_method} method
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
expect
|
|
50
|
+
it "should raise Auth0::BadRequest on send http #{http_method} method
|
|
51
|
+
to path defined through HTTParty when 400 or other unknown status received" do
|
|
52
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', query: {})
|
|
53
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', query: {})
|
|
54
|
+
.and_return(StubResponse.new({}, false, 400))
|
|
55
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(
|
|
56
|
+
Auth0::BadRequest)
|
|
46
57
|
end
|
|
47
58
|
|
|
48
|
-
it "should raise Auth0::AccessDenied on send http #{http_method} method
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
expect
|
|
59
|
+
it "should raise Auth0::AccessDenied on send http #{http_method} method
|
|
60
|
+
to path defined through HTTParty when 403" do
|
|
61
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', query: {})
|
|
62
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', query: {})
|
|
63
|
+
.and_return(StubResponse.new({}, false, 403))
|
|
64
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::AccessDenied)
|
|
52
65
|
end
|
|
53
|
-
it "should raise Auth0::ServerError on send http #{http_method} method
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
expect
|
|
66
|
+
it "should raise Auth0::ServerError on send http #{http_method} method
|
|
67
|
+
to path defined through HTTParty when 500 received" do
|
|
68
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', query: {})
|
|
69
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', query: {})
|
|
70
|
+
.and_return(StubResponse.new({}, false, 500))
|
|
71
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::ServerError)
|
|
57
72
|
end
|
|
58
73
|
|
|
59
|
-
it
|
|
60
|
-
allow(DummyClassForProxy).to receive(http_method).with(
|
|
61
|
-
expect(DummyClassForProxy).to receive(http_method).with(
|
|
62
|
-
|
|
74
|
+
it 'should escape path with URI.escape' do
|
|
75
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/te%20st', query: {})
|
|
76
|
+
expect(DummyClassForProxy).to receive(http_method).with('/te%20st', query: {})
|
|
77
|
+
.and_return(StubResponse.new({}, true, 200))
|
|
78
|
+
expect { @instance.send(http_method, '/te st') }.not_to raise_error
|
|
63
79
|
end
|
|
64
80
|
end
|
|
65
81
|
end
|
|
66
82
|
|
|
67
83
|
%i(post put patch delete).each do |http_method|
|
|
68
84
|
context ".#{http_method}" do
|
|
69
|
-
it {expect(@instance).to respond_to(http_method.to_sym)}
|
|
85
|
+
it { expect(@instance).to respond_to(http_method.to_sym) }
|
|
70
86
|
it "should call send http #{http_method} method to path defined through HTTParty" do
|
|
71
|
-
allow(DummyClassForProxy).to receive(http_method).with(
|
|
72
|
-
expect(DummyClassForProxy).to receive(http_method).with(
|
|
73
|
-
|
|
87
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', body: '{}')
|
|
88
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', body: '{}')
|
|
89
|
+
.and_return(StubResponse.new('{}', true, 200))
|
|
90
|
+
expect { @instance.send(http_method, '/test') }.not_to raise_error
|
|
74
91
|
end
|
|
75
92
|
|
|
76
|
-
it
|
|
77
|
-
allow(DummyClassForProxy).to receive(http_method).with(
|
|
78
|
-
|
|
79
|
-
expect
|
|
93
|
+
it 'should not raise exception if data returned not in json format (should be fixed in v2)' do
|
|
94
|
+
allow(DummyClassForProxy).to receive(http_method).with('/test', body: '{}')
|
|
95
|
+
.and_return(StubResponse.new('Some random text here', true, 200))
|
|
96
|
+
expect { @instance.send(http_method, '/test') }.not_to raise_error
|
|
97
|
+
expect(@instance.send(http_method, '/test')).to eql('Some random text here')
|
|
80
98
|
end
|
|
81
99
|
|
|
82
|
-
it "should raise Auth0::Unauthorized on send http #{http_method} method
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
expect
|
|
100
|
+
it "should raise Auth0::Unauthorized on send http #{http_method} method
|
|
101
|
+
to path defined through HTTParty when 401 status received" do
|
|
102
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', body: '{}')
|
|
103
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', body: '{}')
|
|
104
|
+
.and_return(StubResponse.new('{}', false, 401))
|
|
105
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unauthorized)
|
|
86
106
|
end
|
|
87
107
|
|
|
88
|
-
it "should raise Auth0::NotFound on send http #{http_method} method
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
expect
|
|
108
|
+
it "should raise Auth0::NotFound on send http #{http_method} method
|
|
109
|
+
to path defined through HTTParty when 404 status received" do
|
|
110
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', body: '{}')
|
|
111
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', body: '{}')
|
|
112
|
+
.and_return(StubResponse.new('{}', false, 404))
|
|
113
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::NotFound)
|
|
92
114
|
end
|
|
93
115
|
|
|
94
|
-
it "should raise Auth0::Unsupported on send http #{http_method} method
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
expect
|
|
116
|
+
it "should raise Auth0::Unsupported on send http #{http_method} method
|
|
117
|
+
to path defined through HTTParty when 418 or other unknown status received" do
|
|
118
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', body: '{}')
|
|
119
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', body: '{}')
|
|
120
|
+
.and_return(StubResponse.new('{}', false, 418))
|
|
121
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unsupported)
|
|
98
122
|
end
|
|
99
123
|
|
|
100
|
-
it "should raise Auth0::BadRequest on send http #{http_method} method
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
expect
|
|
124
|
+
it "should raise Auth0::BadRequest on send http #{http_method} method
|
|
125
|
+
to path defined through HTTParty when 400 or other unknown status received" do
|
|
126
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', body: '{}')
|
|
127
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', body: '{}')
|
|
128
|
+
.and_return(StubResponse.new('{}', false, 400))
|
|
129
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::BadRequest)
|
|
104
130
|
end
|
|
105
131
|
|
|
106
|
-
it "should raise Auth0::ServerError on send http #{http_method} method
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
expect
|
|
132
|
+
it "should raise Auth0::ServerError on send http #{http_method} method
|
|
133
|
+
to path defined through HTTParty when 500 received" do
|
|
134
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/test', body: '{}')
|
|
135
|
+
expect(DummyClassForProxy).to receive(http_method).with('/test', body: '{}')
|
|
136
|
+
.and_return(StubResponse.new('{}', false, 500))
|
|
137
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::ServerError)
|
|
110
138
|
end
|
|
111
139
|
|
|
112
|
-
it
|
|
113
|
-
allow(DummyClassForProxy).to receive(http_method).with(
|
|
114
|
-
expect(DummyClassForProxy).to receive(http_method).with(
|
|
115
|
-
|
|
140
|
+
it 'should escape path with URI.escape' do
|
|
141
|
+
allow(DummyClassForProxy).to receive(http_method).with('http://login.auth0.com/te%20st', body: '{}')
|
|
142
|
+
expect(DummyClassForProxy).to receive(http_method).with('/te%20st', body: '{}')
|
|
143
|
+
.and_return(StubResponse.new('{}', true, 200))
|
|
144
|
+
expect { @instance.send(http_method, '/te st') }.not_to raise_error
|
|
116
145
|
end
|
|
117
146
|
end
|
|
118
147
|
end
|