Commit d5cd1c4a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'qa-staging-2' into 'master'

[QA] Improve the fork scenario to take a username and password instead of always…

Closes gitlab-org/quality/staging#2

See merge request gitlab-org/gitlab-ce!21090
parents 92cf7e8f 98ba19b5
...@@ -4,7 +4,12 @@ module QA ...@@ -4,7 +4,12 @@ module QA
class Fork < Factory::Base class Fork < Factory::Base
dependency Factory::Repository::ProjectPush, as: :push dependency Factory::Repository::ProjectPush, as: :push
dependency Factory::Resource::User, as: :user dependency Factory::Resource::User, as: :user do |user|
if Runtime::Env.forker?
user.username = Runtime::Env.forker_username
user.password = Runtime::Env.forker_password
end
end
product(:user) { |factory| factory.user } product(:user) { |factory| factory.user }
......
...@@ -4,28 +4,52 @@ module QA ...@@ -4,28 +4,52 @@ module QA
module Factory module Factory
module Resource module Resource
class User < Factory::Base class User < Factory::Base
attr_accessor :name, :username, :email, :password attr_reader :unique_id
attr_writer :username, :password, :name, :email
def initialize def initialize
@name = "name-#{SecureRandom.hex(8)}" @unique_id = SecureRandom.hex(8)
@username = "username-#{SecureRandom.hex(8)}"
@email = "mail#{SecureRandom.hex(8)}@mail.com"
@password = 'password'
end end
product(:name) { |factory| factory.name } def username
@username ||= "qa-user-#{unique_id}"
end
product(:username) { |factory| factory.username } def password
@password ||= 'password'
end
product(:email) { |factory| factory.email } def name
@name ||= username
end
def email
@email ||= "#{username}@example.com"
end
def credentials_given?
defined?(@username) && defined?(@password)
end
product(:name) { |factory| factory.name }
product(:username) { |factory| factory.username }
product(:email) { |factory| factory.email }
product(:password) { |factory| factory.password } product(:password) { |factory| factory.password }
def fabricate! def fabricate!
Page::Menu::Main.act { sign_out } Page::Menu::Main.perform { |main| main.sign_out }
Page::Main::Login.act { switch_to_register_tab }
Page::Main::SignUp.perform do |page| if credentials_given?
page.sign_up!(name: name, username: username, email: email, password: password) Page::Main::Login.perform do |login|
login.sign_in_using_credentials(self)
end
else
Page::Main::Login.perform do |login|
login.switch_to_register_tab
end
Page::Main::SignUp.perform do |signup|
signup.sign_up!(self)
end
end end
end end
end end
......
...@@ -28,7 +28,7 @@ module QA ...@@ -28,7 +28,7 @@ module QA
end end
def use_default_credentials def use_default_credentials
self.username = Runtime::User.name self.username = Runtime::User.username
self.password = Runtime::User.password self.password = Runtime::User.password
end end
......
...@@ -40,17 +40,19 @@ module QA ...@@ -40,17 +40,19 @@ module QA
end end
end end
def sign_in_using_credentials def sign_in_using_credentials(user = nil)
# Don't try to log-in if we're already logged-in # Don't try to log-in if we're already logged-in
return if Page::Menu::Main.act { has_personal_area?(wait: 0) } return if Page::Menu::Main.act { has_personal_area?(wait: 0) }
using_wait_time 0 do using_wait_time 0 do
set_initial_password_if_present set_initial_password_if_present
raise NotImplementedError if Runtime::User.ldap_user? && user&.credentials_given?
if Runtime::User.ldap_user? if Runtime::User.ldap_user?
sign_in_using_ldap_credentials sign_in_using_ldap_credentials
else else
sign_in_using_gitlab_credentials sign_in_using_gitlab_credentials(user || Runtime::User)
end end
end end
...@@ -69,21 +71,30 @@ module QA ...@@ -69,21 +71,30 @@ module QA
click_on 'Register' click_on 'Register'
end end
def switch_to_ldap_tab
click_on 'LDAP'
end
def switch_to_standard_tab
click_on 'Standard'
end
private private
def sign_in_using_ldap_credentials def sign_in_using_ldap_credentials
click_link 'LDAP' switch_to_ldap_tab
fill_in :username, with: Runtime::User.ldap_username fill_in :username, with: Runtime::User.ldap_username
fill_in :password, with: Runtime::User.ldap_password fill_in :password, with: Runtime::User.ldap_password
click_button 'Sign in' click_button 'Sign in'
end end
def sign_in_using_gitlab_credentials def sign_in_using_gitlab_credentials(user)
click_link 'Standard' if page.has_content?('LDAP') switch_to_sign_in_tab unless page.has_button?('Sign in')
switch_to_standard_tab if page.has_content?('LDAP')
fill_in :user_login, with: Runtime::User.name fill_in :user_login, with: user.username
fill_in :user_password, with: Runtime::User.password fill_in :user_password, with: user.password
click_button 'Sign in' click_button 'Sign in'
end end
......
...@@ -11,12 +11,12 @@ module QA ...@@ -11,12 +11,12 @@ module QA
element :register_button, 'submit "Register"' element :register_button, 'submit "Register"'
end end
def sign_up!(name:, username:, email:, password:) def sign_up!(user)
fill_in :new_user_name, with: name fill_in :new_user_name, with: user.name
fill_in :new_user_username, with: username fill_in :new_user_username, with: user.username
fill_in :new_user_email, with: email fill_in :new_user_email, with: user.email
fill_in :new_user_email_confirmation, with: email fill_in :new_user_email_confirmation, with: user.email
fill_in :new_user_password, with: password fill_in :new_user_password, with: user.password
click_button 'Register' click_button 'Register'
Page::Menu::Main.act { has_personal_area? } Page::Menu::Main.act { has_personal_area? }
......
...@@ -39,6 +39,18 @@ module QA ...@@ -39,6 +39,18 @@ module QA
ENV['GITLAB_PASSWORD'] ENV['GITLAB_PASSWORD']
end end
def forker?
forker_username && forker_password
end
def forker_username
ENV['GITLAB_FORKER_USERNAME']
end
def forker_password
ENV['GITLAB_FORKER_PASSWORD']
end
def ldap_username def ldap_username
ENV['GITLAB_LDAP_USERNAME'] ENV['GITLAB_LDAP_USERNAME']
end end
......
...@@ -3,12 +3,12 @@ module QA ...@@ -3,12 +3,12 @@ module QA
module User module User
extend self extend self
def default_name def default_username
'root' 'root'
end end
def name def username
Runtime::Env.user_username || default_name Runtime::Env.user_username || default_username
end end
def password def password
......
...@@ -7,7 +7,7 @@ module QA ...@@ -7,7 +7,7 @@ module QA
end end
let(:project_name) { "api-basics-#{SecureRandom.hex(8)}" } let(:project_name) { "api-basics-#{SecureRandom.hex(8)}" }
let(:sanitized_project_path) { CGI.escape("#{Runtime::User.name}/#{project_name}") } let(:sanitized_project_path) { CGI.escape("#{Runtime::User.username}/#{project_name}") }
it 'user creates a project with a file and deletes them afterwards' do it 'user creates a project with a file and deletes them afterwards' do
create_project_request = Runtime::API::Request.new(@api_client, '/projects') create_project_request = Runtime::API::Request.new(@api_client, '/projects')
......
...@@ -14,11 +14,11 @@ module QA ...@@ -14,11 +14,11 @@ module QA
end end
it 'submit request with a valid user name' do it 'submit request with a valid user name' do
get request.url, { params: { username: Runtime::User.name } } get request.url, { params: { username: Runtime::User.username } }
expect_status(200) expect_status(200)
expect(json_body).to contain_exactly( expect(json_body).to contain_exactly(
a_hash_including(username: Runtime::User.name) a_hash_including(username: Runtime::User.username)
) )
end end
......
...@@ -8,14 +8,12 @@ module QA ...@@ -8,14 +8,12 @@ module QA
merge_request.fork_branch = 'feature-branch' merge_request.fork_branch = 'feature-branch'
end end
Page::Menu::Main.act { sign_out } Page::Menu::Main.perform { |main| main.sign_out }
Page::Main::Login.act do Page::Main::Login.perform { |login| login.sign_in_using_credentials }
switch_to_sign_in_tab
sign_in_using_credentials
end
merge_request.visit! merge_request.visit!
Page::MergeRequest::Show.act { merge! }
Page::MergeRequest::Show.perform { |show| show.merge! }
expect(page).to have_content('The changes were merged') expect(page).to have_content('The changes were merged')
end end
......
...@@ -77,6 +77,31 @@ describe QA::Runtime::Env do ...@@ -77,6 +77,31 @@ describe QA::Runtime::Env do
end end
end end
describe '.forker?' do
it 'returns false if no forker credentials are defined' do
expect(described_class).not_to be_forker
end
it 'returns false if only forker username is defined' do
stub_env('GITLAB_FORKER_USERNAME', 'foo')
expect(described_class).not_to be_forker
end
it 'returns false if only forker password is defined' do
stub_env('GITLAB_FORKER_PASSWORD', 'bar')
expect(described_class).not_to be_forker
end
it 'returns true if forker username and password are defined' do
stub_env('GITLAB_FORKER_USERNAME', 'foo')
stub_env('GITLAB_FORKER_PASSWORD', 'bar')
expect(described_class).to be_forker
end
end
describe '.github_access_token' do describe '.github_access_token' do
it 'returns "" if GITHUB_ACCESS_TOKEN is not defined' do it 'returns "" if GITHUB_ACCESS_TOKEN is not defined' do
expect(described_class.github_access_token).to eq('') expect(described_class.github_access_token).to eq('')
......
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