Commit a189141a authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'jsl-geo-api-for-ssh-check' into 'master'

Use API for SSH key check in Geo specs

See merge request gitlab-org/gitlab!33931
parents 92294b62 5a015efb
...@@ -6,6 +6,7 @@ module QA ...@@ -6,6 +6,7 @@ module QA
extend Forwardable extend Forwardable
attr_reader :title attr_reader :title
attr_accessor :expires_at
attribute :id attribute :id
...@@ -53,13 +54,27 @@ module QA ...@@ -53,13 +54,27 @@ module QA
def api_post_body def api_post_body
{ {
title: title, title: title,
key: public_key key: public_key,
expires_at: expires_at
} }
end end
def api_delete_path def api_delete_path
"/user/keys/#{id}" "/user/keys/#{id}"
end end
def replicated?
api_client = Runtime::API::Client.new(:geo_secondary)
QA::Runtime::Logger.debug('Checking for SSH key replication')
Support::Retrier.retry_until(max_duration: QA::EE::Runtime::Geo.max_db_replication_time, sleep_interval: 3) do
response = get Runtime::API::Request.new(api_client, api_get_path).url
response.code == QA::Support::Api::HTTP_STATUS_OK &&
parse_body(response)[:title].include?(title)
end
end
end end
end end
end end
...@@ -7,7 +7,7 @@ module QA ...@@ -7,7 +7,7 @@ module QA
context 'regular git commit' do context 'regular git commit' do
it "is replicated to the secondary" do it "is replicated to the secondary" do
key_title = "key for ssh tests #{Time.now.to_f}" key_title = "Geo SSH #{Time.now.to_f}"
file_content = 'This is a Geo project! Commit from primary.' file_content = 'This is a Geo project! Commit from primary.'
project = nil project = nil
key = nil key = nil
...@@ -16,12 +16,13 @@ module QA ...@@ -16,12 +16,13 @@ module QA
# Create a new SSH key for the user # Create a new SSH key for the user
key = Resource::SSHKey.fabricate_via_api! do |resource| key = Resource::SSHKey.fabricate_via_api! do |resource|
resource.title = key_title resource.title = key_title
resource.expires_at = Date.today + 2
end end
# Create a new Project # Create a new Project
project = Resource::Project.fabricate_via_api! do |project| project = Resource::Project.fabricate_via_api! do |project|
project.name = 'geo-project' project.name = 'geo-project'
project.description = 'Geo test project for ssh push' project.description = 'Geo test project for SSH push'
end end
# Perform a git push over SSH directly to the primary # Perform a git push over SSH directly to the primary
...@@ -42,20 +43,13 @@ module QA ...@@ -42,20 +43,13 @@ module QA
end end
end end
QA::Runtime::Logger.debug('Visiting the secondary geo node') QA::Runtime::Logger.debug('*****Visiting the secondary geo node*****')
QA::Flow::Login.while_signed_in(address: :geo_secondary) do QA::Flow::Login.while_signed_in(address: :geo_secondary) do
EE::Page::Main::Banner.perform do |banner| EE::Page::Main::Banner.perform do |banner|
expect(banner).to have_secondary_read_only_banner expect(banner).to have_secondary_read_only_banner
end end
# Ensure the SSH key has replicated
Page::Main::Menu.act { click_settings_link }
Page::Profile::Menu.act { click_ssh_keys }
expect(page).to have_content(key.title)
expect(page).to have_content(key.md5_fingerprint)
# Ensure project has replicated # Ensure project has replicated
Page::Main::Menu.perform { |menu| menu.go_to_projects } Page::Main::Menu.perform { |menu| menu.go_to_projects }
Page::Dashboard::Projects.perform do |dashboard| Page::Dashboard::Projects.perform do |dashboard|
...@@ -76,7 +70,7 @@ module QA ...@@ -76,7 +70,7 @@ module QA
context 'git-lfs commit' do context 'git-lfs commit' do
it "is replicated to the secondary" do it "is replicated to the secondary" do
key_title = "key for ssh tests #{Time.now.to_f}" key_title = "Geo SSH LFS #{Time.now.to_f}"
file_content = 'The rendered file could not be displayed because it is stored in LFS.' file_content = 'The rendered file could not be displayed because it is stored in LFS.'
project = nil project = nil
key = nil key = nil
...@@ -90,7 +84,7 @@ module QA ...@@ -90,7 +84,7 @@ module QA
# Create a new Project # Create a new Project
project = Resource::Project.fabricate_via_api! do |project| project = Resource::Project.fabricate_via_api! do |project|
project.name = 'geo-project' project.name = 'geo-project'
project.description = 'Geo test project for ssh lfs push' project.description = 'Geo test project for SSH LFS push'
end end
# Perform a git push over SSH directly to the primary # Perform a git push over SSH directly to the primary
...@@ -115,20 +109,13 @@ module QA ...@@ -115,20 +109,13 @@ module QA
end end
end end
QA::Runtime::Logger.debug('Visiting the secondary geo node') QA::Runtime::Logger.debug('*****Visiting the secondary geo node*****')
QA::Flow::Login.while_signed_in(address: :geo_secondary) do QA::Flow::Login.while_signed_in(address: :geo_secondary) do
EE::Page::Main::Banner.perform do |banner| EE::Page::Main::Banner.perform do |banner|
expect(banner).to have_secondary_read_only_banner expect(banner).to have_secondary_read_only_banner
end end
# Ensure the SSH key has replicated
Page::Main::Menu.act { click_settings_link }
Page::Profile::Menu.act { click_ssh_keys }
expect(page).to have_content(key.title)
expect(page).to have_content(key.md5_fingerprint)
# Ensure project has replicated # Ensure project has replicated
Page::Main::Menu.perform { |menu| menu.go_to_projects } Page::Main::Menu.perform { |menu| menu.go_to_projects }
Page::Dashboard::Projects.perform do |dashboard| Page::Dashboard::Projects.perform do |dashboard|
......
...@@ -9,7 +9,7 @@ module QA ...@@ -9,7 +9,7 @@ module QA
context 'regular git commit' do context 'regular git commit' do
it 'is proxied to the primary and ultimately replicated to the secondary' do it 'is proxied to the primary and ultimately replicated to the secondary' do
file_name = 'README.md' file_name = 'README.md'
key_title = "key for ssh tests #{Time.now.to_f}" key_title = "Geo SSH to 2nd #{Time.now.to_f}"
project = nil project = nil
key = nil key = nil
...@@ -17,12 +17,13 @@ module QA ...@@ -17,12 +17,13 @@ module QA
# Create a new SSH key for the user # Create a new SSH key for the user
key = Resource::SSHKey.fabricate_via_api! do |resource| key = Resource::SSHKey.fabricate_via_api! do |resource|
resource.title = key_title resource.title = key_title
resource.expires_at = Date.today + 2
end end
# Create a new Project # Create a new Project
project = Resource::Project.fabricate_via_api! do |project| project = Resource::Project.fabricate_via_api! do |project|
project.name = 'geo-project' project.name = 'geo-project'
project.description = 'Geo test project for ssh push to 2nd' project.description = 'Geo test project for SSH push to 2nd'
end end
# Perform a git push over SSH directly to the primary # Perform a git push over SSH directly to the primary
...@@ -39,7 +40,7 @@ module QA ...@@ -39,7 +40,7 @@ module QA
project.visit! project.visit!
end end
QA::Runtime::Logger.debug('Visiting the secondary geo node') QA::Runtime::Logger.debug('*****Visiting the secondary geo node*****')
QA::Flow::Login.while_signed_in(address: :geo_secondary) do QA::Flow::Login.while_signed_in(address: :geo_secondary) do
EE::Page::Main::Banner.perform do |banner| EE::Page::Main::Banner.perform do |banner|
...@@ -47,14 +48,7 @@ module QA ...@@ -47,14 +48,7 @@ module QA
end end
# Ensure the SSH key has replicated # Ensure the SSH key has replicated
Page::Main::Menu.perform(&:click_settings_link) expect(key).to be_replicated
Page::Profile::Menu.perform do |menu|
menu.click_ssh_keys
menu.wait_for_key_to_replicate(key_title)
end
expect(page).to have_content(key.title)
expect(page).to have_content(key.md5_fingerprint)
# Ensure project has replicated # Ensure project has replicated
Page::Main::Menu.perform(&:go_to_projects) Page::Main::Menu.perform(&:go_to_projects)
...@@ -97,7 +91,7 @@ module QA ...@@ -97,7 +91,7 @@ module QA
context 'git-lfs commit' do context 'git-lfs commit' do
it 'is proxied to the primary and ultimately replicated to the secondary' do it 'is proxied to the primary and ultimately replicated to the secondary' do
key_title = "key for ssh tests #{Time.now.to_f}" key_title = "Geo SSH LFS to 2nd #{Time.now.to_f}"
file_name_primary = 'README.md' file_name_primary = 'README.md'
file_name_secondary = 'README_MORE.md' file_name_secondary = 'README_MORE.md'
project = nil project = nil
...@@ -107,6 +101,7 @@ module QA ...@@ -107,6 +101,7 @@ module QA
# Create a new SSH key for the user # Create a new SSH key for the user
key = Resource::SSHKey.fabricate_via_api! do |resource| key = Resource::SSHKey.fabricate_via_api! do |resource|
resource.title = key_title resource.title = key_title
resource.expires_at = Date.today + 2
end end
# Create a new Project # Create a new Project
...@@ -129,7 +124,7 @@ module QA ...@@ -129,7 +124,7 @@ module QA
end end
end end
QA::Runtime::Logger.debug('Visiting the secondary geo node') QA::Runtime::Logger.debug('*****Visiting the secondary geo node*****')
QA::Flow::Login.while_signed_in(address: :geo_secondary) do QA::Flow::Login.while_signed_in(address: :geo_secondary) do
EE::Page::Main::Banner.perform do |banner| EE::Page::Main::Banner.perform do |banner|
...@@ -137,14 +132,7 @@ module QA ...@@ -137,14 +132,7 @@ module QA
end end
# Ensure the SSH key has replicated # Ensure the SSH key has replicated
Page::Main::Menu.perform(&:click_settings_link) expect(key).to be_replicated
Page::Profile::Menu.perform do |menu|
menu.click_ssh_keys
menu.wait_for_key_to_replicate(key_title)
end
expect(page).to have_content(key.title)
expect(page).to have_content(key.md5_fingerprint)
# Ensure project has replicated # Ensure project has replicated
Page::Main::Menu.perform(&:go_to_projects) Page::Main::Menu.perform(&:go_to_projects)
......
...@@ -9,7 +9,7 @@ module QA ...@@ -9,7 +9,7 @@ module QA
wiki_content = 'This tests replication of wikis via SSH' wiki_content = 'This tests replication of wikis via SSH'
push_content = 'This is from the Geo wiki push via SSH!' push_content = 'This is from the Geo wiki push via SSH!'
project_name = "geo-wiki-project-#{SecureRandom.hex(8)}" project_name = "geo-wiki-project-#{SecureRandom.hex(8)}"
key_title = "key for ssh tests #{Time.now.to_f}" key_title = "Geo wiki SSH #{Time.now.to_f}"
project = nil project = nil
key = nil key = nil
...@@ -17,12 +17,13 @@ module QA ...@@ -17,12 +17,13 @@ module QA
# Create a new SSH key # Create a new SSH key
key = Resource::SSHKey.fabricate_via_api! do |resource| key = Resource::SSHKey.fabricate_via_api! do |resource|
resource.title = key_title resource.title = key_title
resource.expires_at = Date.today + 2
end end
# Create a new project and wiki # Create a new project and wiki
project = Resource::Project.fabricate_via_api! do |project| project = Resource::Project.fabricate_via_api! do |project|
project.name = project_name project.name = project_name
project.description = 'Geo project for wiki ssh spec' project.description = 'Geo project for wiki SSH spec'
end end
wiki = Resource::Wiki::ProjectPage.fabricate_via_api! do |wiki| wiki = Resource::Wiki::ProjectPage.fabricate_via_api! do |wiki|
...@@ -47,22 +48,13 @@ module QA ...@@ -47,22 +48,13 @@ module QA
validate_content(push_content) validate_content(push_content)
end end
QA::Runtime::Logger.debug('Visiting the secondary geo node') QA::Runtime::Logger.debug('*****Visiting the secondary geo node*****')
QA::Flow::Login.while_signed_in(address: :geo_secondary) do QA::Flow::Login.while_signed_in(address: :geo_secondary) do
EE::Page::Main::Banner.perform do |banner| EE::Page::Main::Banner.perform do |banner|
expect(banner).to have_secondary_read_only_banner expect(banner).to have_secondary_read_only_banner
end end
# Ensure the SSH key has replicated
Page::Main::Menu.perform(&:click_settings_link)
Page::Profile::Menu.perform(&:click_ssh_keys)
Page::Profile::SSHKeys.perform do |ssh|
expect(ssh.keys_list).to have_content(key.title)
expect(ssh.keys_list).to have_content(key.md5_fingerprint)
end
Page::Main::Menu.perform(&:go_to_projects) Page::Main::Menu.perform(&:go_to_projects)
Page::Dashboard::Projects.perform do |dashboard| Page::Dashboard::Projects.perform do |dashboard|
......
...@@ -7,7 +7,7 @@ module QA ...@@ -7,7 +7,7 @@ module QA
wiki_content = 'This tests replication of wikis via SSH to secondary' wiki_content = 'This tests replication of wikis via SSH to secondary'
push_content = 'This is from the Geo wiki push via SSH to secondary!' push_content = 'This is from the Geo wiki push via SSH to secondary!'
project_name = "geo-wiki-project-#{SecureRandom.hex(8)}" project_name = "geo-wiki-project-#{SecureRandom.hex(8)}"
key_title = "key for ssh tests #{Time.now.to_f}" key_title = "Geo wiki SSH to 2nd #{Time.now.to_f}"
wiki = nil wiki = nil
key = nil key = nil
...@@ -16,12 +16,13 @@ module QA ...@@ -16,12 +16,13 @@ module QA
# Create a new SSH key # Create a new SSH key
key = Resource::SSHKey.fabricate_via_api! do |resource| key = Resource::SSHKey.fabricate_via_api! do |resource|
resource.title = key_title resource.title = key_title
resource.expires_at = Date.today + 2
end end
# Create a new project and wiki # Create a new project and wiki
project = Resource::Project.fabricate_via_api! do |project| project = Resource::Project.fabricate_via_api! do |project|
project.name = project_name project.name = project_name
project.description = 'Geo project for wiki ssh spec' project.description = 'Geo project for wiki SSH spec'
end end
wiki = Resource::Wiki::ProjectPage.fabricate_via_api! do |wiki| wiki = Resource::Wiki::ProjectPage.fabricate_via_api! do |wiki|
...@@ -36,7 +37,7 @@ module QA ...@@ -36,7 +37,7 @@ module QA
end end
it 'proxies wiki commit to primary node and ultmately replicates to secondary node' do it 'proxies wiki commit to primary node and ultmately replicates to secondary node' do
QA::Runtime::Logger.debug('Visiting the secondary geo node') QA::Runtime::Logger.debug('*****Visiting the secondary geo node*****')
QA::Flow::Login.while_signed_in(address: :geo_secondary) do QA::Flow::Login.while_signed_in(address: :geo_secondary) do
EE::Page::Main::Banner.perform do |banner| EE::Page::Main::Banner.perform do |banner|
...@@ -44,13 +45,7 @@ module QA ...@@ -44,13 +45,7 @@ module QA
end end
# Ensure the SSH key has replicated # Ensure the SSH key has replicated
Page::Main::Menu.perform(&:click_settings_link) expect(key).to be_replicated
Page::Profile::Menu.perform(&:click_ssh_keys)
Page::Profile::SSHKeys.perform do |ssh|
expect(ssh.keys_list).to have_content(key.title)
expect(ssh.keys_list).to have_content(key.md5_fingerprint)
end
Page::Main::Menu.perform(&:go_to_projects) Page::Main::Menu.perform(&:go_to_projects)
...@@ -99,6 +94,8 @@ module QA ...@@ -99,6 +94,8 @@ module QA
end end
end end
private
def validate_content(content) def validate_content(content)
Page::Project::Wiki::Show.perform do |show| Page::Project::Wiki::Show.perform do |show|
expect(show).to have_content(content) expect(show).to have_content(content)
......
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