Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-14 03:10:41 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-14 03:10:41 +0300
commitdcd075c981ad8efcdf6206f67e1c82c6ab4b3152 (patch)
treeabddfa196c5972b62eb20259df5f7e2f1cabcac3 /spec
parent9f4c898b9d7243343ab321227e9cfbfa8babedfe (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/import/github_controller_spec.rb64
-rw-r--r--spec/initializers/100_patch_omniauth_oauth2_spec.rb2
-rw-r--r--spec/lib/gitlab/auth_spec.rb6
-rw-r--r--spec/lib/gitlab/ci/variables/builder/release_spec.rb13
-rw-r--r--spec/requests/import/github_groups_controller_spec.rb69
-rw-r--r--spec/routing/import_routing_spec.rb7
-rw-r--r--spec/serializers/import/github_org_entity_spec.rb25
-rw-r--r--spec/serializers/import/github_org_serializer_spec.rb47
-rw-r--r--spec/services/users/destroy_service_spec.rb15
9 files changed, 228 insertions, 20 deletions
diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb
index 592e2b44192..f3632e7370c 100644
--- a/spec/controllers/import/github_controller_spec.rb
+++ b/spec/controllers/import/github_controller_spec.rb
@@ -44,13 +44,6 @@ RSpec.describe Import::GithubController do
end
describe "GET callback" do
- before do
- allow(controller).to receive(:get_token).and_return(token)
- allow(controller).to receive(:oauth_options).and_return({})
-
- stub_omniauth_provider('github')
- end
-
context "when auth state param is missing from session" do
it "reports an error" do
get :callback
@@ -63,17 +56,31 @@ RSpec.describe Import::GithubController do
context "when auth state param is present in session" do
let(:valid_auth_state) { "secret-state" }
- before do
- session[:github_auth_state_key] = valid_auth_state
- end
+ context 'when remove_legacy_github_client feature is disabled' do
+ before do
+ stub_feature_flags(remove_legacy_github_client: false)
+ allow_next_instance_of(Gitlab::LegacyGithubImport::Client) do |client|
+ allow(client).to receive(:get_token).and_return(token)
+ end
+ session[:github_auth_state_key] = valid_auth_state
+ end
- it "updates access token if state param is valid" do
- token = "asdasd12345"
+ it "updates access token if state param is valid" do
+ token = "asdasd12345"
+
+ get :callback, params: { state: valid_auth_state }
+
+ expect(session[:github_access_token]).to eq(token)
+ expect(controller).to redirect_to(status_import_github_url)
+ end
- get :callback, params: { state: valid_auth_state }
+ it "includes namespace_id from query params if it is present" do
+ namespace_id = 1
- expect(session[:github_access_token]).to eq(token)
- expect(controller).to redirect_to(status_import_github_url)
+ 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
end
it "reports an error if state param is invalid" do
@@ -83,12 +90,31 @@ RSpec.describe Import::GithubController do
expect(flash[:alert]).to eq('Access denied to your GitHub account.')
end
- it "includes namespace_id from query params if it is present" do
- namespace_id = 1
+ context 'when remove_legacy_github_client feature is enabled' do
+ before do
+ stub_feature_flags(remove_legacy_github_client: true)
+ allow_next_instance_of(OAuth2::Client) do |client|
+ allow(client).to receive_message_chain(:auth_code, :get_token, :token).and_return(token)
+ end
+ session[:github_auth_state_key] = valid_auth_state
+ end
+
+ it "updates access token if state param is valid" do
+ token = "asdasd12345"
- get :callback, params: { state: valid_auth_state, namespace_id: namespace_id }
+ get :callback, params: { state: valid_auth_state }
- expect(controller).to redirect_to(status_import_github_url(namespace_id: namespace_id))
+ expect(session[:github_access_token]).to eq(token)
+ expect(controller).to redirect_to(status_import_github_url)
+ end
+
+ it "includes namespace_id from query params if it is present" do
+ namespace_id = 1
+
+ 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
end
end
end
diff --git a/spec/initializers/100_patch_omniauth_oauth2_spec.rb b/spec/initializers/100_patch_omniauth_oauth2_spec.rb
index 36a14816b7e..8c8e2b24484 100644
--- a/spec/initializers/100_patch_omniauth_oauth2_spec.rb
+++ b/spec/initializers/100_patch_omniauth_oauth2_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe 'OmniAuth::Strategies::OAuth2' do
it 'verifies the gem version' do
current_version = OmniAuth::OAuth2::VERSION
- expected_version = '1.7.3'
+ expected_version = '1.8.0'
expect(current_version).to eq(expected_version), <<~EOF
New version #{current_version} of the `omniauth-oauth2` gem detected!
diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb
index c2d64aa2fb3..5a6fa7c416b 100644
--- a/spec/lib/gitlab/auth_spec.rb
+++ b/spec/lib/gitlab/auth_spec.rb
@@ -495,6 +495,12 @@ RSpec.describe Gitlab::Auth, :use_clean_rails_memory_store_caching do
end
end
end
+
+ it 'updates last_used_at column if token is valid' do
+ personal_access_token = create(:personal_access_token, scopes: ['write_repository'])
+
+ expect { gl_auth.find_for_git_client('', personal_access_token.token, project: nil, ip: 'ip') }.to change { personal_access_token.reload.last_used_at }
+ end
end
context 'while using regular user and password' do
diff --git a/spec/lib/gitlab/ci/variables/builder/release_spec.rb b/spec/lib/gitlab/ci/variables/builder/release_spec.rb
index 8934ea06962..85b1659d07b 100644
--- a/spec/lib/gitlab/ci/variables/builder/release_spec.rb
+++ b/spec/lib/gitlab/ci/variables/builder/release_spec.rb
@@ -39,6 +39,19 @@ RSpec.describe Gitlab::Ci::Variables::Builder::Release do
expect(subject['CI_RELEASE_DESCRIPTION'].value.length).to eq(1024)
end
end
+
+ context 'when description is nil' do
+ before do
+ release.update_attribute(:description, nil)
+ end
+
+ it 'returns without error' do
+ builder = subject
+
+ expect(builder).to match_array([])
+ expect(builder.errors).to be_nil
+ end
+ end
end
context 'when the release is not present' do
diff --git a/spec/requests/import/github_groups_controller_spec.rb b/spec/requests/import/github_groups_controller_spec.rb
new file mode 100644
index 00000000000..544cbf88cd2
--- /dev/null
+++ b/spec/requests/import/github_groups_controller_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Import::GithubGroupsController do
+ describe 'GET status' do
+ subject(:status) { get '/import/github_group/status', params: params, headers: headers }
+
+ let_it_be(:user) { create(:user) }
+ let(:headers) { { 'Accept' => 'application/json' } }
+ let(:params) { {} }
+
+ before do
+ login_as(user)
+ end
+
+ context 'when OAuth config is missing' do
+ before do
+ allow(Gitlab::Auth::OAuth::Provider).to receive(:config_for).with('github').and_return(nil)
+ end
+
+ it 'returns missing config error' do
+ status
+
+ expect(json_response['errors']).to eq('Missing OAuth configuration for GitHub.')
+ end
+ end
+
+ context 'when OAuth config present' do
+ let(:github_access_token) { 'asdasd12345' }
+
+ before do
+ post '/import/github/personal_access_token', params: { personal_access_token: github_access_token }
+ end
+
+ it 'fetches organizations' do
+ expect_next_instance_of(Octokit::Client) do |client|
+ expect(client).to receive(:organizations).and_return([].to_enum)
+ end
+
+ status
+ end
+
+ context 'with pagination' do
+ context 'when no page is specified' do
+ it 'requests first page' do
+ expect_next_instance_of(Octokit::Client) do |client|
+ expect(client).to receive(:organizations).with(nil, { page: 1, per_page: 25 }).and_return([].to_enum)
+ end
+
+ status
+ end
+ end
+
+ context 'when page is specified' do
+ let(:params) { { page: 2 } }
+
+ it 'responds with organizations with specified page' do
+ expect_next_instance_of(Octokit::Client) do |client|
+ expect(client).to receive(:organizations).with(nil, { page: 2, per_page: 25 }).and_return([].to_enum)
+ end
+
+ status
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/routing/import_routing_spec.rb b/spec/routing/import_routing_spec.rb
index b1da2eaa33b..b63ae1e7e4e 100644
--- a/spec/routing/import_routing_spec.rb
+++ b/spec/routing/import_routing_spec.rb
@@ -177,3 +177,10 @@ RSpec.describe Import::PhabricatorController, 'routing' do
expect(get("/import/phabricator/new")).to route_to("import/phabricator#new")
end
end
+
+# status_import_github_group GET /import/github_group/status(.:format) import/github_groups#status
+RSpec.describe Import::GithubGroupsController, 'routing' do
+ it 'to #status' do
+ expect(get('/import/github_group/status')).to route_to('import/github_groups#status')
+ end
+end
diff --git a/spec/serializers/import/github_org_entity_spec.rb b/spec/serializers/import/github_org_entity_spec.rb
new file mode 100644
index 00000000000..46fceb8ac60
--- /dev/null
+++ b/spec/serializers/import/github_org_entity_spec.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Import::GithubOrgEntity do
+ let(:org_data) do
+ {
+ 'id' => 12345,
+ 'login' => 'org-name',
+ 'url' => 'https://api.github.com/orgs/org-name',
+ 'avatar_url' => 'https://avatars.githubusercontent.com/u/12345?v=4',
+ 'node_id' => 'O_teStT',
+ 'description' => ''
+ }
+ end
+
+ subject { described_class.new(org_data).as_json }
+
+ it 'exposes correct attributes' do
+ expect(subject.keys).to contain_exactly(
+ :description,
+ :name
+ )
+ end
+end
diff --git a/spec/serializers/import/github_org_serializer_spec.rb b/spec/serializers/import/github_org_serializer_spec.rb
new file mode 100644
index 00000000000..4206914cd6e
--- /dev/null
+++ b/spec/serializers/import/github_org_serializer_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Import::GithubOrgSerializer do
+ it 'represents GithubOrgEntity entities' do
+ expect(described_class.entity_class).to eq(Import::GithubOrgEntity)
+ end
+
+ describe '#represent' do
+ let(:org_data) do
+ {
+ id: 123456,
+ login: 'org-name',
+ node_id: 'O_teStT',
+ url: 'https://api.github.com/orgs/org-name',
+ repos_url: 'https://api.github.com/orgs/org-name/repos',
+ events_url: 'https://api.github.com/orgs/org-name/events',
+ hooks_url: 'https://api.github.com/orgs/org-name/hooks',
+ issues_url: 'https://api.github.com/orgs/org-name/issues',
+ members_url: 'https://api.github.com/orgs/org-name/members{/member}',
+ public_members_url: 'https://api.github.com/orgs/org-name/public_members{/member}',
+ avatar_url: 'avatar_url',
+ description: 'description'
+ }
+ end
+
+ subject { described_class.new.represent(resource) }
+
+ context 'when a single object is being serialized' do
+ let(:resource) { org_data }
+
+ it 'serializes organization object' do
+ expect(subject).to eq({ name: 'org-name', description: 'description' })
+ end
+ end
+
+ context 'when multiple objects are being serialized' do
+ let(:count) { 3 }
+ let(:resource) { Array.new(count, org_data) }
+
+ it 'serializes array of organizations' do
+ expect(subject).to all(eq({ name: 'org-name', description: 'description' }))
+ end
+ end
+ end
+end
diff --git a/spec/services/users/destroy_service_spec.rb b/spec/services/users/destroy_service_spec.rb
index b32599d4af8..c8ea7f704e2 100644
--- a/spec/services/users/destroy_service_spec.rb
+++ b/spec/services/users/destroy_service_spec.rb
@@ -407,6 +407,21 @@ RSpec.describe Users::DestroyService do
expect(issue.updated_by).to be_nil
expect(resource_label_event.user).to be_nil
end
+
+ it 'nullifies assigned_merge_requests, last_updated_merge_requests' do
+ merge_request = create(:merge_request, source_project: project, target_project: project,
+ assignee: other_user, updated_by: other_user, merge_user: other_user)
+
+ described_class.new(user).execute(other_user, skip_authorization: true)
+
+ merge_request.reload
+
+ aggregate_failures do
+ expect(merge_request.updated_by).to be_nil
+ expect(merge_request.assignee).to be_nil
+ expect(merge_request.assignee_id).to be_nil
+ end
+ end
end
end