-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from taylorfinnell/add_connections
Add connections
- Loading branch information
Showing
6 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Auth0 | ||
module Api | ||
module V2 | ||
module Connections | ||
def connections(strategy: nil, fields: nil, include_fields: true) | ||
request_params = { | ||
strategy: strategy, | ||
fields: fields, | ||
include_fields: include_fields | ||
} | ||
path = "/api/v2/connections" | ||
get(path, request_params) | ||
end | ||
alias :get_connections :connections | ||
|
||
def create_connection(body) | ||
path = "/api/v2/connections" | ||
request_params = body | ||
post(path, request_params ) | ||
end | ||
|
||
def connection(connection_id, fields: nil, include_fields: true) | ||
path = "/api/v2/connections/" + connection_id.to_s | ||
request_params = { | ||
fields: fields, | ||
include_fields: include_fields | ||
} | ||
get(path, request_params) | ||
end | ||
|
||
def delete_connection(connection_id) | ||
raise Auth0::MissingConnectionId, "you must specify a connection id" if connection_id.to_s.empty? | ||
path = "/api/v2/connections/#{connection_id}" | ||
delete(path) | ||
end | ||
|
||
def update_connection(connection_id, body) | ||
raise Auth0::MissingConnectionId, "you must specify a connection id" if connection_id.to_s.empty? | ||
path = "/api/v2/connections/" + connection_id.to_s | ||
patch(path, body) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require "spec_helper" | ||
describe Auth0::Api::V2::Connections do | ||
|
||
let(:client) { Auth0Client.new(v2_creds) } | ||
|
||
let(:name) { SecureRandom.uuid[0..25] } | ||
let(:strategy) { 'google-oauth2' } | ||
let(:options) { {} } | ||
let(:enabled_clients) { [] } | ||
|
||
let!(:connection) { client.create_connection({ | ||
name: name, | ||
strategy: strategy, | ||
options: options, | ||
enabled_clients: enabled_clients, | ||
})} | ||
|
||
describe '.connections' do | ||
|
||
let(:connections) { client.connections() } | ||
|
||
it { expect(connections.size).to be > 0 } | ||
it { expect(connections.find {|con| con["name"] == name}).to_not be_nil } | ||
|
||
context "#filters" do | ||
it { expect(client.connections(strategy: strategy).size).to be > 0 } | ||
it { expect(client.connections(strategy: strategy, fields: [:name].join(',')).first).to include("name") } | ||
it { expect(client.connections(strategy: strategy, fields: [:name].join(','), include_fields: false).first).to_not include("name") } | ||
end | ||
|
||
end | ||
|
||
describe '.connection' do | ||
|
||
let(:subject) { client.connection(connection["id"]) } | ||
|
||
it { should include("name" => connection['name']) } | ||
|
||
context "#filters" do | ||
it { expect(client.connection(connection["id"], fields: [:name, :id].join(','))).to include("id", "name") } | ||
it { expect(client.connection(connection["id"], fields: [:name, :id].join(','), include_fields: false)).to_not include("id", "name") } | ||
end | ||
|
||
end | ||
|
||
describe '.create_connection' do | ||
|
||
let(:subject) { connection } | ||
|
||
it { should include("id", "name") } | ||
it { should include( | ||
"name" => connection['name'], | ||
)} | ||
|
||
end | ||
|
||
describe '.delete_connection' do | ||
|
||
it { expect { client.delete_connection connection["id"] }.to_not raise_error } | ||
|
||
it { expect { client.delete_connection "" }.to raise_error(Auth0::MissingConnectionId) } | ||
|
||
end | ||
|
||
|
||
describe '.update_connection' do | ||
new_name = SecureRandom.uuid[0..25] | ||
it { expect(client.update_connection(connection["id"], {"name" => new_name})).to include("name" => new_name) } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require "spec_helper" | ||
describe Auth0::Api::V2::Connections do | ||
before :all do | ||
dummy_instance = DummyClass.new | ||
dummy_instance.extend(Auth0::Api::V2::Connections) | ||
@instance = dummy_instance | ||
end | ||
|
||
context ".connections" do | ||
it {expect(@instance).to respond_to(:connections)} | ||
it {expect(@instance).to respond_to(:get_connections)} | ||
|
||
it "is expected to call /api/v2/connections" do | ||
expect(@instance).to receive(:get).with("/api/v2/connections", { | ||
strategy: nil, | ||
fields: nil, | ||
include_fields: true | ||
}) | ||
|
||
expect{@instance.connections}.not_to raise_error | ||
end | ||
end | ||
|
||
context '.create_connection' do | ||
it {expect(@instance).to respond_to(:connection)} | ||
it {expect(@instance).to respond_to(:create_connection)} | ||
|
||
it "is expected to call /api/v2/connections" do | ||
body = double | ||
expect(@instance).to receive(:post).with("/api/v2/connections", body) | ||
|
||
expect{@instance.create_connection(body)}.not_to raise_error | ||
end | ||
end | ||
|
||
context ".connection" do | ||
it {expect(@instance).to respond_to(:connection)} | ||
it "is expected to call get request to /api/v2/connection/CONNECTION_ID" do | ||
expect(@instance).to receive(:get).with("/api/v2/connections/CONNECTION_ID", {fields: nil, include_fields: true}) | ||
expect{@instance.connection("CONNECTION_ID")}.not_to raise_error | ||
end | ||
end | ||
|
||
context ".delete_connection" do | ||
it {expect(@instance).to respond_to(:delete_connection)} | ||
it "is expected to call delete to /api/v2/connections/connectionId" do | ||
expect(@instance).to receive(:delete).with("/api/v2/connections/connectionId") | ||
@instance.delete_connection("connectionId") | ||
end | ||
|
||
it "is expected not to call delete to /api/v2/connections if connection_id is blank" do | ||
expect(@instance).not_to receive(:delete) | ||
expect{@instance.delete_connection("")}.to raise_exception(Auth0::MissingConnectionId) | ||
end | ||
end | ||
|
||
context ".update_connection" do | ||
it {expect(@instance).to respond_to(:update_connection)} | ||
it "is expected to call patch to /api/v2/connections/connectionId" do | ||
body = double | ||
expect(@instance).to receive(:patch).with("/api/v2/connections/connectionId", body) | ||
@instance.update_connection("connectionId", body) | ||
end | ||
|
||
it "is expected not to call delete to /api/v2/connections if connection_id is blank" do | ||
expect(@instance).not_to receive(:patch) | ||
expect{@instance.delete_connection("")}.to raise_exception(Auth0::MissingConnectionId) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
module Credentials | ||
def v1_creds | ||
{client_id: ENV["CLIENT_ID"], client_secret: ENV["CLIENT_SECRET"], domain: ENV["DOMAIN"]} | ||
end | ||
def v1_creds | ||
{client_id: ENV["CLIENT_ID"], client_secret: ENV["CLIENT_SECRET"], domain: ENV["DOMAIN"]} | ||
end | ||
|
||
def v1_global_creds | ||
{client_id: ENV["GLOBAL_CLIENT_ID"], client_secret: ENV["GLOBAL_CLIENT_SECRET"], domain: ENV["DOMAIN"]} | ||
end | ||
def v1_global_creds | ||
{client_id: ENV["GLOBAL_CLIENT_ID"], client_secret: ENV["GLOBAL_CLIENT_SECRET"], domain: ENV["DOMAIN"]} | ||
end | ||
|
||
def v2_creds | ||
{token: ENV["MASTER_JWT"], api_version: 2, domain: ENV["DOMAIN"]} | ||
end | ||
def v2_creds | ||
{token: ENV["MASTER_JWT"], api_version: 2, domain: ENV["DOMAIN"]} | ||
end | ||
end |