Commit 73058db9 authored by Mark Lapierre's avatar Mark Lapierre Committed by Dan Davison

Add expiry date when SSH key is created

This helps prevent the tests from creating 100s of keys
that stay around forever.
parent b898ff1d
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
.col.form-group .col.form-group
= f.label :expires_at, s_('Profiles|Expires at'), class: 'label-bold' = f.label :expires_at, s_('Profiles|Expires at'), class: 'label-bold'
= f.date_field :expires_at, class: "form-control input-lg qa-key-expiry-field", min: Date.tomorrow = f.date_field :expires_at, class: "form-control input-lg", min: Date.tomorrow, data: { qa_selector: 'key_expiry_date_field' }
.js-add-ssh-key-validation-warning.hide .js-add-ssh-key-validation-warning.hide
.bs-callout.bs-callout-warning{ role: 'alert', aria_live: 'assertive' } .bs-callout.bs-callout-warning{ role: 'alert', aria_live: 'assertive' }
......
...@@ -5,6 +5,7 @@ module QA ...@@ -5,6 +5,7 @@ module QA
module Profile module Profile
class SSHKeys < Page::Base class SSHKeys < Page::Base
view 'app/views/profiles/keys/_form.html.haml' do view 'app/views/profiles/keys/_form.html.haml' do
element :key_expiry_date_field
element :key_title_field element :key_title_field
element :key_public_key_field element :key_public_key_field
element :add_key_button element :add_key_button
...@@ -19,17 +20,26 @@ module QA ...@@ -19,17 +20,26 @@ module QA
end end
def add_key(public_key, title) def add_key(public_key, title)
fill_element :key_public_key_field, public_key fill_element(:key_public_key_field, public_key)
fill_element :key_title_field, title fill_element(:key_title_field, title)
# Expire in 2 days just in case the key is created just before midnight
fill_expiry_date(Date.today + 2)
click_element :add_key_button click_element(:add_key_button)
end
def fill_expiry_date(date)
date = date.strftime('%m/%d/%Y') if date.is_a?(Date)
Date.strptime(date, '%m/%d/%Y') rescue ArgumentError raise "Expiry date must be in mm/dd/yyyy format"
fill_element(:key_expiry_date_field, date)
end end
def remove_key(title) def remove_key(title)
click_link(title) click_link(title)
accept_alert do accept_alert do
click_element :delete_key_button click_element(:delete_key_button)
end end
end end
......
...@@ -5,12 +5,16 @@ module QA ...@@ -5,12 +5,16 @@ module QA
class SSHKey < Base class SSHKey < Base
extend Forwardable extend Forwardable
attr_accessor :title attr_reader :title
attribute :id attribute :id
def_delegators :key, :private_key, :public_key, :md5_fingerprint def_delegators :key, :private_key, :public_key, :md5_fingerprint
def initialize
self.title = Time.now.to_f
end
def key def key
@key ||= Runtime::Key::RSA.new @key ||= Runtime::Key::RSA.new
end end
...@@ -28,6 +32,10 @@ module QA ...@@ -28,6 +32,10 @@ module QA
api_post api_post
end end
def title=(title)
@title = "E2E test key: #{title}"
end
def api_delete def api_delete
QA::Runtime::Logger.debug("Deleting SSH key with title '#{title}' and fingerprint '#{md5_fingerprint}'") QA::Runtime::Logger.debug("Deleting SSH key with title '#{title}' and fingerprint '#{md5_fingerprint}'")
......
...@@ -12,7 +12,7 @@ module QA ...@@ -12,7 +12,7 @@ module QA
resource.title = key_title resource.title = key_title
end end
expect(page).to have_content("Title: #{key_title}") expect(page).to have_content(key.title)
expect(page).to have_content(key.md5_fingerprint) expect(page).to have_content(key.md5_fingerprint)
Page::Main::Menu.perform(&:click_settings_link) Page::Main::Menu.perform(&:click_settings_link)
......
...@@ -53,7 +53,7 @@ module QA ...@@ -53,7 +53,7 @@ module QA
Page::Main::Menu.act { click_settings_link } Page::Main::Menu.act { click_settings_link }
Page::Profile::Menu.act { click_ssh_keys } Page::Profile::Menu.act { click_ssh_keys }
expect(page).to have_content(key_title) expect(page).to have_content(key.title)
expect(page).to have_content(key.md5_fingerprint) expect(page).to have_content(key.md5_fingerprint)
# Ensure project has replicated # Ensure project has replicated
...@@ -126,7 +126,7 @@ module QA ...@@ -126,7 +126,7 @@ module QA
Page::Main::Menu.act { click_settings_link } Page::Main::Menu.act { click_settings_link }
Page::Profile::Menu.act { click_ssh_keys } Page::Profile::Menu.act { click_ssh_keys }
expect(page).to have_content(key_title) expect(page).to have_content(key.title)
expect(page).to have_content(key.md5_fingerprint) expect(page).to have_content(key.md5_fingerprint)
# Ensure project has replicated # Ensure project has replicated
......
...@@ -53,7 +53,7 @@ module QA ...@@ -53,7 +53,7 @@ module QA
menu.wait_for_key_to_replicate(key_title) menu.wait_for_key_to_replicate(key_title)
end end
expect(page).to have_content(key_title) expect(page).to have_content(key.title)
expect(page).to have_content(key.md5_fingerprint) expect(page).to have_content(key.md5_fingerprint)
# Ensure project has replicated # Ensure project has replicated
...@@ -143,7 +143,7 @@ module QA ...@@ -143,7 +143,7 @@ module QA
menu.wait_for_key_to_replicate(key_title) menu.wait_for_key_to_replicate(key_title)
end end
expect(page).to have_content(key_title) expect(page).to have_content(key.title)
expect(page).to have_content(key.md5_fingerprint) expect(page).to have_content(key.md5_fingerprint)
# Ensure project has replicated # Ensure project has replicated
......
...@@ -59,7 +59,7 @@ module QA ...@@ -59,7 +59,7 @@ module QA
Page::Profile::Menu.perform(&:click_ssh_keys) Page::Profile::Menu.perform(&:click_ssh_keys)
Page::Profile::SSHKeys.perform do |ssh| Page::Profile::SSHKeys.perform do |ssh|
expect(ssh.keys_list).to have_content(key_title) expect(ssh.keys_list).to have_content(key.title)
expect(ssh.keys_list).to have_content(key.md5_fingerprint) expect(ssh.keys_list).to have_content(key.md5_fingerprint)
end end
......
...@@ -48,7 +48,7 @@ module QA ...@@ -48,7 +48,7 @@ module QA
Page::Profile::Menu.perform(&:click_ssh_keys) Page::Profile::Menu.perform(&:click_ssh_keys)
Page::Profile::SSHKeys.perform do |ssh| Page::Profile::SSHKeys.perform do |ssh|
expect(ssh.keys_list).to have_content(key_title) expect(ssh.keys_list).to have_content(key.title)
expect(ssh.keys_list).to have_content(key.md5_fingerprint) expect(ssh.keys_list).to have_content(key.md5_fingerprint)
end end
......
# frozen_string_literal: true
describe QA::Resource::SSHKey do
describe '#key' do
it 'generates a default key' do
expect(subject.key).to be_a(QA::Runtime::Key::RSA)
end
end
describe '#title' do
it 'generates a default title' do
expect(subject.title).to match(/E2E test key: \d+/)
end
it 'is possible to set the title' do
subject.title = 'I am in a title'
expect(subject.title).to eq('E2E test key: I am in a title')
end
end
end
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