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
def auth
oauth = Gitlab::Geo::OauthSession.new(state: params[:state])
unless oauth.is_oauth_state_valid?
unless oauth.oauth_state_valid?
redirect_to root_url
return
end
......@@ -14,7 +14,7 @@ class Oauth::GeoAuthController < ActionController::Base
def callback
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
return
end
......
......@@ -7,7 +7,7 @@ module Gitlab
attr_accessor :state
attr_accessor :return_to
def is_oauth_state_valid?
def oauth_state_valid?
return false unless state
salt, hmac, return_to = state.split(':', 3)
......
......@@ -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) }
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
expect(response).to redirect_to(root_url)
......@@ -40,7 +40,7 @@ describe Oauth::GeoAuthController do
end
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
expect(response).to redirect_to(new_user_session_path)
......
......@@ -14,24 +14,24 @@ describe Gitlab::Geo::OauthSession do
allow(subject).to receive(:primary_node_url) { 'http://localhost:3001/' }
end
describe '#is_oauth_state_valid?' do
describe '#oauth_state_valid?' 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
it 'returns false when return_to cannot be retrieved' do
subject.state = 'invalidstate'
expect(subject.is_oauth_state_valid?).to be_falsey
expect(subject.oauth_state_valid?).to be_falsey
end
it 'returns false when hmac does not match' do
subject.state = dummy_state
expect(subject.is_oauth_state_valid?).to be_falsey
expect(subject.oauth_state_valid?).to be_falsey
end
it 'returns true when hmac matches generated one' do
subject.state = valid_state
expect(subject.is_oauth_state_valid?).to be_truthy
expect(subject.oauth_state_valid?).to be_truthy
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