forked from lynndylanhurley/devise_token_auth
-
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.
Merge pull request lynndylanhurley#699 from lynndylanhurley/oauth_red…
…irect_whitelist Apply `redirect_whitelist` to OAuth redirect URI.
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -279,4 +279,46 @@ def get_success(params = {}) | |
} | ||
end | ||
end | ||
|
||
describe 'Using redirect_whitelist' do | ||
before do | ||
@user_email = '[email protected]' | ||
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new( | ||
provider: 'facebook', | ||
uid: '123545', | ||
info: { | ||
name: 'chong', | ||
email: @user_email | ||
} | ||
) | ||
@good_redirect_url = Faker::Internet.url | ||
@bad_redirect_url = Faker::Internet.url | ||
DeviseTokenAuth.redirect_whitelist = [@good_redirect_url] | ||
end | ||
|
||
teardown do | ||
DeviseTokenAuth.redirect_whitelist = nil | ||
end | ||
|
||
test 'request using non-whitelisted redirect fail' do | ||
get_via_redirect '/auth/facebook', | ||
auth_origin_url: @bad_redirect_url, | ||
omniauth_window_type: 'newWindow' | ||
|
||
data_json = @response.body.match(/var data \= (.+)\;/)[1] | ||
data = ActiveSupport::JSON.decode(data_json) | ||
assert_equal "Redirect to '#{@bad_redirect_url}' not allowed.", | ||
data['error'] | ||
end | ||
|
||
test 'request to whitelisted redirect should succeed' do | ||
get_via_redirect '/auth/facebook', | ||
auth_origin_url: @good_redirect_url, | ||
omniauth_window_type: 'newWindow' | ||
|
||
data_json = @response.body.match(/var data \= (.+)\;/)[1] | ||
data = ActiveSupport::JSON.decode(data_json) | ||
assert_equal @user_email, data['email'] | ||
end | ||
end | ||
end |