diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-22 06:08:52 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-22 06:08:52 +0000 |
commit | 57b795ee00fbe7a17fa0ad2eb21987eab5fc4aa4 (patch) | |
tree | d88fdfb3b26c0309d4bc0331b4fdab41e2c886dc /spec/controllers | |
parent | 0c924987e1d6f0453eea407e227efd2122b760fd (diff) | |
download | gitlab-ce-57b795ee00fbe7a17fa0ad2eb21987eab5fc4aa4.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/import/bitbucket_controller_spec.rb | 29 | ||||
-rw-r--r-- | spec/controllers/import/github_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/controllers/import/gitlab_controller_spec.rb | 40 |
3 files changed, 57 insertions, 17 deletions
diff --git a/spec/controllers/import/bitbucket_controller_spec.rb b/spec/controllers/import/bitbucket_controller_spec.rb index 6d24830af27..7367970d3e4 100644 --- a/spec/controllers/import/bitbucket_controller_spec.rb +++ b/spec/controllers/import/bitbucket_controller_spec.rb @@ -45,18 +45,21 @@ RSpec.describe Import::BitbucketController do end context "when auth state param is valid" do + let(:expires_at) { Time.current + 1.day } + let(:expires_in) { 1.day } + let(:access_token) do + double(token: token, + secret: secret, + expires_at: expires_at, + expires_in: expires_in, + refresh_token: refresh_token) + end + before do session[:bitbucket_auth_state] = 'state' end it "updates access token" do - expires_at = Time.current + 1.day - expires_in = 1.day - access_token = double(token: token, - secret: secret, - expires_at: expires_at, - expires_in: expires_in, - refresh_token: refresh_token) allow_any_instance_of(OAuth2::Client) .to receive(:get_token) .with(hash_including( @@ -75,6 +78,18 @@ RSpec.describe Import::BitbucketController do expect(session[:bitbucket_expires_in]).to eq(expires_in) expect(controller).to redirect_to(status_import_bitbucket_url) end + + it "passes namespace_id query param to status if provided" do + namespace_id = 30 + + allow_any_instance_of(OAuth2::Client) + .to receive(:get_token) + .and_return(access_token) + + get :callback, params: { code: code, state: 'state', namespace_id: namespace_id } + + expect(controller).to redirect_to(status_import_bitbucket_url(namespace_id: namespace_id)) + end end end diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb index 56e55c45e66..46160aac0c1 100644 --- a/spec/controllers/import/github_controller_spec.rb +++ b/spec/controllers/import/github_controller_spec.rb @@ -83,11 +83,10 @@ RSpec.describe Import::GithubController do expect(flash[:alert]).to eq('Access denied to your GitHub account.') end - it "includes namespace_id from session if it is present" do + it "includes namespace_id from query params if it is present" do namespace_id = 1 - session[:namespace_id] = 1 - get :callback, params: { state: valid_auth_state } + get :callback, params: { state: valid_auth_state, namespace_id: namespace_id } expect(controller).to redirect_to(status_import_github_url(namespace_id: namespace_id)) end diff --git a/spec/controllers/import/gitlab_controller_spec.rb b/spec/controllers/import/gitlab_controller_spec.rb index 117c934ad5d..7b3978297fb 100644 --- a/spec/controllers/import/gitlab_controller_spec.rb +++ b/spec/controllers/import/gitlab_controller_spec.rb @@ -38,21 +38,47 @@ RSpec.describe Import::GitlabController do expect(controller.send(:importable_repos)).to be_an_instance_of(Array) end + + it "passes namespace_id query param to status if provided" do + namespace_id = 30 + + allow_next_instance_of(Gitlab::GitlabImport::Client) do |instance| + allow(instance).to receive(:get_token).and_return(token) + end + + get :callback, params: { namespace_id: namespace_id } + + expect(controller).to redirect_to(status_import_gitlab_url(namespace_id: namespace_id)) + end end describe "GET status" do let(:repo_fake) { Struct.new(:id, :path, :path_with_namespace, :web_url, keyword_init: true) } let(:repo) { repo_fake.new(id: 1, path: 'vim', path_with_namespace: 'asd/vim', web_url: 'https://gitlab.com/asd/vim') } - before do - assign_session_token + context 'when session contains access token' do + before do + assign_session_token + end + + it_behaves_like 'import controller status' do + let(:repo_id) { repo.id } + let(:import_source) { repo.path_with_namespace } + let(:provider_name) { 'gitlab' } + let(:client_repos_field) { :projects } + end end - it_behaves_like 'import controller status' do - let(:repo_id) { repo.id } - let(:import_source) { repo.path_with_namespace } - let(:provider_name) { 'gitlab' } - let(:client_repos_field) { :projects } + it 'redirects to auth if session does not contain access token' do + remote_gitlab_url = 'https://test.host/auth/gitlab' + + allow(Gitlab::GitlabImport::Client) + .to receive(:new) + .and_return(double(authorize_url: remote_gitlab_url)) + + get :status + + expect(response).to redirect_to(remote_gitlab_url) end end |