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>2021-02-02 09:09:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-02 09:09:47 +0300
commitbcd0f3a2f6bd59a9de40f5a9f2829cec3d456207 (patch)
tree61512d781122c114e0049971264f031845a857a1 /spec
parent7580728fc297c86cc5a31fb67e7153217facf1c0 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/experiments/application_experiment_spec.rb14
-rw-r--r--spec/requests/api/deploy_tokens_spec.rb16
-rw-r--r--spec/tasks/gitlab/password_rake_spec.rb76
3 files changed, 90 insertions, 16 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb
index 76fdcd222d1..5c5f563a803 100644
--- a/spec/experiments/application_experiment_spec.rb
+++ b/spec/experiments/application_experiment_spec.rb
@@ -5,6 +5,14 @@ require 'spec_helper'
RSpec.describe ApplicationExperiment, :experiment do
subject { described_class.new(:stub) }
+ let(:feature_definition) { { name: 'stub', type: 'experiment', group: 'group::adoption', default_enabled: false } }
+
+ around do |example|
+ Feature::Definition.definitions[:stub] = Feature::Definition.new('stub.yml', feature_definition)
+ example.run
+ Feature::Definition.definitions.delete(:stub)
+ end
+
before do
allow(subject).to receive(:enabled?).and_return(true)
end
@@ -105,6 +113,12 @@ RSpec.describe ApplicationExperiment, :experiment do
end
describe "variant resolution" do
+ it "uses the default value as specified in the yaml" do
+ expect(Feature).to receive(:enabled?).with('stub', subject, type: :experiment, default_enabled: :yaml)
+
+ expect(subject.variant.name).to eq('control')
+ end
+
it "returns nil when not rolled out" do
stub_feature_flags(stub: false)
diff --git a/spec/requests/api/deploy_tokens_spec.rb b/spec/requests/api/deploy_tokens_spec.rb
index 8ec4f888e2e..7a31ff725c8 100644
--- a/spec/requests/api/deploy_tokens_spec.rb
+++ b/spec/requests/api/deploy_tokens_spec.rb
@@ -10,24 +10,12 @@ RSpec.describe API::DeployTokens do
let!(:deploy_token) { create(:deploy_token, projects: [project]) }
let!(:group_deploy_token) { create(:deploy_token, :group, groups: [group]) }
- shared_examples 'with feature flag disabled' do
- context 'disabled feature flag' do
- before do
- stub_feature_flags(deploy_tokens_api: false)
- end
-
- it { is_expected.to have_gitlab_http_status(:service_unavailable) }
- end
- end
-
describe 'GET /deploy_tokens' do
subject do
get api('/deploy_tokens', user)
response
end
- it_behaves_like 'with feature flag disabled'
-
context 'when unauthenticated' do
let(:user) { nil }
@@ -81,8 +69,6 @@ RSpec.describe API::DeployTokens do
project.add_maintainer(user)
end
- it_behaves_like 'with feature flag disabled'
-
it { is_expected.to have_gitlab_http_status(:ok) }
it 'returns all deploy tokens for the project' do
@@ -128,8 +114,6 @@ RSpec.describe API::DeployTokens do
group.add_maintainer(user)
end
- it_behaves_like 'with feature flag disabled'
-
it { is_expected.to have_gitlab_http_status(:ok) }
it 'returns all deploy tokens for the group' do
diff --git a/spec/tasks/gitlab/password_rake_spec.rb b/spec/tasks/gitlab/password_rake_spec.rb
new file mode 100644
index 00000000000..d5320f3b4af
--- /dev/null
+++ b/spec/tasks/gitlab/password_rake_spec.rb
@@ -0,0 +1,76 @@
+# frozen_string_literal: true
+
+require 'rake_helper'
+
+RSpec.describe 'gitlab:password rake tasks' do
+ let_it_be(:user_1) { create(:user, username: 'foobar', password: 'initial_password') }
+
+ def stub_username(username)
+ allow(Gitlab::TaskHelpers).to receive(:prompt).with('Enter username: ').and_return(username)
+ end
+
+ def stub_password(password, confirmation = nil)
+ confirmation ||= password
+ allow(Gitlab::TaskHelpers).to receive(:prompt_for_password).and_return(password)
+ allow(Gitlab::TaskHelpers).to receive(:prompt_for_password).with('Confirm password: ').and_return(confirmation)
+ end
+
+ before do
+ Rake.application.rake_require 'tasks/gitlab/password'
+
+ stub_username('foobar')
+ stub_password('secretpassword')
+ end
+
+ describe ':reset' do
+ context 'when all inputs are correct' do
+ it 'updates the password properly' do
+ run_rake_task('gitlab:password:reset', user_1.username)
+ expect(user_1.reload.valid_password?('secretpassword')).to eq(true)
+ end
+ end
+
+ context 'when username is not provided' do
+ it 'asks for username' do
+ expect(Gitlab::TaskHelpers).to receive(:prompt).with('Enter username: ')
+
+ run_rake_task('gitlab:password:reset')
+ end
+
+ context 'when username is empty' do
+ it 'aborts with an error' do
+ stub_username('')
+ expect { run_rake_task('gitlab:password:reset') }.to raise_error(/Username can not be empty./)
+ end
+ end
+ end
+
+ context 'when username is passed as argument' do
+ it 'does not ask for username' do
+ expect(Gitlab::TaskHelpers).not_to receive(:prompt)
+
+ run_rake_task('gitlab:password:reset', 'foobar')
+ end
+ end
+
+ context 'when passwords do not match' do
+ before do
+ stub_password('randompassword', 'differentpassword')
+ end
+
+ it 'aborts with an error' do
+ expect { run_rake_task('gitlab:password:reset') }.to raise_error(%r{Unable to change password of the user with username foobar.\nPassword confirmation doesn't match Password})
+ end
+ end
+
+ context 'when user cannot be found' do
+ before do
+ stub_username('nonexistentuser')
+ end
+
+ it 'aborts with an error' do
+ expect { run_rake_task('gitlab:password:reset') }.to raise_error(/Unable to find user with username nonexistentuser./)
+ end
+ end
+ end
+end