-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirects user to the original page they were targeting (#191)
- Loading branch information
Showing
4 changed files
with
56 additions
and
40 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,53 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe OmniauthCallbacksController do | ||
before do | ||
User.create(provider: 'shibboleth', | ||
uid: 'brianbboys1967', | ||
display_name: 'Brian Wilson') | ||
request.env["devise.mapping"] = Devise.mappings[:user] | ||
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:shib] | ||
post :shibboleth | ||
end | ||
OmniAuth.config.mock_auth[:shib] = | ||
OmniAuth::AuthHash.new( | ||
provider: 'shibboleth', | ||
uid: "P0000001", | ||
info: { | ||
display_name: "Brian Wilson", | ||
uid: 'brianbboys1967' | ||
} | ||
) | ||
|
||
context "when origin is present" do | ||
before do | ||
request.env["omniauth.origin"] = '/example' | ||
post :shibboleth | ||
end | ||
|
||
it "redirects to origin" do | ||
expect(response.redirect_url).to eq 'http://test.host/example' | ||
end | ||
end | ||
|
||
context "when origin is missing" do | ||
it "redirects to home" do | ||
expect(response.redirect_url).to include 'http://test.host/' | ||
end | ||
end | ||
|
||
it "sets a cookie" do | ||
expect(response.cookies).to include "bearer_token" | ||
expect(decrypt_string(response.cookies["bearer_token"])).to eq 1.day.from_now.to_s | ||
end | ||
|
||
def decrypt_string(encrypted_str) | ||
cipher_salt1 = ENV["IIIF_COOKIE_SALT_1"] || 'some-random-salt-' | ||
cipher_salt2 = ENV["IIIF_COOKIE_SALT_2"] || 'another-random-salt-' | ||
cipher = OpenSSL::Cipher.new('AES-128-ECB').decrypt | ||
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(cipher_salt1, cipher_salt2, 20_000, cipher.key_len) | ||
decrypted = [encrypted_str].pack('H*').unpack('C*').pack('c*') | ||
cipher.update(decrypted) + cipher.final | ||
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 was deleted.
Oops, something went wrong.