auth0-ruby 0.9
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 +7 -0
- data/.bundle/config +2 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +68 -0
- data/README.md +27 -0
- data/Rakefile +9 -0
- data/auth0.gemspec +29 -0
- data/doc/Auth0.html +153 -0
- data/doc/Auth0/Api.html +128 -0
- data/doc/Auth0/Api/AuthenticationEndpoints.html +596 -0
- data/doc/Auth0/Api/V1.html +192 -0
- data/doc/Auth0/Api/V1/Clients.html +440 -0
- data/doc/Auth0/Api/V1/Connections.html +506 -0
- data/doc/Auth0/Api/V1/Logs.html +366 -0
- data/doc/Auth0/Api/V1/Rules.html +439 -0
- data/doc/Auth0/Api/V1/Users.html +1617 -0
- data/doc/Auth0/BadRequest.html +142 -0
- data/doc/Auth0/Client.html +236 -0
- data/doc/Auth0/Exception.html +140 -0
- data/doc/Auth0/Mixins.html +225 -0
- data/doc/Auth0/Mixins/HTTPartyProxy.html +121 -0
- data/doc/Auth0/Mixins/Initializer.html +298 -0
- data/doc/Auth0/NotFound.html +143 -0
- data/doc/Auth0/ServerError.html +142 -0
- data/doc/Auth0/Unauthorized.html +143 -0
- data/doc/Auth0/Unsupported.html +142 -0
- data/doc/Auth0/UserIdIsBlank.html +143 -0
- data/doc/Auth0Client.html +235 -0
- data/doc/_index.html +347 -0
- data/doc/class_list.html +58 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +103 -0
- data/doc/file_list.html +60 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +103 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +181 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +327 -0
- data/doc/top-level-namespace.html +114 -0
- data/lib/auth0.rb +8 -0
- data/lib/auth0/api/authentication_endpoints.rb +71 -0
- data/lib/auth0/api/v1.rb +19 -0
- data/lib/auth0/api/v1/clients.rb +48 -0
- data/lib/auth0/api/v1/connections.rb +51 -0
- data/lib/auth0/api/v1/logs.rb +41 -0
- data/lib/auth0/api/v1/rules.rb +44 -0
- data/lib/auth0/api/v1/users.rb +163 -0
- data/lib/auth0/client.rb +7 -0
- data/lib/auth0/exception.rb +18 -0
- data/lib/auth0/mixins.rb +13 -0
- data/lib/auth0/mixins/httparty_proxy.rb +29 -0
- data/lib/auth0/mixins/initializer.rb +25 -0
- data/lib/auth0/version.rb +4 -0
- data/lib/auth0_client.rb +3 -0
- data/spec/lib/auth0/api/authentication_endpoints_spec.rb +56 -0
- data/spec/lib/auth0/api/v1/clients_spec.rb +62 -0
- data/spec/lib/auth0/api/v1/connections_spec.rb +62 -0
- data/spec/lib/auth0/api/v1/logs_spec.rb +46 -0
- data/spec/lib/auth0/api/v1/rules_spec.rb +40 -0
- data/spec/lib/auth0/api/v1/users_spec.rb +215 -0
- data/spec/lib/auth0/client_spec.rb +19 -0
- data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +60 -0
- data/spec/lib/auth0_client_spec.rb +8 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/dummy_class.rb +7 -0
- data/spec/support/dummy_class_for_proxy.rb +4 -0
- data/spec/support/stub_response.rb +2 -0
- metadata +253 -0
data/lib/auth0/client.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Auth0
|
2
|
+
# Default exception in namespace of Auth0
|
3
|
+
# if you want to catch all exceptions, then you should use this one.
|
4
|
+
# Network exceptions are not included
|
5
|
+
class Exception < StandardError; end
|
6
|
+
end
|
7
|
+
# exception for unauthorized requests, if you see it, probably Bearer Token is not set correctly
|
8
|
+
class Auth0::Unauthorized < Auth0::Exception; end
|
9
|
+
# exception for not found resource, you query for an unexistent resource, or wrong path
|
10
|
+
class Auth0::NotFound < Auth0::Exception; end
|
11
|
+
# exception for unknown error
|
12
|
+
class Auth0::Unsupported < Auth0::Exception; end
|
13
|
+
# exception for server error
|
14
|
+
class Auth0::ServerError < Auth0::Exception; end
|
15
|
+
# exception for incorrect request, you've sent wrong params
|
16
|
+
class Auth0::BadRequest < Auth0::Exception; end
|
17
|
+
# exception for unset user_id, this might cause removal of all users, or other unexpected bahaviour
|
18
|
+
class Auth0::UserIdIsBlank < Auth0::Exception; end
|
data/lib/auth0/mixins.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'uri'
|
3
|
+
require "auth0/mixins/initializer"
|
4
|
+
require "auth0/mixins/httparty_proxy"
|
5
|
+
require "auth0/api/authentication_endpoints"
|
6
|
+
require "auth0/api/v1"
|
7
|
+
# Collecting dependencies here
|
8
|
+
module Auth0::Mixins
|
9
|
+
include Auth0::Mixins::HTTPartyProxy
|
10
|
+
include Auth0::Mixins::Initializer
|
11
|
+
include Auth0::Api::AuthenticationEndpoints
|
12
|
+
include Auth0::Api::V1
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Auth0
|
2
|
+
module Mixins
|
3
|
+
# here's the proxy for HTTParty, we're building all request on that gem for now, if you want to feel free to use your own http client
|
4
|
+
module HTTPartyProxy
|
5
|
+
# proxying requests from instance methods to HTTParty class methods
|
6
|
+
%i(get post put patch delete).each do |method|
|
7
|
+
define_method(method) do |path, body={}|
|
8
|
+
safe_path = URI.escape(path)
|
9
|
+
result = self.class.send(method, safe_path, body: body.to_json)
|
10
|
+
response_body =
|
11
|
+
begin
|
12
|
+
JSON.parse(result.body.to_s)
|
13
|
+
rescue JSON::ParserError
|
14
|
+
result.body
|
15
|
+
end
|
16
|
+
case result.code
|
17
|
+
when 200...226 then response_body
|
18
|
+
when 400 then raise Auth0::BadRequest, response_body
|
19
|
+
when 401 then raise Auth0::Unauthorized, response_body
|
20
|
+
when 404 then raise Auth0::NotFound, response_body
|
21
|
+
when 500 then raise Auth0::ServerError, response_body
|
22
|
+
else
|
23
|
+
raise Auth0::Unsupported, response_body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Auth0
|
2
|
+
module Mixins
|
3
|
+
# Help class where Auth0::Client initialization described
|
4
|
+
module Initializer
|
5
|
+
# Default initialization mechanism, moved here to keep Auth0::Client clear
|
6
|
+
# accepts hash as parameter
|
7
|
+
# you can get all required fields from here: https://auth0.com/docs/auth-api
|
8
|
+
def initialize(config)
|
9
|
+
options = Hash[config.map{|(k,v)| [k.to_sym,v]}]
|
10
|
+
self.class.base_uri "https://#{options[:namespace]}"
|
11
|
+
self.class.headers "Content-Type" => 'application/json'
|
12
|
+
@client_id = options[:client_id]
|
13
|
+
@client_secret = options[:client_secret]
|
14
|
+
@token = obtain_access_token
|
15
|
+
self.class.headers "Authorization" => "Bearer #{@token}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# including initializer in top of klass
|
19
|
+
def self.included(klass)
|
20
|
+
klass.send :prepend, Initializer
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/auth0_client.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
describe Auth0::Api::AuthenticationEndpoints do
|
3
|
+
before :all do
|
4
|
+
dummy_instance = DummyClass.new
|
5
|
+
dummy_instance.extend(Auth0::Api::AuthenticationEndpoints)
|
6
|
+
@instance = dummy_instance
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".obtain_access_token" do
|
10
|
+
it {expect(@instance).to respond_to(:obtain_access_token)}
|
11
|
+
it "is expected to make post request to '/oauth/token'" do
|
12
|
+
allow(@instance).to receive(:post).with("/oauth/token", {client_id: nil, client_secret: nil, grant_type: 'client_credentials'}).
|
13
|
+
and_return({"access_token" => "AccessToken"})
|
14
|
+
expect(@instance).to receive(:post).with("/oauth/token", {client_id: nil, client_secret: nil, grant_type: 'client_credentials'})
|
15
|
+
expect(@instance.obtain_access_token).to eql "AccessToken"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context ".delegation" do
|
20
|
+
it {expect(@instance).to respond_to(:delegation)}
|
21
|
+
it "is expected to make post request to '/delegation'" do
|
22
|
+
expect(@instance).to receive(:post).with("/delegation",{:client_id=>nil, :grant_type=>"urn:ietf:params:oauth:grant-type:jwt-bearer", :id_token=>"token", :target=>"target", :scope=>""})
|
23
|
+
@instance.delegation("token", "target", "")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context ".login" do
|
28
|
+
it {expect(@instance).to respond_to(:signup)}
|
29
|
+
it "is expected to make post to /oauth/ro" do
|
30
|
+
expect(@instance).to receive(:post).with("/oauth/ro", {client_id: nil, username:"test@test.com", password: "password", connection: "Username-Password-Authentication", scope: "openid", grand_type: "password", id_token: nil})
|
31
|
+
@instance.login("test@test.com", "password")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context ".signup" do
|
35
|
+
it {expect(@instance).to respond_to(:signup)}
|
36
|
+
it "is expected to make post to /dbconnections/signup" do
|
37
|
+
expect(@instance).to receive(:post).with("/dbconnections/signup", {client_id: nil, email: "test@test.com", password: "password", connection: "User"})
|
38
|
+
@instance.signup("test@test.com", "password", "User")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context ".change_password" do
|
42
|
+
it {expect(@instance).to respond_to(:change_password)}
|
43
|
+
it "is expected to make post to /dbconnections/change_password" do
|
44
|
+
expect(@instance).to receive(:post).with("/dbconnections/change_password", {client_id: nil, email: "test@test.com", password: "password", connection: "User"})
|
45
|
+
@instance.change_password("test@test.com", "password", "User")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context ".token_info" do
|
50
|
+
it {expect(@instance).to respond_to(:token_info)}
|
51
|
+
it "is expected to make post to /tokeinfo" do
|
52
|
+
expect(@instance).to receive(:post).with("/tokeninfo", {id_token: "SomerandomToken"})
|
53
|
+
@instance.token_info("SomerandomToken")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
describe Auth0::Api::V1::Clients do
|
3
|
+
before :all do
|
4
|
+
dummy_instance = DummyClass.new
|
5
|
+
dummy_instance.extend(Auth0::Api::V1::Clients)
|
6
|
+
@instance = dummy_instance
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".clients" do
|
10
|
+
it {expect(@instance).to respond_to(:clients)}
|
11
|
+
it "is expected to send get request to /api/clients" do
|
12
|
+
expect(@instance).to receive(:get).with("/api/clients")
|
13
|
+
expect{@instance.clients}.not_to raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".create_client" do
|
18
|
+
it {expect(@instance).to respond_to(:create_client)}
|
19
|
+
it "is expected to send post request to /api/clients" do
|
20
|
+
client_name = "ClientRandomName"
|
21
|
+
callbacks = "Some absolutely random stuff here"
|
22
|
+
expect(@instance).to receive(:post).with("/api/clients",{name: client_name, callbacks: callbacks})
|
23
|
+
expect{@instance.create_client(client_name, callbacks)}.not_to raise_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context ".create_client" do
|
28
|
+
it {expect(@instance).to respond_to(:create_client)}
|
29
|
+
it "is expected to send post request to /api/clients" do
|
30
|
+
client_name = "Some random name"
|
31
|
+
callbacks = "Some random stuff"
|
32
|
+
expect(@instance).to receive(:post).with("/api/clients",{name: client_name, callbacks: callbacks})
|
33
|
+
expect{@instance.create_client(client_name, callbacks)}.not_to raise_error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context ".update_client" do
|
38
|
+
it {expect(@instance).to respond_to(:update_client)}
|
39
|
+
it "is expected to perform put to /api/clients/#client_id" do
|
40
|
+
client_name = "Some random name"
|
41
|
+
callbacks = "Some random stuff"
|
42
|
+
expect(@instance).to receive(:put).with("/api/clients/client_id",{name: client_name, callbacks: callbacks})
|
43
|
+
expect{@instance.update_client(client_name, callbacks, "client_id")}.not_to raise_error
|
44
|
+
end
|
45
|
+
|
46
|
+
it "is expected to make warn on deprecated endpoint" do
|
47
|
+
expect(@instance).to receive(:warn).with("This endpoint has been deprecated in favor of PUT.")
|
48
|
+
@instance.update_client("test")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context ".patch_client" do
|
53
|
+
it {expect(@instance).to respond_to(:patch_client)}
|
54
|
+
it "is expected to perform patch to /api/clients/#client_id" do
|
55
|
+
client_name = "Some random name"
|
56
|
+
callbacks = "Some random stuff"
|
57
|
+
expect(@instance).to receive(:patch).with("/api/clients/client_id",{name: client_name, callbacks: callbacks})
|
58
|
+
expect{@instance.patch_client(client_name, callbacks, "client_id")}.not_to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
describe Auth0::Api::V1::Connections do
|
3
|
+
before :all do
|
4
|
+
dummy_instance = DummyClass.new
|
5
|
+
dummy_instance.extend(Auth0::Api::V1::Connections)
|
6
|
+
dummy_instance.extend(Auth0::Mixins::Initializer)
|
7
|
+
@instance = dummy_instance
|
8
|
+
end
|
9
|
+
|
10
|
+
context ".connections" do
|
11
|
+
it {expect(@instance).to respond_to(:connections)}
|
12
|
+
it {expect(@instance).to respond_to(:get_connections)}
|
13
|
+
it "is expected to send get request to /api/connections" do
|
14
|
+
expect(@instance).to receive(:get).with("/api/connections")
|
15
|
+
expect{@instance.connections}.not_to raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context ".connection" do
|
20
|
+
it {expect(@instance).to respond_to(:connection)}
|
21
|
+
it "it is expected to send get request to /api/connections/RandomConnectionName" do
|
22
|
+
expect(@instance).to receive(:get).with("/api/connections/RandomConnectionName")
|
23
|
+
expect{@instance.connection("RandomConnectionName")}.not_to raise_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context ".delete_connection" do
|
28
|
+
it {expect(@instance).to respond_to(:delete_connection)}
|
29
|
+
it "it is expected to send delete request to /api/connections/RandomConnectionName" do
|
30
|
+
expect(@instance).to receive(:delete).with("/api/connections/RandomConnectionName")
|
31
|
+
expect{@instance.delete_connection("RandomConnectionName")}.not_to raise_error
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context ".create_connection" do
|
36
|
+
it {expect(@instance).to respond_to(:create_connection)}
|
37
|
+
it "is expected to send post to /api/connections" do
|
38
|
+
params= { name: "Some Test name",
|
39
|
+
strategy: "Unpredictable",
|
40
|
+
options: {
|
41
|
+
tenant_domain: "google.com",
|
42
|
+
domain_aliases: "test.google.com,auth0.com"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
expect(@instance).to receive(:post).with("/api/connections",params)
|
46
|
+
expect{@instance.create_connection("Some Test name", "Unpredictable", "google.com", "test.google.com,auth0.com")}.not_to raise_error
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context ".update_connection" do
|
50
|
+
it {expect(@instance).to respond_to(:update_connection)}
|
51
|
+
it "is expected to send put to /api/connections/TestName" do
|
52
|
+
params= { status: false,
|
53
|
+
options: {
|
54
|
+
tenant_domain: "google.com",
|
55
|
+
}
|
56
|
+
}
|
57
|
+
expect(@instance).to receive(:put).with("/api/connections/TestName",params)
|
58
|
+
expect{@instance.update_connection("TestName", "google.com", false)}.not_to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
describe Auth0::Api::V1::Logs do
|
3
|
+
before :all do
|
4
|
+
dummy_instance = DummyClass.new
|
5
|
+
dummy_instance.extend(Auth0::Api::V1::Logs)
|
6
|
+
dummy_instance.extend(Auth0::Mixins::Initializer)
|
7
|
+
@instance = dummy_instance
|
8
|
+
end
|
9
|
+
|
10
|
+
context ".logs or .search_logs" do
|
11
|
+
it {expect(@instance).to respond_to(:logs)}
|
12
|
+
it {expect(@instance).to respond_to(:search_logs)}
|
13
|
+
it "should call path with all provided params per_page" do
|
14
|
+
expect(@instance).to receive(:get).with("/api/logs?per_page=500")
|
15
|
+
expect{@instance.logs("per_page" => 500)}.not_to raise_error
|
16
|
+
end
|
17
|
+
it "should call path with all provided params per_page, page" do
|
18
|
+
expect(@instance).to receive(:get).with("/api/logs?per_page=500&page=3")
|
19
|
+
expect{@instance.logs("per_page" => 500, page: 3)}.not_to raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should raise warn if any garbage params are passed" do
|
23
|
+
error_message = "random_stuff is not in acceptable params list: [:take, :from, :search_criteria, :page, :per_page, :sort, :fields, :exclude_fields]"
|
24
|
+
expect(@instance).to receive(:warn).with(error_message)
|
25
|
+
@instance.logs("per_page" => 500, page: 3, random_stuff:7 )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context ".log" do
|
30
|
+
it {expect(@instance).to respond_to :log}
|
31
|
+
it "is expected to get '/api/logs/te st'" do
|
32
|
+
expect(@instance).to receive(:get).with("/api/logs/te st")
|
33
|
+
expect{@instance.log("te st")}.not_to raise_error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context ".user_logs" do
|
38
|
+
it {expect(@instance).to respond_to(:user_logs)}
|
39
|
+
it "is expected to get /api/users/#user_id/logs" do
|
40
|
+
expect(@instance).to receive(:get).with("/api/users/auth0|test test/logs?page=0&per_page=50")
|
41
|
+
expect{@instance.user_logs("auth0|test test")}.not_to raise_error
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
describe Auth0::Api::V1::Rules do
|
3
|
+
before :all do
|
4
|
+
dummy_instance = DummyClass.new
|
5
|
+
dummy_instance.extend(Auth0::Api::V1::Rules)
|
6
|
+
dummy_instance.extend(Auth0::Mixins::Initializer)
|
7
|
+
@instance = dummy_instance
|
8
|
+
end
|
9
|
+
|
10
|
+
context ".rules" do
|
11
|
+
it {expect(@instance).to respond_to(:rules)}
|
12
|
+
it "is expected to call get /api/rules" do
|
13
|
+
expect(@instance).to receive(:get).with("/api/rules")
|
14
|
+
expect{@instance.rules}.not_to raise_error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context ".create_rule" do
|
19
|
+
it {expect(@instance).to respond_to(:create_rule)}
|
20
|
+
it "is expected to call post /api/rules" do
|
21
|
+
expect(@instance).to receive(:post).with("/api/rules", {name:"test",script:"script",order:"order",status:"status"})
|
22
|
+
expect{@instance.create_rule("test", "script", "order", "status")}.not_to raise_error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context ".update_rule" do
|
26
|
+
it {expect(@instance).to respond_to(:update_rule)}
|
27
|
+
it "is expected to call put /api/rules/test" do
|
28
|
+
expect(@instance).to receive(:put).with("/api/rules/test", {script:"script",order:"order",status:"status"})
|
29
|
+
expect{@instance.update_rule("test", "script", "order", "status")}.not_to raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context ".delete_rule" do
|
33
|
+
it {expect(@instance).to respond_to(:delete_rule)}
|
34
|
+
it "is expected to call delete /api/rules/test" do
|
35
|
+
expect(@instance).to receive(:delete).with("/api/rules/test")
|
36
|
+
expect{@instance.delete_rule("test")}.not_to raise_error
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
describe Auth0::Api::V1::Users do
|
3
|
+
before :all do
|
4
|
+
dummy_instance = DummyClass.new
|
5
|
+
dummy_instance.extend(Auth0::Api::V1::Users)
|
6
|
+
@instance = dummy_instance
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".users" do
|
10
|
+
it {expect(@instance).to respond_to(:users)}
|
11
|
+
it {expect(@instance).to respond_to(:users_search)}
|
12
|
+
it "is expected to call /api/users when search is nill" do
|
13
|
+
expect(@instance).to receive(:get).with("/api/users")
|
14
|
+
expect{@instance.users}.not_to raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "is expected to call /api/users?search=search_criteria when search is search_criteria" do
|
18
|
+
expect(@instance).to receive(:get).with("/api/users?search=search_criteria")
|
19
|
+
expect{@instance.users("search_criteria")}.not_to raise_error
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context ".user" do
|
24
|
+
it {expect(@instance).to respond_to(:user)}
|
25
|
+
it "is expected to call get request to /api/users/USER_ID" do
|
26
|
+
expect(@instance).to receive(:get).with("/api/users/USER_ID")
|
27
|
+
expect{@instance.user("USER_ID")}.not_to raise_error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context ".user_devices" do
|
32
|
+
it {expect(@instance).to respond_to(:user_devices)}
|
33
|
+
it "is expected to call /api/users when search is nill" do
|
34
|
+
expect(@instance).to receive(:get).with("/api/users/USER_ID/devices")
|
35
|
+
expect{@instance.user_devices("USER_ID")}.not_to raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context ".connection_users" do
|
40
|
+
it {expect(@instance).to respond_to(:connection_users)}
|
41
|
+
it {expect(@instance).to respond_to(:search_connection_users)}
|
42
|
+
it "is expected to call /api/connections/CONNECTION_ID/users/ when search is nill" do
|
43
|
+
expect(@instance).to receive(:get).with("/api/connections/CONNECTION_ID/users")
|
44
|
+
expect{@instance.connection_users("CONNECTION_ID")}.not_to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it "is expected to call /api/connections/CONNECTION_ID/users?search=search_criteria when search is search_criteria" do
|
48
|
+
expect(@instance).to receive(:get).with("/api/connections/CONNECTION_ID/users?search=search_criteria")
|
49
|
+
expect{@instance.connection_users("CONNECTION_ID", "search_criteria")}.not_to raise_error
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context ".enterpriseconnections_users" do
|
54
|
+
it{expect(@instance).to respond_to(:enterpriseconnections_users)}
|
55
|
+
it "is expected to call get to /api/enterpriseconnections/users" do
|
56
|
+
expect(@instance).to receive(:get).with("/api/enterpriseconnections/users?search=arr a&per_page=11")
|
57
|
+
@instance.enterpriseconnections_users "arr a", 11
|
58
|
+
end
|
59
|
+
|
60
|
+
it "is expected to call get to /api/enterpriseconnections/users?search=dfasdf&per_page=500" do
|
61
|
+
expect(@instance).to receive(:get).with("/api/enterpriseconnections/users?search=arr a&per_page=500")
|
62
|
+
@instance.enterpriseconnections_users "arr a"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context ".socialconnections_users" do
|
67
|
+
it{expect(@instance).to respond_to(:socialconnections_users)}
|
68
|
+
it "is expected to call get to /api/socialconnections/users" do
|
69
|
+
expect(@instance).to receive(:get).with("/api/socialconnections/users?search=arr a&per_page=11")
|
70
|
+
@instance.socialconnections_users "arr a", 11
|
71
|
+
end
|
72
|
+
it "is expected to call get to /api/socialconnections/users" do
|
73
|
+
expect(@instance).to receive(:get).with("/api/socialconnections/users?search=arr a&per_page=500")
|
74
|
+
@instance.socialconnections_users "arr a"
|
75
|
+
end
|
76
|
+
it "is expected to call get to /api/socialconnections/users" do
|
77
|
+
expect(@instance).to receive(:get).with("/api/socialconnections/users?search=&per_page=500")
|
78
|
+
@instance.socialconnections_users
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context ".client_users" do
|
83
|
+
it {expect(@instance).to respond_to(:client_users)}
|
84
|
+
it "is expected to call /api/client/test_client_id/users through get" do
|
85
|
+
expect(@instance).to receive(:get).with("/api/clients/test_client_id/users")
|
86
|
+
@instance.client_users("test_client_id")
|
87
|
+
end
|
88
|
+
it "is expected to call /api/client//users if no client_id passed" do
|
89
|
+
expect(@instance).to receive(:get).with("/api/clients//users")
|
90
|
+
expect{@instance.client_users()}.not_to raise_error
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context ".create_user" do
|
95
|
+
it {expect(@instance).to respond_to(:create_user)}
|
96
|
+
it "is expected to call post to /api/users" do
|
97
|
+
expect(@instance).to receive(:post).with("/api/users", {email: "test@test.com", password: "password", connection: "conn"})
|
98
|
+
@instance.create_user("test@test.com", "password", "conn")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context ".send_verification_email" do
|
103
|
+
it {expect(@instance).to respond_to(:send_verification_email)}
|
104
|
+
it "is expected to call post to /api/users/test/send_verification_email" do
|
105
|
+
expect(@instance).to receive(:post).with("/api/users/test/send_verification_email")
|
106
|
+
@instance.send_verification_email("test")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context ".change_password_ticket" do
|
111
|
+
it {expect(@instance).to respond_to(:change_password_ticket)}
|
112
|
+
it "is expected to call post to /api/users/USERID/change_password_ticket" do
|
113
|
+
password = SecureRandom.hex
|
114
|
+
expect(@instance).to receive(:post).with("/api/users/USERID/change_password_ticket", { "newPassword" => password, "resultUrl" => nil })
|
115
|
+
@instance.change_password_ticket "USERID", password
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context ".verification_ticket" do
|
120
|
+
it {expect(@instance).to respond_to(:verification_ticket)}
|
121
|
+
it "is expected to call post to /api/users/userId/verification_ticket if resulturl is set" do
|
122
|
+
expect(@instance).to receive(:post).with("/api/users/auth0|tdasfasdfasdfa/verification_ticket", {"resultUrl" => "google.com"})
|
123
|
+
@instance.verification_ticket("auth0|tdasfasdfasdfa","google.com")
|
124
|
+
end
|
125
|
+
it "is expected to call post to /api/users/userId/verification_ticket if result url is empty" do
|
126
|
+
expect(@instance).to receive(:post).with("/api/users/auth0|tdasfasdfasdfa/verification_ticket", {"resultUrl" => nil})
|
127
|
+
@instance.verification_ticket("auth0|tdasfasdfasdfa")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context ".create_public_key" do
|
132
|
+
it {expect(@instance).to respond_to(:create_public_key)}
|
133
|
+
it "is expected to call post to /api/users/userId/public_key" do
|
134
|
+
expect(@instance).to receive(:post).with("/api/users/auth0|tdasfasdfasdfa/public_key", {device: "device22", public_key: "SuperSecurePK"})
|
135
|
+
@instance.create_public_key("auth0|tdasfasdfasdfa","device22", "SuperSecurePK")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context ".update_user_email" do
|
140
|
+
it {expect(@instance).to respond_to(:update_user_email)}
|
141
|
+
it "is expected to call put to /api/users/auth0|tdasfasdfasdfa/email" do
|
142
|
+
expect(@instance).to receive(:put).with("/api/users/auth0|tdasfasdfasdfa/email", {email:"email", verify: true})
|
143
|
+
@instance.update_user_email("auth0|tdasfasdfasdfa", "email")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context ".update_user_metadata" do
|
148
|
+
it {expect(@instance).to respond_to :update_user_metadata}
|
149
|
+
it "is expected to call put to /api/users/userId/metadata" do
|
150
|
+
expect(@instance).to receive(:put).with("/api/users/userId/metadata", {supersecret_users_data: "3"})
|
151
|
+
@instance.update_user_metadata "userId", {supersecret_users_data: "3"}
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context ".update_user_password" do
|
156
|
+
it {expect(@instance).to respond_to(:update_user_password)}
|
157
|
+
it "is expected to call put to /api/users/auth0|tdasfasdfasdfa/password" do
|
158
|
+
expect(@instance).to receive(:put).with("/api/users/auth0|tdasfasdfasdfa/password", {password:"password", verify: true})
|
159
|
+
@instance.update_user_password("auth0|tdasfasdfasdfa", "password")
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context ".update_user_password_using_email" do
|
164
|
+
it {expect(@instance).to respond_to(:update_user_password_using_email)}
|
165
|
+
it "is expected to call put to /api/users/email@email.com/password" do
|
166
|
+
expect(@instance).to receive(:put).with("/api/users/email@email.com/password", {email: "email@email.com", password:"password", connection:"Con", verify: true})
|
167
|
+
@instance.update_user_password_using_email("email@email.com", "password", "Con")
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context ".patch_user_metadata" do
|
172
|
+
it {expect(@instance).to respond_to :patch_user_metadata}
|
173
|
+
it "is expected to call patch to /api/users/userId/metadata" do
|
174
|
+
expect(@instance).to receive(:patch).with("/api/users/userId/metadata", {supersecret_users_data: "3"})
|
175
|
+
@instance.patch_user_metadata "userId", {supersecret_users_data: "3"}
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context ".delete_users" do
|
180
|
+
it {expect(@instance).to respond_to :delete_users}
|
181
|
+
it "is expected to call delete to /api/users" do
|
182
|
+
expect(@instance).to receive(:delete).with("/api/users/")
|
183
|
+
@instance.delete_users
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context ".delete_user" do
|
188
|
+
it {expect(@instance).to respond_to(:delete_user)}
|
189
|
+
it "is expected to call delete to /api/users/userId" do
|
190
|
+
expect(@instance).to receive(:delete).with("/api/users/userId")
|
191
|
+
@instance.delete_user("userId")
|
192
|
+
end
|
193
|
+
|
194
|
+
it "is expected not to call delete to /api/users if user_id is blank" do
|
195
|
+
expect(@instance).not_to receive(:delete)
|
196
|
+
expect{@instance.delete_user("")}.to raise_exception(Auth0::UserIdIsBlank)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context ".revoke_user_refresh_token" do
|
201
|
+
it {expect(@instance).to respond_to(:revoke_user_refresh_token)}
|
202
|
+
it "is expected to call delete to /api/users/user_id/refresh_tokens/refresh_token" do
|
203
|
+
expect(@instance).to receive(:delete).with("/api/users/user_id/refresh_tokens/refresh_token")
|
204
|
+
@instance.revoke_user_refresh_token("user_id", "refresh_token")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context ".revoke_user_device_public_key" do
|
209
|
+
it {expect(@instance).to respond_to(:revoke_user_device_public_key)}
|
210
|
+
it "is expected to call delete to /api/users/user_id/publickey?device=device" do
|
211
|
+
expect(@instance).to receive(:delete).with("/api/users/user_id/publickey?device=device")
|
212
|
+
@instance.revoke_user_device_public_key("user_id", "device")
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|