-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
133 additions
and
0 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
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,16 @@ | ||
require "warden/strategies/omniauth" | ||
|
||
Warden::Strategies.add(:cddo_sso) do | ||
include Warden::Strategies::OmniAuth | ||
|
||
private | ||
|
||
def prep_user(auth_hash) | ||
User.find_for_auth( | ||
provider: auth_hash[:provider], | ||
uid: auth_hash[:uid], | ||
email: auth_hash[:info][:email], | ||
name: auth_hash[:info][: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
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,84 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "usage of cddo_sso auth provider" do | ||
let(:omniauth_hash) do | ||
OmniAuth::AuthHash.new({ | ||
provider: "cddo_sso", | ||
uid: "123456", | ||
info: { | ||
email: "[email protected]", | ||
name: "Test User", | ||
}, | ||
}) | ||
end | ||
|
||
before do | ||
allow(Settings).to receive(:auth_provider).and_return("cddo_sso") | ||
|
||
OmniAuth.config.test_mode = true | ||
OmniAuth.config.mock_auth[:cddo_sso] = nil | ||
end | ||
|
||
after do | ||
OmniAuth.config.test_mode = false | ||
end | ||
|
||
describe "authentication" do | ||
it "redirects to OmniAuth when no user is logged in" do | ||
logout | ||
|
||
get root_path | ||
|
||
expect(response).to redirect_to("/auth/cddo_sso") | ||
end | ||
|
||
it "authenticates with OmniAuth and Warden" do | ||
OmniAuth.config.mock_auth[:cddo_sso] = omniauth_hash | ||
|
||
get "/auth/cddo_sso" | ||
|
||
expect(response).to redirect_to("/auth/cddo_sso/callback") | ||
|
||
get "/auth/cddo_sso/callback" | ||
|
||
expect(request.env["warden"].authenticated?).to be true | ||
end | ||
end | ||
|
||
describe "signing out" do | ||
before do | ||
OmniAuth.config.mock_auth[:cddo_sso] = omniauth_hash | ||
get "/auth/cddo_sso" | ||
get "/auth/cddo_sso/callback" | ||
end | ||
|
||
it "signs the user out of sso.service.security.gov.uk" do | ||
allow(Settings.cddo_sso).to receive(:identifier).and_return("baz") | ||
|
||
get sign_out_path | ||
|
||
expect(response).to redirect_to("https://sso.service.security.gov.uk/sign-out?from_app=baz") | ||
end | ||
end | ||
|
||
describe User do | ||
describe ".find_for_auth" do | ||
it "is called by the cddo_sso Warden strategy" do | ||
allow(described_class).to receive(:find_for_auth).and_call_original | ||
|
||
OmniAuth.config.mock_auth[:cddo_sso] = omniauth_hash | ||
get "/auth/cddo_sso" | ||
get "/auth/cddo_sso/callback" | ||
|
||
expect(described_class).to have_received(:find_for_auth).with( | ||
provider: "cddo_sso", | ||
uid: "123456", | ||
email: "[email protected]", | ||
name: "Test User", | ||
) | ||
|
||
expect(request.env["warden"].winning_strategy.successful?).to be true | ||
end | ||
end | ||
end | ||
end |