diff options
| author | Shinya Maeda <shinya@gitlab.com> | 2017-10-05 21:29:22 +0900 |
|---|---|---|
| committer | Shinya Maeda <shinya@gitlab.com> | 2017-10-05 21:29:22 +0900 |
| commit | fe135fac68fab5e2a15e7aaa250ae91cd7fa4851 (patch) | |
| tree | 576f7033950cb887b5c9013854a862bb12ae7485 /spec | |
| parent | b229637b0837065a9993d06573b41218ab7e9dfb (diff) | |
| download | gitlab-ce-fe135fac68fab5e2a15e7aaa250ae91cd7fa4851.tar.gz | |
authorizations_controller_spec. cluster_policy_spec.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/google_api/authorizations_controller_spec.rb | 43 | ||||
| -rw-r--r-- | spec/policies/gcp/cluster_policy_spec.rb | 28 |
2 files changed, 71 insertions, 0 deletions
diff --git a/spec/controllers/google_api/authorizations_controller_spec.rb b/spec/controllers/google_api/authorizations_controller_spec.rb new file mode 100644 index 00000000000..53d584d167c --- /dev/null +++ b/spec/controllers/google_api/authorizations_controller_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe GoogleApi::AuthorizationsController do + describe 'GET|POST #callback' do + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:state) { namespace_project_clusters_url(project.namespace, project).to_s } + let(:token) { 'token' } + let(:expires_at) { 1.hour.since.strftime('%s') } + + subject { get :callback, code: 'xxx', state: state } + + before do + sign_in(user) + + allow_any_instance_of(GoogleApi::CloudPlatform::Client) + .to receive(:get_token).and_return([token, expires_at]) + end + + it 'sets token and expires_atin session' do + subject + + expect(session[GoogleApi::CloudPlatform::Client.session_key_for_token]) + .to eq(token) + expect(session[GoogleApi::CloudPlatform::Client.session_key_for_expires_at]) + .to eq(expires_at) + end + + context 'when redirection url is stored in state' do + it 'redirects to the URL stored in state param' do + expect(subject).to redirect_to(state) + end + end + + context 'when redirection url is not stored in state' do + let(:state) { '' } + + it 'redirects to root_path' do + expect(subject).to redirect_to(root_path) + end + end + end +end diff --git a/spec/policies/gcp/cluster_policy_spec.rb b/spec/policies/gcp/cluster_policy_spec.rb new file mode 100644 index 00000000000..e213aa3d557 --- /dev/null +++ b/spec/policies/gcp/cluster_policy_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Gcp::ClusterPolicy, :models do + set(:project) { create(:project) } + set(:cluster) { create(:gcp_cluster, project: project) } + let(:user) { create(:user) } + let(:policy) { described_class.new(user, cluster) } + + describe 'rules' do + context 'when developer' do + before do + project.add_developer(user) + end + + it { expect(policy).to be_disallowed :update_cluster } + it { expect(policy).to be_disallowed :admin_cluster } + end + + context 'when master' do + before do + project.add_master(user) + end + + it { expect(policy).to be_allowed :update_cluster } + it { expect(policy).to be_allowed :admin_cluster } + end + end +end |
