summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/error_tracking/list_projects_service_spec.rb30
-rw-r--r--spec/services/users/update_service_spec.rb43
-rw-r--r--spec/services/web_hook_service_spec.rb5
3 files changed, 71 insertions, 7 deletions
diff --git a/spec/services/error_tracking/list_projects_service_spec.rb b/spec/services/error_tracking/list_projects_service_spec.rb
index ce391bd1ca0..8408adcc21d 100644
--- a/spec/services/error_tracking/list_projects_service_spec.rb
+++ b/spec/services/error_tracking/list_projects_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe ErrorTracking::ListProjectsService do
+RSpec.describe ErrorTracking::ListProjectsService, feature_category: :integrations do
let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project) }
@@ -51,15 +51,33 @@ RSpec.describe ErrorTracking::ListProjectsService do
end
context 'masked param token' do
- let(:params) { ActionController::Parameters.new(token: "*********", api_host: new_api_host) }
+ let(:params) { ActionController::Parameters.new(token: "*********", api_host: api_host) }
- before do
- expect(error_tracking_setting).to receive(:list_sentry_projects)
+ context 'with the current api host' do
+ let(:api_host) { 'https://sentrytest.gitlab.com' }
+
+ before do
+ expect(error_tracking_setting).to receive(:list_sentry_projects)
.and_return({ projects: [] })
+ end
+
+ it 'uses database token' do
+ expect { subject.execute }.not_to change { error_tracking_setting.token }
+ end
end
- it 'uses database token' do
- expect { subject.execute }.not_to change { error_tracking_setting.token }
+ context 'with a new api host' do
+ let(:api_host) { new_api_host }
+
+ it 'returns an error' do
+ expect(result[:message]).to start_with('Token is a required field')
+ expect(error_tracking_setting).not_to be_valid
+ expect(error_tracking_setting).not_to receive(:list_sentry_projects)
+ end
+
+ it 'resets the token' do
+ expect { subject.execute }.to change { error_tracking_setting.token }.from(token).to(nil)
+ end
end
end
diff --git a/spec/services/users/update_service_spec.rb b/spec/services/users/update_service_spec.rb
index 411cd7316d8..f4ea757f81a 100644
--- a/spec/services/users/update_service_spec.rb
+++ b/spec/services/users/update_service_spec.rb
@@ -77,6 +77,34 @@ RSpec.describe Users::UpdateService do
subject
end
+ context 'when race condition' do
+ # See https://gitlab.com/gitlab-org/gitlab/-/issues/382957
+ it 'updates email for stale user', :aggregate_failures do
+ unconfirmed_email = 'unconfirmed-email-user-has-access-to@example.com'
+ forgery_email = 'forgery@example.com'
+
+ user.update!(email: unconfirmed_email)
+
+ stale_user = User.find(user.id)
+
+ service1 = described_class.new(stale_user, { email: unconfirmed_email }.merge(user: stale_user))
+
+ service2 = described_class.new(user, { email: forgery_email }.merge(user: user))
+
+ service2.execute
+ reloaded_user = User.find(user.id)
+ expect(reloaded_user.unconfirmed_email).to eq(forgery_email)
+ expect(stale_user.confirmation_token).not_to eq(user.confirmation_token)
+ expect(reloaded_user.confirmation_token).to eq(user.confirmation_token)
+
+ service1.execute
+ reloaded_user = User.find(user.id)
+ expect(reloaded_user.unconfirmed_email).to eq(unconfirmed_email)
+ expect(stale_user.confirmation_token).not_to eq(user.confirmation_token)
+ expect(reloaded_user.confirmation_token).to eq(stale_user.confirmation_token)
+ end
+ end
+
context 'when check_password is true' do
def update_user(user, opts)
described_class.new(user, opts.merge(user: user)).execute(check_password: true)
@@ -139,9 +167,24 @@ RSpec.describe Users::UpdateService do
update_user(user, job_title: 'supreme leader of the universe')
end.not_to change { user.user_canonical_email }
end
+
+ it 'does not reset unconfirmed email' do
+ unconfirmed_email = 'unconfirmed-email@example.com'
+ user.update!(email: unconfirmed_email)
+
+ expect do
+ update_user(user, job_title: 'supreme leader of the universe')
+ end.not_to change { user.unconfirmed_email }
+ end
end
end
+ it 'does not try to reset unconfirmed email for a new user' do
+ expect do
+ update_user(build(:user), job_title: 'supreme leader of the universe')
+ end.not_to raise_error
+ end
+
def update_user(user, opts)
described_class.new(user, opts.merge(user: user)).execute
end
diff --git a/spec/services/web_hook_service_spec.rb b/spec/services/web_hook_service_spec.rb
index c081b20d95f..4b925a058e7 100644
--- a/spec/services/web_hook_service_spec.rb
+++ b/spec/services/web_hook_service_spec.rb
@@ -129,7 +129,10 @@ RSpec.describe WebHookService, :request_store, :clean_gitlab_redis_shared_state
context 'there is userinfo' do
before do
- project_hook.update!(url: 'http://{one}:{two}@example.com')
+ project_hook.update!(
+ url: 'http://{one}:{two}@example.com',
+ url_variables: { 'one' => 'a', 'two' => 'b' }
+ )
stub_full_request('http://example.com', method: :post)
end