Commit 388e07e1 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Fix rubocop offense

parent b05f4a56
...@@ -4,7 +4,7 @@ class Oauth::GeoAuthController < ActionController::Base ...@@ -4,7 +4,7 @@ class Oauth::GeoAuthController < ActionController::Base
def auth def auth
oauth = Gitlab::Geo::OauthSession.new(state: params[:state]) oauth = Gitlab::Geo::OauthSession.new(state: params[:state])
unless oauth.is_oauth_state_valid? unless oauth.oauth_state_valid?
redirect_to root_url redirect_to root_url
return return
end end
...@@ -14,7 +14,7 @@ class Oauth::GeoAuthController < ActionController::Base ...@@ -14,7 +14,7 @@ class Oauth::GeoAuthController < ActionController::Base
def callback def callback
oauth = Gitlab::Geo::OauthSession.new(state: params[:state]) oauth = Gitlab::Geo::OauthSession.new(state: params[:state])
unless oauth.is_oauth_state_valid? unless oauth.oauth_state_valid?
redirect_to new_user_session_path redirect_to new_user_session_path
return return
end end
......
...@@ -7,7 +7,7 @@ module Gitlab ...@@ -7,7 +7,7 @@ module Gitlab
attr_accessor :state attr_accessor :state
attr_accessor :return_to attr_accessor :return_to
def is_oauth_state_valid? def oauth_state_valid?
return false unless state return false unless state
salt, hmac, return_to = state.split(':', 3) salt, hmac, return_to = state.split(':', 3)
......
...@@ -16,7 +16,7 @@ describe Oauth::GeoAuthController do ...@@ -16,7 +16,7 @@ describe Oauth::GeoAuthController do
let(:primary_node_oauth_endpoint) { Gitlab::Geo::OauthSession.new.authorize_url(redirect_uri: oauth_geo_callback_url, state: auth_state) } let(:primary_node_oauth_endpoint) { Gitlab::Geo::OauthSession.new.authorize_url(redirect_uri: oauth_geo_callback_url, state: auth_state) }
it 'redirects to root_url when state is invalid' do it 'redirects to root_url when state is invalid' do
allow_any_instance_of(Gitlab::Geo::OauthSession).to receive(:is_oauth_state_valid?) { false } allow_any_instance_of(Gitlab::Geo::OauthSession).to receive(:oauth_state_valid?) { false }
get :auth, state: auth_state get :auth, state: auth_state
expect(response).to redirect_to(root_url) expect(response).to redirect_to(root_url)
...@@ -40,7 +40,7 @@ describe Oauth::GeoAuthController do ...@@ -40,7 +40,7 @@ describe Oauth::GeoAuthController do
end end
it 'redirects to login screen if state is invalid' do it 'redirects to login screen if state is invalid' do
allow_any_instance_of(Gitlab::Geo::OauthSession).to receive(:is_oauth_state_valid?) { false } allow_any_instance_of(Gitlab::Geo::OauthSession).to receive(:oauth_state_valid?) { false }
get :callback, state: callback_state get :callback, state: callback_state
expect(response).to redirect_to(new_user_session_path) expect(response).to redirect_to(new_user_session_path)
......
...@@ -14,24 +14,24 @@ describe Gitlab::Geo::OauthSession do ...@@ -14,24 +14,24 @@ describe Gitlab::Geo::OauthSession do
allow(subject).to receive(:primary_node_url) { 'http://localhost:3001/' } allow(subject).to receive(:primary_node_url) { 'http://localhost:3001/' }
end end
describe '#is_oauth_state_valid?' do describe '#oauth_state_valid?' do
it 'returns false when state is not present' do it 'returns false when state is not present' do
expect(subject.is_oauth_state_valid?).to be_falsey expect(subject.oauth_state_valid?).to be_falsey
end end
it 'returns false when return_to cannot be retrieved' do it 'returns false when return_to cannot be retrieved' do
subject.state = 'invalidstate' subject.state = 'invalidstate'
expect(subject.is_oauth_state_valid?).to be_falsey expect(subject.oauth_state_valid?).to be_falsey
end end
it 'returns false when hmac does not match' do it 'returns false when hmac does not match' do
subject.state = dummy_state subject.state = dummy_state
expect(subject.is_oauth_state_valid?).to be_falsey expect(subject.oauth_state_valid?).to be_falsey
end end
it 'returns true when hmac matches generated one' do it 'returns true when hmac matches generated one' do
subject.state = valid_state subject.state = valid_state
expect(subject.is_oauth_state_valid?).to be_truthy expect(subject.oauth_state_valid?).to be_truthy
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment