diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-10-14 20:52:52 +1300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-10-14 20:52:52 +1300 |
commit | a9b8affb12cad2dd790ffc2feba997315aa2d5a4 (patch) | |
tree | 36e271187a4b7974e966ad360c819107d2165a39 /spec/controllers | |
parent | f714634ebc14d16d501420b1975b545aa36d1479 (diff) | |
download | gitlab-ce-extract_gcp_from_controller.tar.gz |
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/concerns/gcp_session_spec.rb | 68 | ||||
-rw-r--r-- | spec/controllers/projects/clusters_controller_spec.rb | 83 |
2 files changed, 86 insertions, 65 deletions
diff --git a/spec/controllers/concerns/gcp_session_spec.rb b/spec/controllers/concerns/gcp_session_spec.rb new file mode 100644 index 00000000000..8b57a404092 --- /dev/null +++ b/spec/controllers/concerns/gcp_session_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +# extract new and create_gcp, create_user ? + +require 'spec_helper' + +describe GcpSession do + controller(ApplicationController) do + # `described_class` is not available in this context + include GcpSession # rubocop:disable RSpec/DescribedClass + end + + describe '#token_in_session' do + subject { controller_class.new.token_in_session } + + it 'runs' do + subject + end + end + + describe '#validated_gcp_token' do + context 'when access token is expired' do + before do + stub_google_api_expired_token + end + + it { expect(@valid_gcp_token).to be_falsey } + end + + context 'when access token is not stored in session' do + it { expect(@valid_gcp_token).to be_falsey } + end + end + + describe '#gcp_authorize_url' do + context 'when omniauth has been configured' do + let(:key) { 'secret-key' } + let(:session_key_for_redirect_uri) do + GoogleApi::CloudPlatform::Client.session_key_for_redirect_uri(key) + end + + before do + allow(SecureRandom).to receive(:hex).and_return(key) + end + + it 'has authorize_url' do + go + + expect(assigns(:authorize_url)).to include(key) + expect(session[session_key_for_redirect_uri]).to eq(new_project_cluster_path(project)) + end + end + + context 'when omniauth has not configured' do + before do + stub_omniauth_setting(providers: []) + end + + it 'does not have authorize_url' do + go + + expect(assigns(:authorize_url)).to be_nil + end + end + end + + +end diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index 3773b29e5cd..deaa48b36f2 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -83,58 +83,16 @@ describe Projects::ClustersController do sign_in(user) end - context 'when omniauth has been configured' do - let(:key) { 'secret-key' } - let(:session_key_for_redirect_uri) do - GoogleApi::CloudPlatform::Client.session_key_for_redirect_uri(key) - end - - before do - allow(SecureRandom).to receive(:hex).and_return(key) - end - - it 'has authorize_url' do - go - - expect(assigns(:authorize_url)).to include(key) - expect(session[session_key_for_redirect_uri]).to eq(new_project_cluster_path(project)) - end - end - - context 'when omniauth has not configured' do - before do - stub_omniauth_setting(providers: []) - end - - it 'does not have authorize_url' do - go + it 'has new object' do + go - expect(assigns(:authorize_url)).to be_nil - end + expect(assigns(:gcp_cluster)).to be_an_instance_of(Clusters::Cluster) end - context 'when access token is valid' do - before do - stub_google_api_validate_token - end - - it 'has new object' do - go - - expect(assigns(:gcp_cluster)).to be_an_instance_of(Clusters::Cluster) - end - end - - context 'when access token is expired' do - before do - stub_google_api_expired_token - end - - it { expect(@valid_gcp_token).to be_falsey } - end + it 'sets the redirect url after google authorization' do + go - context 'when access token is not stored in session' do - it { expect(@valid_gcp_token).to be_falsey } + expect(assigns(:redirect_after_authorize_url)).to eq new_project_cluster_path(project) end end @@ -192,10 +150,6 @@ describe Projects::ClustersController do end context 'when access token is valid' do - before do - stub_google_api_validate_token - end - it 'creates a new cluster' do expect(ClusterProvisionWorker).to receive(:perform_async) expect { go }.to change { Clusters::Cluster.count } @@ -228,19 +182,13 @@ describe Projects::ClustersController do expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template(:new) end - end - end - - context 'when access token is expired' do - before do - stub_google_api_expired_token - end - it { expect(@valid_gcp_token).to be_falsey } - end + it 'sets the redirect url after google authorization' do + go - context 'when access token is not stored in session' do - it { expect(@valid_gcp_token).to be_falsey } + expect(assigns(:redirect_after_authorize_url)).to eq new_project_cluster_path(project) + end + end end end @@ -248,8 +196,7 @@ describe Projects::ClustersController do before do allow_any_instance_of(described_class) .to receive(:token_in_session).and_return('token') - allow_any_instance_of(described_class) - .to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s) + allow_any_instance_of(GoogleApi::CloudPlatform::Client) .to receive(:projects_zones_clusters_create) do OpenStruct.new( @@ -323,6 +270,12 @@ describe Projects::ClustersController do expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template(:new) end + + it 'sets the redirect url after google authorization' do + go + + expect(assigns(:redirect_after_authorize_url)).to eq new_project_cluster_path(project) + end end context 'when creates a RBAC-enabled cluster' do |