auth0 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +2 -1
- data/.rubocop_todo.yml +0 -2
- data/.travis.yml +4 -2
- data/CHANGELOG.md +40 -38
- data/DEPLOYMENT.md +5 -0
- data/Gemfile +1 -1
- data/README.md +20 -2
- data/Rakefile +1 -1
- data/auth0.gemspec +4 -3
- data/doc_config/templates/default/layout/html/footer.erb +1 -1
- data/examples/ruby-api/.gitignore +86 -0
- data/examples/ruby-api/Gemfile +8 -0
- data/examples/ruby-api/README.md +24 -0
- data/examples/ruby-api/config.ru +2 -0
- data/examples/ruby-api/main.rb +33 -0
- data/examples/ruby-on-rails-api/.gitignore +18 -0
- data/examples/ruby-on-rails-api/Gemfile +48 -0
- data/examples/ruby-on-rails-api/README.md +27 -0
- data/examples/ruby-on-rails-api/Rakefile +6 -0
- data/examples/ruby-on-rails-api/app/assets/images/.keep +0 -0
- data/examples/ruby-on-rails-api/app/assets/javascripts/application.js +16 -0
- data/examples/ruby-on-rails-api/app/assets/stylesheets/application.css +15 -0
- data/examples/ruby-on-rails-api/app/controllers/application_controller.rb +8 -0
- data/examples/ruby-on-rails-api/app/controllers/concerns/.keep +0 -0
- data/examples/ruby-on-rails-api/app/controllers/ping_controller.rb +6 -0
- data/examples/ruby-on-rails-api/app/controllers/secured_ping_controller.rb +11 -0
- data/examples/ruby-on-rails-api/app/helpers/application_helper.rb +3 -0
- data/examples/ruby-on-rails-api/app/mailers/.keep +0 -0
- data/examples/ruby-on-rails-api/app/models/.keep +0 -0
- data/examples/ruby-on-rails-api/app/models/concerns/.keep +0 -0
- data/examples/ruby-on-rails-api/app/views/layouts/application.html.erb +14 -0
- data/examples/ruby-on-rails-api/bin/bundle +3 -0
- data/examples/ruby-on-rails-api/bin/rails +4 -0
- data/examples/ruby-on-rails-api/bin/rake +4 -0
- data/examples/ruby-on-rails-api/bin/setup +29 -0
- data/examples/ruby-on-rails-api/config.ru +4 -0
- data/examples/ruby-on-rails-api/config/application.rb +23 -0
- data/examples/ruby-on-rails-api/config/boot.rb +4 -0
- data/examples/ruby-on-rails-api/config/database.yml +27 -0
- data/examples/ruby-on-rails-api/config/environment.rb +5 -0
- data/examples/ruby-on-rails-api/config/environments/development.rb +37 -0
- data/examples/ruby-on-rails-api/config/environments/production.rb +83 -0
- data/examples/ruby-on-rails-api/config/environments/test.rb +41 -0
- data/examples/ruby-on-rails-api/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/ruby-on-rails-api/config/initializers/cookies_serializer.rb +3 -0
- data/examples/ruby-on-rails-api/config/initializers/dotenv.rb +4 -0
- data/examples/ruby-on-rails-api/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/ruby-on-rails-api/config/initializers/inflections.rb +16 -0
- data/examples/ruby-on-rails-api/config/initializers/knock.rb +53 -0
- data/examples/ruby-on-rails-api/config/initializers/mime_types.rb +4 -0
- data/examples/ruby-on-rails-api/config/initializers/session_store.rb +3 -0
- data/examples/ruby-on-rails-api/config/initializers/wrap_parameters.rb +14 -0
- data/examples/ruby-on-rails-api/config/locales/en.yml +23 -0
- data/examples/ruby-on-rails-api/config/routes.rb +58 -0
- data/examples/ruby-on-rails-api/config/secrets.yml +28 -0
- data/examples/ruby-on-rails-api/db/schema.rb +15 -0
- data/examples/ruby-on-rails-api/db/seeds.rb +7 -0
- data/examples/ruby-on-rails-api/lib/assets/.keep +0 -0
- data/examples/ruby-on-rails-api/lib/tasks/.keep +0 -0
- data/examples/ruby-on-rails-api/log/.keep +0 -0
- data/examples/ruby-on-rails-api/public/404.html +67 -0
- data/examples/ruby-on-rails-api/public/422.html +67 -0
- data/examples/ruby-on-rails-api/public/500.html +66 -0
- data/examples/ruby-on-rails-api/public/favicon.ico +0 -0
- data/examples/ruby-on-rails-api/public/robots.txt +5 -0
- data/examples/ruby-on-rails-api/test/controllers/.keep +0 -0
- data/examples/ruby-on-rails-api/test/fixtures/.keep +0 -0
- data/examples/ruby-on-rails-api/test/helpers/.keep +0 -0
- data/examples/ruby-on-rails-api/test/integration/.keep +0 -0
- data/examples/ruby-on-rails-api/test/mailers/.keep +0 -0
- data/examples/ruby-on-rails-api/test/models/.keep +0 -0
- data/examples/ruby-on-rails-api/test/ping_controller_test.rb +8 -0
- data/examples/ruby-on-rails-api/test/secured_ping_controller_test.rb +26 -0
- data/examples/ruby-on-rails-api/test/test_helper.rb +16 -0
- data/lib/auth0/api/authentication_endpoints.rb +59 -30
- data/lib/auth0/api/v1/clients.rb +1 -1
- data/lib/auth0/api/v1/connections.rb +4 -3
- data/lib/auth0/api/v1/logs.rb +1 -1
- data/lib/auth0/api/v1/rules.rb +1 -1
- data/lib/auth0/api/v1/users.rb +5 -5
- data/lib/auth0/api/v2.rb +10 -0
- data/lib/auth0/api/v2/blacklists.rb +1 -1
- data/lib/auth0/api/v2/client_grants.rb +57 -0
- data/lib/auth0/api/v2/clients.rb +14 -14
- data/lib/auth0/api/v2/connections.rb +19 -20
- data/lib/auth0/api/v2/device_credentials.rb +76 -0
- data/lib/auth0/api/v2/emails.rb +5 -7
- data/lib/auth0/api/v2/jobs.rb +15 -12
- data/lib/auth0/api/v2/logs.rb +65 -0
- data/lib/auth0/api/v2/resource_servers.rb +61 -0
- data/lib/auth0/api/v2/rules.rb +21 -20
- data/lib/auth0/api/v2/stats.rb +2 -2
- data/lib/auth0/api/v2/tenants.rb +6 -4
- data/lib/auth0/api/v2/tickets.rb +13 -14
- data/lib/auth0/api/v2/user_blocks.rb +62 -0
- data/lib/auth0/api/v2/users.rb +63 -32
- data/lib/auth0/client.rb +0 -2
- data/lib/auth0/mixins.rb +4 -3
- data/lib/auth0/mixins/httpproxy.rb +55 -0
- data/lib/auth0/mixins/initializer.rb +27 -10
- data/lib/auth0/version.rb +1 -1
- data/spec/integration/lib/auth0/api/api_authentication_spec.rb +118 -0
- data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +1 -1
- data/spec/integration/lib/auth0/api/v2/api_client_grants_spec.rb +53 -0
- data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +5 -2
- data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +8 -5
- data/spec/integration/lib/auth0/api/v2/api_device_credentials_spec.rb +67 -0
- data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +15 -8
- data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +11 -9
- data/spec/integration/lib/auth0/api/v2/api_logs_spec.rb +69 -0
- data/spec/integration/lib/auth0/api/v2/api_resource_servers_spec.rb +47 -0
- data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +2 -1
- data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +2 -2
- data/spec/integration/lib/auth0/api/v2/api_user_blocks_spec.rb +73 -0
- data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +32 -5
- data/spec/integration/lib/auth0/auth0_client_spec.rb +14 -11
- data/spec/lib/auth0/api/authentication_endpoints_spec.rb +116 -56
- data/spec/lib/auth0/api/v1/connections_spec.rb +2 -4
- data/spec/lib/auth0/api/v1/rules_spec.rb +2 -1
- data/spec/lib/auth0/api/v1/users_spec.rb +17 -9
- data/spec/lib/auth0/api/v2/client_grants_spec.rb +44 -0
- data/spec/lib/auth0/api/v2/connections_spec.rb +2 -1
- data/spec/lib/auth0/api/v2/device_credentials_spec.rb +73 -0
- data/spec/lib/auth0/api/v2/jobs_spec.rb +3 -2
- data/spec/lib/auth0/api/v2/logs_spec.rb +48 -0
- data/spec/lib/auth0/api/v2/resource_servers_spec.rb +63 -0
- data/spec/lib/auth0/api/v2/rules_spec.rb +8 -4
- data/spec/lib/auth0/api/v2/tenants_spec.rb +2 -1
- data/spec/lib/auth0/api/v2/tickets_spec.rb +4 -7
- data/spec/lib/auth0/api/v2/user_blocks_spec.rb +52 -0
- data/spec/lib/auth0/api/v2/users_spec.rb +39 -6
- data/spec/lib/auth0/client_spec.rb +8 -5
- data/spec/lib/auth0/mixins/httpproxy_spec.rb +225 -0
- data/spec/lib/auth0/mixins/initializer_spec.rb +1 -1
- data/spec/spec_helper_full.rb +12 -3
- data/spec/spec_helper_unit.rb +2 -2
- data/spec/support/credentials.rb +6 -4
- data/spec/support/dummy_class.rb +2 -1
- data/spec/support/dummy_class_for_proxy.rb +2 -2
- data/spec/support/dummy_class_for_restclient.rb +2 -0
- metadata +117 -9
- data/lib/auth0/mixins/httparty_proxy.rb +0 -38
- data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +0 -148
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Auth0::Api::V2::UserBlocks do
|
3
|
+
before :all do
|
4
|
+
dummy_instance = DummyClass.new
|
5
|
+
dummy_instance.extend(Auth0::Api::V2::UserBlocks)
|
6
|
+
@instance = dummy_instance
|
7
|
+
end
|
8
|
+
|
9
|
+
context '.user_blocks' do
|
10
|
+
it { expect(@instance).to respond_to(:user_blocks) }
|
11
|
+
it 'is expected to call /api/v2/user-blocks?identifier=Test' do
|
12
|
+
expect(@instance).to receive(:get).with('/api/v2/user-blocks', identifier: 'Test')
|
13
|
+
expect { @instance.user_blocks('Test') }.not_to raise_error
|
14
|
+
end
|
15
|
+
it 'expect client to raise an error when calling with empty identifier' do
|
16
|
+
expect { @instance.user_blocks(nil) }.to raise_error('Must specify a valid identifier')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '.delete_user_blocks' do
|
21
|
+
it { expect(@instance).to respond_to(:delete_user_blocks) }
|
22
|
+
it 'is expected to call /api/v2/user-blocks?identifier=Test' do
|
23
|
+
expect(@instance).to receive(:delete).with('/api/v2/user-blocks', identifier: 'Test')
|
24
|
+
expect { @instance.delete_user_blocks('Test') }.not_to raise_error
|
25
|
+
end
|
26
|
+
it 'expect client to raise an error when calling with empty identifier' do
|
27
|
+
expect { @instance.delete_user_blocks(nil) }.to raise_error('Must specify a valid identifier')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '.user_blocks_by_id' do
|
32
|
+
it { expect(@instance).to respond_to(:user_blocks_by_id) }
|
33
|
+
it 'is expected to call /api/v2/user-blocks/Test' do
|
34
|
+
expect(@instance).to receive(:get).with('/api/v2/user-blocks/Test')
|
35
|
+
expect { @instance.user_blocks_by_id('Test') }.not_to raise_error
|
36
|
+
end
|
37
|
+
it 'expect client to raise an error when calling with empty identifier' do
|
38
|
+
expect { @instance.user_blocks_by_id(nil) }.to raise_error('Must specify a valid identifier')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context '.delete_user_blocks_by_id' do
|
43
|
+
it { expect(@instance).to respond_to(:delete_user_blocks_by_id) }
|
44
|
+
it 'is expected to call /api/v2/user-blocks/Test' do
|
45
|
+
expect(@instance).to receive(:delete).with('/api/v2/user-blocks/Test')
|
46
|
+
expect { @instance.delete_user_blocks_by_id('Test') }.not_to raise_error
|
47
|
+
end
|
48
|
+
it 'expect client to raise an error when calling with empty identifier' do
|
49
|
+
expect { @instance.delete_user_blocks_by_id(nil) }.to raise_error('Must specify a valid identifier')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -19,7 +19,8 @@ describe Auth0::Api::V2::Users do
|
|
19
19
|
connection: nil,
|
20
20
|
fields: nil,
|
21
21
|
include_fields: nil,
|
22
|
-
q: nil
|
22
|
+
q: nil
|
23
|
+
)
|
23
24
|
expect { @instance.users }.not_to raise_error
|
24
25
|
end
|
25
26
|
end
|
@@ -41,12 +42,14 @@ describe Auth0::Api::V2::Users do
|
|
41
42
|
email: 'test@test.com',
|
42
43
|
password: 'password',
|
43
44
|
connection: 'conn',
|
44
|
-
name: 'name'
|
45
|
+
name: 'name'
|
46
|
+
)
|
45
47
|
@instance.create_user(
|
46
48
|
'name',
|
47
49
|
email: 'test@test.com',
|
48
50
|
password: 'password',
|
49
|
-
connection: 'conn'
|
51
|
+
connection: 'conn'
|
52
|
+
)
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
@@ -68,7 +71,8 @@ describe Auth0::Api::V2::Users do
|
|
68
71
|
it 'is expected not to call delete to /api/v2/users if user_id is blank' do
|
69
72
|
expect(@instance).not_to receive(:delete)
|
70
73
|
expect { @instance.delete_user('') }.to raise_exception(
|
71
|
-
Auth0::MissingUserId
|
74
|
+
Auth0::MissingUserId
|
75
|
+
)
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
@@ -88,13 +92,15 @@ describe Auth0::Api::V2::Users do
|
|
88
92
|
email: 'test@test.com',
|
89
93
|
password: 'password',
|
90
94
|
connection: 'conn',
|
91
|
-
name: 'name'
|
95
|
+
name: 'name'
|
96
|
+
)
|
92
97
|
@instance.patch_user(
|
93
98
|
'UserID',
|
94
99
|
email: 'test@test.com',
|
95
100
|
password: 'password',
|
96
101
|
connection: 'conn',
|
97
|
-
name: 'name'
|
102
|
+
name: 'name'
|
103
|
+
)
|
98
104
|
end
|
99
105
|
it { expect { @instance.patch_user('', 'body') }.to raise_error 'Must supply a valid user_id' }
|
100
106
|
it { expect { @instance.patch_user('UserId', '') }.to raise_error 'Must supply a valid body' }
|
@@ -131,4 +137,31 @@ describe Auth0::Api::V2::Users do
|
|
131
137
|
end
|
132
138
|
it { expect { @instance.delete_user_provider(nil, 'test') }.to raise_error 'Must supply a valid user_id' }
|
133
139
|
end
|
140
|
+
|
141
|
+
context '.user_logs' do
|
142
|
+
it { expect(@instance).to respond_to(:user_logs) }
|
143
|
+
it { expect(@instance).to respond_to(:get_user_log_events) }
|
144
|
+
it 'is expected to call /api/v2/USER_ID/logs' do
|
145
|
+
expect(@instance).to receive(:get).with(
|
146
|
+
'/api/v2/users/USER_ID/logs',
|
147
|
+
user_id: 'USER_ID',
|
148
|
+
per_page: nil,
|
149
|
+
page: nil,
|
150
|
+
include_totals: nil,
|
151
|
+
sort: nil
|
152
|
+
)
|
153
|
+
expect { @instance.user_logs('USER_ID') }.not_to raise_error
|
154
|
+
end
|
155
|
+
it { expect { @instance.user_logs('') }.to raise_error 'Must supply a valid user_id' }
|
156
|
+
it 'is expected to raise an error when per_page is higher than 100' do
|
157
|
+
expect { @instance.user_logs('USER_ID', per_page: rand(101..2000)) }.to raise_error(
|
158
|
+
'The total amount of entries per page should be less than 100'
|
159
|
+
)
|
160
|
+
end
|
161
|
+
it 'is expected to raise an error when sort does not match pattern' do
|
162
|
+
expect { @instance.user_logs('USER_ID', sort: 'no match') }.to raise_error(
|
163
|
+
'Sort does not match pattern ^(([a-zA-Z0-9_\\.]+))\\:(1|-1)$'
|
164
|
+
)
|
165
|
+
end
|
166
|
+
end
|
134
167
|
end
|
@@ -48,7 +48,8 @@ describe Auth0::Client do
|
|
48
48
|
|
49
49
|
context 'with namespace' do
|
50
50
|
let(:subject) do
|
51
|
-
Auth0::Client.new(
|
51
|
+
Auth0::Client.new(protocols: 'v1', client_id: 'client_id', client_secret: 'client_secret',
|
52
|
+
namespace: 'samples.auth0.com')
|
52
53
|
end
|
53
54
|
|
54
55
|
it_should_behave_like 'v1 API client'
|
@@ -57,7 +58,8 @@ describe Auth0::Client do
|
|
57
58
|
|
58
59
|
context 'with domain' do
|
59
60
|
let(:subject) do
|
60
|
-
Auth0::Client.new(
|
61
|
+
Auth0::Client.new(protocols: 'v1', client_id: 'client_id', client_secret: 'client_secret',
|
62
|
+
domain: 'samples.auth0.com')
|
61
63
|
end
|
62
64
|
|
63
65
|
it_should_behave_like 'v1 API client'
|
@@ -70,7 +72,8 @@ describe Auth0::Client do
|
|
70
72
|
client_id: 'client_id',
|
71
73
|
client_secret: 'client_secret',
|
72
74
|
domain: 'samples.auth0.com',
|
73
|
-
api_version: 1
|
75
|
+
api_version: 1
|
76
|
+
)
|
74
77
|
end
|
75
78
|
it_should_behave_like 'v1 API client'
|
76
79
|
it_should_behave_like 'authentication API client'
|
@@ -83,13 +86,13 @@ describe Auth0::Client do
|
|
83
86
|
end
|
84
87
|
|
85
88
|
context 'with namespace' do
|
86
|
-
let(:subject) { Auth0::Client.new(
|
89
|
+
let(:subject) { Auth0::Client.new(access_token: 'access_token', namespace: 'samples.auth0.com') }
|
87
90
|
it_should_behave_like 'v2 API client'
|
88
91
|
it_should_behave_like 'authentication API client'
|
89
92
|
end
|
90
93
|
|
91
94
|
context 'with domain' do
|
92
|
-
let(:subject) { Auth0::Client.new(
|
95
|
+
let(:subject) { Auth0::Client.new(access_token: 'access_token', domain: 'samples.auth0.com') }
|
93
96
|
it_should_behave_like 'v2 API client'
|
94
97
|
it_should_behave_like 'authentication API client'
|
95
98
|
end
|
@@ -0,0 +1,225 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Auth0::Mixins::HTTPProxy do
|
5
|
+
before :each do
|
6
|
+
dummy_instance = DummyClassForProxy.new
|
7
|
+
dummy_instance.extend(Auth0::Mixins::HTTPProxy)
|
8
|
+
@instance = dummy_instance
|
9
|
+
@exception = DummyClassForRestClient.new
|
10
|
+
end
|
11
|
+
|
12
|
+
%i(get delete).each do |http_method|
|
13
|
+
context ".#{http_method}" do
|
14
|
+
it { expect(@instance).to respond_to(http_method.to_sym) }
|
15
|
+
it "should call send http #{http_method} method to path defined through HTTP" do
|
16
|
+
expect(RestClient::Request).to receive(:execute).with(method: http_method,
|
17
|
+
url: '/test',
|
18
|
+
timeout: nil,
|
19
|
+
headers: { params: {} },
|
20
|
+
payload: nil)
|
21
|
+
.and_return(StubResponse.new({}, true, 200))
|
22
|
+
expect { @instance.send(http_method, '/test') }.not_to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should not raise exception if data returned not in json format (should be fixed in v2)' do
|
26
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method,
|
27
|
+
url: '/test',
|
28
|
+
timeout: nil,
|
29
|
+
headers: { params: {} },
|
30
|
+
payload: nil)
|
31
|
+
.and_return(StubResponse.new('Some random text here', true, 200))
|
32
|
+
expect { @instance.send(http_method, '/test') }.not_to raise_error
|
33
|
+
expect(@instance.send(http_method, '/test')).to eql('Some random text here')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should raise Auth0::Unauthorized on send http #{http_method}
|
37
|
+
method to path defined through HTTP when 401 status received" do
|
38
|
+
expect(RestClient::Request).to receive(:execute).with(method: http_method,
|
39
|
+
url: '/test',
|
40
|
+
timeout: nil,
|
41
|
+
headers: { params: {} },
|
42
|
+
payload: nil)
|
43
|
+
.and_return(StubResponse.new({}, false, 401))
|
44
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unauthorized)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should raise Auth0::NotFound on send http #{http_method} method
|
48
|
+
to path defined through HTTP when 404 status received" do
|
49
|
+
expect(RestClient::Request).to receive(:execute).with(method: http_method,
|
50
|
+
url: '/test',
|
51
|
+
timeout: nil,
|
52
|
+
headers: { params: {} },
|
53
|
+
payload: nil)
|
54
|
+
.and_return(StubResponse.new({}, false, 404))
|
55
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::NotFound)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should raise Auth0::Unsupported on send http #{http_method} method
|
59
|
+
to path defined through HTTP when 418 or other unknown status received" do
|
60
|
+
expect(RestClient::Request).to receive(:execute).with(method: http_method,
|
61
|
+
url: '/test',
|
62
|
+
timeout: nil,
|
63
|
+
headers: { params: {} },
|
64
|
+
payload: nil)
|
65
|
+
.and_return(StubResponse.new({}, false, 418))
|
66
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unsupported)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should raise Auth0::BadRequest on send http #{http_method} method
|
70
|
+
to path defined through HTTP when 400 or other unknown status received" do
|
71
|
+
@exception.response = StubResponse.new({}, false, 400)
|
72
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method,
|
73
|
+
url: '/test',
|
74
|
+
timeout: nil,
|
75
|
+
headers: { params: {} },
|
76
|
+
payload: nil)
|
77
|
+
.and_raise(@exception)
|
78
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::BadRequest)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should raise Auth0::AccessDenied on send http #{http_method} method
|
82
|
+
to path defined through HTTP when 403" do
|
83
|
+
@exception.response = StubResponse.new({}, false, 403)
|
84
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method,
|
85
|
+
url: '/test',
|
86
|
+
timeout: nil,
|
87
|
+
headers: { params: {} },
|
88
|
+
payload: nil)
|
89
|
+
.and_raise(@exception)
|
90
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::AccessDenied)
|
91
|
+
end
|
92
|
+
it "should raise Auth0::ServerError on send http #{http_method} method
|
93
|
+
to path defined through HTTP when 500 received" do
|
94
|
+
@exception.response = StubResponse.new({}, false, 500)
|
95
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method,
|
96
|
+
url: '/test',
|
97
|
+
timeout: nil,
|
98
|
+
headers: { params: {} },
|
99
|
+
payload: nil)
|
100
|
+
.and_raise(@exception)
|
101
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::ServerError)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should escape path with URI.escape' do
|
105
|
+
expect(RestClient::Request).to receive(:execute).with(method: http_method,
|
106
|
+
url: '/te%20st',
|
107
|
+
timeout: nil,
|
108
|
+
headers: { params: {} },
|
109
|
+
payload: nil)
|
110
|
+
.and_return(StubResponse.new({}, true, 200))
|
111
|
+
expect { @instance.send(http_method, '/te st') }.not_to raise_error
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
%i(post put patch).each do |http_method|
|
117
|
+
context ".#{http_method}" do
|
118
|
+
it { expect(@instance).to respond_to(http_method.to_sym) }
|
119
|
+
it "should call send http #{http_method} method to path defined through HTTP" do
|
120
|
+
expect(RestClient::Request).to receive(:execute).with(method: http_method,
|
121
|
+
url: '/test',
|
122
|
+
timeout: nil,
|
123
|
+
headers: nil,
|
124
|
+
payload: '{}')
|
125
|
+
.and_return(StubResponse.new({}, true, 200))
|
126
|
+
expect { @instance.send(http_method, '/test') }.not_to raise_error
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should not raise exception if data returned not in json format (should be fixed in v2)' do
|
130
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method,
|
131
|
+
url: '/test',
|
132
|
+
timeout: nil,
|
133
|
+
headers: nil,
|
134
|
+
payload: '{}')
|
135
|
+
.and_return(StubResponse.new('Some random text here', true, 200))
|
136
|
+
expect { @instance.send(http_method, '/test') }.not_to raise_error
|
137
|
+
expect(@instance.send(http_method, '/test')).to eql('Some random text here')
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should raise Auth0::Unauthorized on send http #{http_method} method
|
141
|
+
to path defined through HTTP when 401 status received" do
|
142
|
+
@exception.response = StubResponse.new({}, false, 401)
|
143
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method,
|
144
|
+
url: '/test',
|
145
|
+
timeout: nil,
|
146
|
+
headers: nil,
|
147
|
+
payload: '{}')
|
148
|
+
.and_raise(@exception)
|
149
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unauthorized)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should raise Auth0::NotFound on send http #{http_method} method
|
153
|
+
to path defined through HTTP when 404 status received" do
|
154
|
+
@exception.response = StubResponse.new({}, false, 404)
|
155
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method,
|
156
|
+
url: '/test',
|
157
|
+
timeout: nil,
|
158
|
+
headers: nil,
|
159
|
+
payload: '{}')
|
160
|
+
.and_raise(@exception)
|
161
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::NotFound)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should raise Auth0::Unsupported on send http #{http_method} method
|
165
|
+
to path defined through HTTP when 418 or other unknown status received" do
|
166
|
+
@exception.response = StubResponse.new({}, false, 418)
|
167
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method,
|
168
|
+
url: '/test',
|
169
|
+
timeout: nil,
|
170
|
+
headers: nil,
|
171
|
+
payload: '{}')
|
172
|
+
.and_raise(@exception)
|
173
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::Unsupported)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should raise Auth0::BadRequest on send http #{http_method} method
|
177
|
+
to path defined through HTTP when 400 or other unknown status received" do
|
178
|
+
@exception.response = StubResponse.new({}, false, 400)
|
179
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method,
|
180
|
+
url: '/test',
|
181
|
+
timeout: nil,
|
182
|
+
headers: nil,
|
183
|
+
payload: '{}')
|
184
|
+
.and_raise(@exception)
|
185
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::BadRequest)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should raise Auth0::ServerError on send http #{http_method} method
|
189
|
+
to path defined through HTTP when 500 received" do
|
190
|
+
@exception.response = StubResponse.new({}, false, 500)
|
191
|
+
allow(RestClient::Request).to receive(:execute).with(method: http_method, url: '/test',
|
192
|
+
timeout: nil,
|
193
|
+
headers: nil,
|
194
|
+
payload: '{}')
|
195
|
+
.and_raise(@exception)
|
196
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::ServerError)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should escape path with URI.escape' do
|
200
|
+
expect(RestClient::Request).to receive(:execute).with(method: http_method,
|
201
|
+
url: '/te%20st',
|
202
|
+
timeout: nil,
|
203
|
+
headers: nil,
|
204
|
+
payload: '{}')
|
205
|
+
.and_return(StubResponse.new({}, true, 200))
|
206
|
+
expect { @instance.send(http_method, '/te st') }.not_to raise_error
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should give the JSON representation of the error as the error message' do
|
210
|
+
res = JSON.generate('statusCode' => 404,
|
211
|
+
'error' => 'Bad Request',
|
212
|
+
'message' => "Path validation error: 'String does not match pattern ^.+\\|.+$:
|
213
|
+
3241312' on property id (The user_id of the user to retrieve).",
|
214
|
+
'errorCode' => 'invalid_uri')
|
215
|
+
expect(RestClient::Request).to receive(:execute).with(method: http_method,
|
216
|
+
url: '/test',
|
217
|
+
timeout: nil,
|
218
|
+
headers: nil,
|
219
|
+
payload: '{}')
|
220
|
+
.and_return(StubResponse.new(res, true, 404))
|
221
|
+
expect { @instance.send(http_method, '/test') }.to raise_error(Auth0::NotFound, res)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
data/spec/spec_helper_full.rb
CHANGED
@@ -16,8 +16,8 @@ require 'faker'
|
|
16
16
|
require 'auth0'
|
17
17
|
require 'pry'
|
18
18
|
|
19
|
-
Dir[
|
20
|
-
Dir[
|
19
|
+
Dir['./lib/**/*.rb'].each { |f| require f }
|
20
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
21
21
|
|
22
22
|
def entity_suffix
|
23
23
|
(ENV['TRAVIS_JOB_ID'] || 'local').delete('_')
|
@@ -33,7 +33,8 @@ RSpec.configure do |config|
|
|
33
33
|
config.after(:suite) do
|
34
34
|
puts "Cleaning up for #{entity_suffix}"
|
35
35
|
v2_client = Auth0Client.new(
|
36
|
-
token: ENV['MASTER_JWT'], api_version: 2, domain: ENV['DOMAIN']
|
36
|
+
token: ENV['MASTER_JWT'], api_version: 2, domain: ENV['DOMAIN']
|
37
|
+
)
|
37
38
|
v2_client
|
38
39
|
.clients
|
39
40
|
.select { |client| client['name'] != 'DefaultApp' && !client['global'] && client['name'].include?(entity_suffix) }
|
@@ -45,3 +46,11 @@ RSpec.configure do |config|
|
|
45
46
|
puts "Finished cleaning up for #{entity_suffix}"
|
46
47
|
end
|
47
48
|
end
|
49
|
+
|
50
|
+
def wait(time, increment = 5, elapsed_time = 0, &block)
|
51
|
+
yield
|
52
|
+
rescue RSpec::Expectations::ExpectationNotMetError => e
|
53
|
+
raise e if elapsed_time >= time
|
54
|
+
sleep increment
|
55
|
+
wait(time, increment, elapsed_time + increment, &block)
|
56
|
+
end
|