Commit a35195f4 authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'qa-ml-push-test-requires-admin' into 'master'

[QA] Test push limit with admin user

Closes gitlab-org/quality/staging#37

See merge request gitlab-org/gitlab-ce!29036
parents 8ac1ac2b cfe0043d
...@@ -10,13 +10,26 @@ module QA ...@@ -10,13 +10,26 @@ module QA
# The environment variables used to indicate if the environment under test # The environment variables used to indicate if the environment under test
# supports the given feature # supports the given feature
SUPPORTED_FEATURES = { SUPPORTED_FEATURES = {
git_protocol_v2: 'QA_CAN_TEST_GIT_PROTOCOL_V2' git_protocol_v2: 'QA_CAN_TEST_GIT_PROTOCOL_V2',
admin: 'QA_CAN_TEST_ADMIN_FEATURES'
}.freeze }.freeze
def supported_features def supported_features
SUPPORTED_FEATURES SUPPORTED_FEATURES
end end
def admin_password
ENV['GITLAB_ADMIN_PASSWORD']
end
def admin_username
ENV['GITLAB_ADMIN_USERNAME']
end
def admin_personal_access_token
ENV['GITLAB_QA_ADMIN_ACCESS_TOKEN']
end
def debug? def debug?
enabled?(ENV['QA_DEBUG'], default: false) enabled?(ENV['QA_DEBUG'], default: false)
end end
...@@ -92,14 +105,6 @@ module QA ...@@ -92,14 +105,6 @@ module QA
ENV['GITLAB_PASSWORD'] ENV['GITLAB_PASSWORD']
end end
def admin_username
ENV['GITLAB_ADMIN_USERNAME']
end
def admin_password
ENV['GITLAB_ADMIN_PASSWORD']
end
def github_username def github_username
ENV['GITHUB_USERNAME'] ENV['GITHUB_USERNAME']
end end
......
# frozen_string_literal: true # frozen_string_literal: true
module QA module QA
# Failure issue: https://gitlab.com/gitlab-org/quality/staging/issues/37 context 'Create', :requires_admin do
context 'Create', :quarantine do
describe 'push after setting the file size limit via admin/application_settings' do describe 'push after setting the file size limit via admin/application_settings' do
before(:all) do before(:context) do
push = Resource::Repository::ProjectPush.fabricate! do |p| @project = Resource::Project.fabricate_via_api! do |p|
p.file_name = 'README.md' p.name = 'project-test-push-limit'
p.file_content = '# This is a test project' p.initialize_with_readme = true
p.commit_message = 'Add README.md'
end end
@project = push.project @api_client = Runtime::API::Client.new(:gitlab, personal_access_token: Runtime::Env.admin_personal_access_token)
end end
before do after(:context) do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
end
after(:all) do
# need to set the default value after test # need to set the default value after test
# default value for file size limit is empty # default value for file size limit is empty
Runtime::Browser.visit(:gitlab, Page::Main::Login) set_file_size_limit(nil)
Page::Main::Login.perform(&:sign_in_using_credentials)
set_file_size_limit('')
Page::Main::Menu.perform(&:sign_out)
end end
it 'push successful when the file size is under the limit' do it 'push successful when the file size is under the limit' do
set_file_size_limit(5) set_file_size_limit(5)
expect(page).to have_content("Application settings saved successfully")
push = push_new_file('oversize_file_1.bin', wait_for_push: true) push = push_new_file('oversize_file_1.bin', wait_for_push: true)
expect(push.output).not_to have_content 'remote: fatal: pack exceeds maximum allowed size' expect(push.output).not_to have_content 'remote: fatal: pack exceeds maximum allowed size'
end end
it 'push fails when the file size is above the limit' do it 'push fails when the file size is above the limit' do
set_file_size_limit(1) set_file_size_limit(1)
expect(page).to have_content("Application settings saved successfully")
expect { push_new_file('oversize_file_2.bin', wait_for_push: false) } expect { push_new_file('oversize_file_2.bin', wait_for_push: false) }
.to raise_error(QA::Git::Repository::RepositoryCommandError, /remote: fatal: pack exceeds maximum allowed size/) .to raise_error(QA::Git::Repository::RepositoryCommandError, /remote: fatal: pack exceeds maximum allowed size/)
end end
def set_file_size_limit(limit) def set_file_size_limit(limit)
Page::Main::Menu.perform(&:click_admin_area) request = Runtime::API::Request.new(@api_client, '/application/settings')
Page::Admin::Menu.perform(&:go_to_general_settings) put request.url, receive_max_input_size: limit
Page::Admin::Settings::General.perform do |setting| expect_status(200)
setting.expand_account_and_limit do |page| expect(json_body).to match(
page.set_max_file_size(limit) a_hash_including(receive_max_input_size: limit)
page.save_settings )
end
end
end end
def push_new_file(file_name, wait_for_push: true) def push_new_file(file_name, wait_for_push: true)
@project.visit! commit_message = 'Adding a new file'
output = Resource::Repository::Push.fabricate! do |p|
Resource::Repository::ProjectPush.fabricate! do |p| p.repository_http_uri = @project.repository_http_location.uri
p.project = @project
p.file_name = file_name p.file_name = file_name
p.file_content = SecureRandom.random_bytes(2000000) p.file_content = SecureRandom.random_bytes(2000000)
p.commit_message = 'Adding a new file' p.commit_message = commit_message
p.wait_for_push = wait_for_push
p.new_branch = false p.new_branch = false
end end
@project.wait_for_push commit_message
output
end end
end end
end end
......
...@@ -227,6 +227,12 @@ describe QA::Runtime::Env do ...@@ -227,6 +227,12 @@ describe QA::Runtime::Env do
env_key: 'QA_CAN_TEST_GIT_PROTOCOL_V2', env_key: 'QA_CAN_TEST_GIT_PROTOCOL_V2',
default: true default: true
it_behaves_like 'boolean method with parameter',
method: :can_test?,
param: :admin,
env_key: 'QA_CAN_TEST_ADMIN_FEATURES',
default: true
it 'raises ArgumentError if feature is unknown' do it 'raises ArgumentError if feature is unknown' do
expect { described_class.can_test? :foo }.to raise_error(ArgumentError, 'Unknown feature "foo"') expect { described_class.can_test? :foo }.to raise_error(ArgumentError, 'Unknown feature "foo"')
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'active_support/core_ext/hash'
describe QA::Specs::Runner do describe QA::Specs::Runner do
shared_examples 'excludes orchestrated' do
it 'excludes the orchestrated tag and includes default args' do
expect_rspec_runner_arguments(['--tag', '~orchestrated', *described_class::DEFAULT_TEST_PATH_ARGS])
subject.perform
end
end
context '#perform' do context '#perform' do
before do before do
allow(QA::Runtime::Browser).to receive(:configure!) allow(QA::Runtime::Browser).to receive(:configure!)
end end
it 'excludes the orchestrated tag by default' do it_behaves_like 'excludes orchestrated'
expect_rspec_runner_arguments(['--tag', '~orchestrated', *described_class::DEFAULT_TEST_PATH_ARGS])
subject.perform
end
context 'when tty is set' do context 'when tty is set' do
subject { described_class.new.tap { |runner| runner.tty = true } } subject { described_class.new.tap { |runner| runner.tty = true } }
...@@ -67,8 +73,6 @@ describe QA::Specs::Runner do ...@@ -67,8 +73,6 @@ describe QA::Specs::Runner do
allow(QA::Runtime::Env).to receive(:signup_disabled?).and_return(true) allow(QA::Runtime::Env).to receive(:signup_disabled?).and_return(true)
end end
subject { described_class.new }
it 'includes default args and excludes the skip_signup_disabled tag' do it 'includes default args and excludes the skip_signup_disabled tag' do
expect_rspec_runner_arguments(['--tag', '~orchestrated', '--tag', '~skip_signup_disabled', *described_class::DEFAULT_TEST_PATH_ARGS]) expect_rspec_runner_arguments(['--tag', '~orchestrated', '--tag', '~skip_signup_disabled', *described_class::DEFAULT_TEST_PATH_ARGS])
...@@ -76,18 +80,54 @@ describe QA::Specs::Runner do ...@@ -76,18 +80,54 @@ describe QA::Specs::Runner do
end end
end end
context 'when git protocol v2 is not supported' do context 'testable features' do
before do shared_examples 'one supported feature' do |feature|
allow(QA::Runtime::Env).to receive(:can_test?).with(:git_protocol_v2).and_return(false) before do
QA::Runtime::Env.supported_features.each do |tag, _|
allow(QA::Runtime::Env).to receive(:can_test?).with(tag).and_return(false)
end
allow(QA::Runtime::Env).to receive(:can_test?).with(feature).and_return(true) unless feature.nil?
end
it 'includes default args and excludes all unsupported tags' do
expect_rspec_runner_arguments(['--tag', '~orchestrated', *excluded_feature_tags_except(feature), *described_class::DEFAULT_TEST_PATH_ARGS])
subject.perform
end
end end
subject { described_class.new } context 'when only git protocol 2 is supported' do
it_behaves_like 'one supported feature', :git_protocol_v2
end
it 'includes default args and excludes the requires_git_protocol_v2 tag' do context 'when only admin features are supported' do
expect_rspec_runner_arguments(['--tag', '~orchestrated', '--tag', '~requires_git_protocol_v2', *described_class::DEFAULT_TEST_PATH_ARGS]) it_behaves_like 'one supported feature', :admin
end
subject.perform context 'when no features are supported' do
it_behaves_like 'one supported feature', nil
end end
context 'when all features are supported' do
before do
QA::Runtime::Env.supported_features.each do |tag, _|
allow(QA::Runtime::Env).to receive(:can_test?).with(tag).and_return(true)
end
end
it_behaves_like 'excludes orchestrated'
end
context 'when features are not specified' do
it_behaves_like 'excludes orchestrated'
end
end
def excluded_feature_tags_except(tag)
QA::Runtime::Env.supported_features.except(tag).map do |tag, _|
['--tag', "~requires_#{tag}"]
end.flatten
end end
def expect_rspec_runner_arguments(arguments) def expect_rspec_runner_arguments(arguments)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment