Commit cfe0043d authored by Mark Lapierre's avatar Mark Lapierre

Test push limit with admin user

Uses `:requires_admin` metadata to specify that a test needs
an admin user.

Sets the push file size limit test to require an admin user.

With an admin access token set as the env var
GITLAB_QA_ADMIN_ACCESS_TOKEN, the push size
limit test now only uses the API and CLI
parent 8ac1ac2b
......@@ -10,13 +10,26 @@ module QA
# The environment variables used to indicate if the environment under test
# supports the given feature
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
def supported_features
SUPPORTED_FEATURES
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?
enabled?(ENV['QA_DEBUG'], default: false)
end
......@@ -92,14 +105,6 @@ module QA
ENV['GITLAB_PASSWORD']
end
def admin_username
ENV['GITLAB_ADMIN_USERNAME']
end
def admin_password
ENV['GITLAB_ADMIN_PASSWORD']
end
def github_username
ENV['GITHUB_USERNAME']
end
......
# frozen_string_literal: true
module QA
# Failure issue: https://gitlab.com/gitlab-org/quality/staging/issues/37
context 'Create', :quarantine do
context 'Create', :requires_admin do
describe 'push after setting the file size limit via admin/application_settings' do
before(:all) do
push = Resource::Repository::ProjectPush.fabricate! do |p|
p.file_name = 'README.md'
p.file_content = '# This is a test project'
p.commit_message = 'Add README.md'
before(:context) do
@project = Resource::Project.fabricate_via_api! do |p|
p.name = 'project-test-push-limit'
p.initialize_with_readme = true
end
@project = push.project
@api_client = Runtime::API::Client.new(:gitlab, personal_access_token: Runtime::Env.admin_personal_access_token)
end
before do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
end
after(:all) do
after(:context) do
# need to set the default value after test
# default value for file size limit is empty
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
set_file_size_limit('')
Page::Main::Menu.perform(&:sign_out)
set_file_size_limit(nil)
end
it 'push successful when the file size is under the limit' do
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)
expect(push.output).not_to have_content 'remote: fatal: pack exceeds maximum allowed size'
end
it 'push fails when the file size is above the limit' do
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) }
.to raise_error(QA::Git::Repository::RepositoryCommandError, /remote: fatal: pack exceeds maximum allowed size/)
end
def set_file_size_limit(limit)
Page::Main::Menu.perform(&:click_admin_area)
Page::Admin::Menu.perform(&:go_to_general_settings)
request = Runtime::API::Request.new(@api_client, '/application/settings')
put request.url, receive_max_input_size: limit
Page::Admin::Settings::General.perform do |setting|
setting.expand_account_and_limit do |page|
page.set_max_file_size(limit)
page.save_settings
end
end
expect_status(200)
expect(json_body).to match(
a_hash_including(receive_max_input_size: limit)
)
end
def push_new_file(file_name, wait_for_push: true)
@project.visit!
Resource::Repository::ProjectPush.fabricate! do |p|
p.project = @project
commit_message = 'Adding a new file'
output = Resource::Repository::Push.fabricate! do |p|
p.repository_http_uri = @project.repository_http_location.uri
p.file_name = file_name
p.file_content = SecureRandom.random_bytes(2000000)
p.commit_message = 'Adding a new file'
p.wait_for_push = wait_for_push
p.commit_message = commit_message
p.new_branch = false
end
@project.wait_for_push commit_message
output
end
end
end
......
......@@ -227,6 +227,12 @@ describe QA::Runtime::Env do
env_key: 'QA_CAN_TEST_GIT_PROTOCOL_V2',
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
expect { described_class.can_test? :foo }.to raise_error(ArgumentError, 'Unknown feature "foo"')
end
......
# frozen_string_literal: true
require 'active_support/core_ext/hash'
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
before do
allow(QA::Runtime::Browser).to receive(:configure!)
end
it 'excludes the orchestrated tag by default' do
expect_rspec_runner_arguments(['--tag', '~orchestrated', *described_class::DEFAULT_TEST_PATH_ARGS])
subject.perform
end
it_behaves_like 'excludes orchestrated'
context 'when tty is set' do
subject { described_class.new.tap { |runner| runner.tty = true } }
......@@ -67,8 +73,6 @@ describe QA::Specs::Runner do
allow(QA::Runtime::Env).to receive(:signup_disabled?).and_return(true)
end
subject { described_class.new }
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])
......@@ -76,18 +80,54 @@ describe QA::Specs::Runner do
end
end
context 'when git protocol v2 is not supported' do
before do
allow(QA::Runtime::Env).to receive(:can_test?).with(:git_protocol_v2).and_return(false)
context 'testable features' do
shared_examples 'one supported feature' do |feature|
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
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
expect_rspec_runner_arguments(['--tag', '~orchestrated', '--tag', '~requires_git_protocol_v2', *described_class::DEFAULT_TEST_PATH_ARGS])
context 'when only admin features are supported' do
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
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
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