aboutsummaryrefslogtreecommitdiff
path: root/spec/acceptance
diff options
context:
space:
mode:
authorMelissa <melissa@puppet.com>2018-07-02 11:45:02 -0700
committerGitHub <noreply@github.com>2018-07-02 11:45:02 -0700
commitc42bbe6471b9f1813d7b40b9f67d988b994a8e5a (patch)
treefa26c6a5cd53626ac3cddc4922c47add356c6435 /spec/acceptance
parentd1719de1d77b9c139b1b5f5832330807c0fe11fe (diff)
parent950a6c0a21896989118badc0f541f7469752c63f (diff)
downloadpuppet-sshkeys_core-c42bbe6471b9f1813d7b40b9f67d988b994a8e5a.tar.gz
puppet-sshkeys_core-c42bbe6471b9f1813d7b40b9f67d988b994a8e5a.tar.bz2
Merge pull request #1 from jhelwig/module-updates
Import the module
Diffstat (limited to 'spec/acceptance')
-rw-r--r--spec/acceptance/nodesets/default.yml19
-rw-r--r--spec/acceptance/tests/resource/ssh_authorized_key/create.rb39
-rw-r--r--spec/acceptance/tests/resource/ssh_authorized_key/create_spec.rb36
-rw-r--r--spec/acceptance/tests/resource/ssh_authorized_key/destroy.rb42
-rw-r--r--spec/acceptance/tests/resource/ssh_authorized_key/destroy_spec.rb38
-rw-r--r--spec/acceptance/tests/resource/ssh_authorized_key/modify.rb43
-rw-r--r--spec/acceptance/tests/resource/ssh_authorized_key/modify_spec.rb36
-rw-r--r--spec/acceptance/tests/resource/ssh_authorized_key/query.rb35
-rw-r--r--spec/acceptance/tests/resource/sshkey/create.rb77
-rw-r--r--spec/acceptance/tests/resource/sshkey/create_spec.rb81
10 files changed, 210 insertions, 236 deletions
diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml
new file mode 100644
index 0000000..ac89483
--- /dev/null
+++ b/spec/acceptance/nodesets/default.yml
@@ -0,0 +1,19 @@
+---
+HOSTS:
+ ubuntu1604-64-1:
+ pe_dir:
+ pe_ver:
+ pe_upgrade_dir:
+ pe_upgrade_ver:
+ hypervisor: vmpooler
+ platform: ubuntu-16.04-amd64
+ packaging_platform: ubuntu-16.04-amd64
+ template: ubuntu-1604-x86_64
+ roles:
+ - agent
+ - default
+CONFIG:
+ type: agent
+ nfs_server: none
+ consoleport: 443
+pooling_api: http://vmpooler.delivery.puppetlabs.net/ \ No newline at end of file
diff --git a/spec/acceptance/tests/resource/ssh_authorized_key/create.rb b/spec/acceptance/tests/resource/ssh_authorized_key/create.rb
deleted file mode 100644
index 6b4c879..0000000
--- a/spec/acceptance/tests/resource/ssh_authorized_key/create.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-test_name "should create an entry for an SSH authorized key"
-
-tag 'audit:medium',
- 'audit:refactor', # Use block style `test_run`
- 'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
-
-confine :except, :platform => ['windows']
-
-auth_keys = '~/.ssh/authorized_keys'
-name = "pl#{rand(999999).to_i}"
-
-agents.each do |agent|
- teardown do
- #(teardown) restore the #{auth_keys} file
- on(agent, "mv /tmp/auth_keys #{auth_keys}", :acceptable_exit_codes => [0,1])
- end
-
- #------- SETUP -------#
- step "(setup) backup #{auth_keys} file"
- on(agent, "cp #{auth_keys} /tmp/auth_keys", :acceptable_exit_codes => [0,1])
- on(agent, "chown $LOGNAME #{auth_keys}")
-
- #------- TESTS -------#
- step "create an authorized key entry with puppet (present)"
- args = ['ensure=present',
- "user=$LOGNAME",
- "type='rsa'",
- "key='mykey'",
- ]
- on(agent, puppet_resource('ssh_authorized_key', "#{name}", args))
-
- step "verify entry in #{auth_keys}"
- on(agent, "cat #{auth_keys}") do |res|
- fail_test "didn't find the ssh_authorized_key for #{name}" unless stdout.include? "#{name}"
- end
-
-end
diff --git a/spec/acceptance/tests/resource/ssh_authorized_key/create_spec.rb b/spec/acceptance/tests/resource/ssh_authorized_key/create_spec.rb
new file mode 100644
index 0000000..5cf35fb
--- /dev/null
+++ b/spec/acceptance/tests/resource/ssh_authorized_key/create_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper_acceptance'
+
+RSpec.context 'ssh_authorized_key: Create' do
+ test_name 'should create an entry for an SSH authorized key'
+
+ let(:auth_keys) { '~/.ssh/authorized_keys' }
+ let(:name) { "pl#{rand(999_999).to_i}" }
+
+ before(:each) do
+ posix_agents.each do |agent|
+ on(agent, "cp #{auth_keys} /tmp/auth_keys", acceptable_exit_codes: [0, 1])
+ on(agent, "chown $LOGNAME #{auth_keys}")
+ end
+ end
+
+ after(:each) do
+ posix_agents.each do |agent|
+ # (teardown) restore the #{auth_keys} file
+ on(agent, "mv /tmp/auth_keys #{auth_keys}", acceptable_exit_codes: [0, 1])
+ end
+ end
+
+ posix_agents.each do |agent|
+ it "#{agent} should create an entry for an SSH authorized key" do
+ args = ['ensure=present',
+ 'user=$LOGNAME',
+ "type='rsa'",
+ "key='mykey'"]
+ on(agent, puppet_resource('ssh_authorized_key', name.to_s, args))
+
+ on(agent, "cat #{auth_keys}") do |_res|
+ fail_test "didn't find the ssh_authorized_key for #{name}" unless stdout.include? name.to_s
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/tests/resource/ssh_authorized_key/destroy.rb b/spec/acceptance/tests/resource/ssh_authorized_key/destroy.rb
deleted file mode 100644
index c80e967..0000000
--- a/spec/acceptance/tests/resource/ssh_authorized_key/destroy.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-test_name "should delete an entry for an SSH authorized key"
-
-tag 'audit:medium',
- 'audit:refactor', # Use block style `test_run`
- 'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
-
-confine :except, :platform => ['windows']
-
-auth_keys = '~/.ssh/authorized_keys'
-name = "pl#{rand(999999).to_i}"
-
-agents.each do |agent|
- teardown do
- #(teardown) restore the #{auth_keys} file
- on(agent, "mv /tmp/auth_keys #{auth_keys}", :acceptable_exit_codes => [0,1])
- end
-
- #------- SETUP -------#
- step "(setup) backup #{auth_keys} file"
- on(agent, "cp #{auth_keys} /tmp/auth_keys", :acceptable_exit_codes => [0,1])
-
- step "(setup) create an authorized key in the #{auth_keys} file"
- on(agent, "echo '' >> #{auth_keys} && echo 'ssh-rsa mykey #{name}' >> #{auth_keys}")
- on(agent, "chown $LOGNAME #{auth_keys}")
-
- #------- TESTS -------#
- step "delete an authorized key entry with puppet (absent)"
- args = ['ensure=absent',
- "user=$LOGNAME",
- "type='rsa'",
- "key='mykey'",
- ]
- on(agent, puppet_resource('ssh_authorized_key', "#{name}", args))
-
- step "verify entry deleted from #{auth_keys}"
- on(agent, "cat #{auth_keys}") do |res|
- fail_test "found the ssh_authorized_key for #{name}" if stdout.include? "#{name}"
- end
-
-end
diff --git a/spec/acceptance/tests/resource/ssh_authorized_key/destroy_spec.rb b/spec/acceptance/tests/resource/ssh_authorized_key/destroy_spec.rb
new file mode 100644
index 0000000..af160ce
--- /dev/null
+++ b/spec/acceptance/tests/resource/ssh_authorized_key/destroy_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper_acceptance'
+
+RSpec.context 'sshkeys: Destroy' do
+ confine :except, platform: ['windows']
+
+ let(:auth_keys) { '~/.ssh/authorized_keys' }
+ let(:name) { "pl#{rand(999_999).to_i}" }
+
+ before(:each) do
+ posix_agents.each do |agent|
+ on(agent, "cp #{auth_keys} /tmp/auth_keys", acceptable_exit_codes: [0, 1])
+
+ on(agent, "echo '' >> #{auth_keys} && echo 'ssh-rsa mykey #{name}' >> #{auth_keys}")
+ on(agent, "chown $LOGNAME #{auth_keys}")
+ end
+ end
+
+ after(:each) do
+ posix_agents.each do |agent|
+ # (teardown) restore the #{auth_keys} file
+ on(agent, "mv /tmp/auth_keys #{auth_keys}", acceptable_exit_codes: [0, 1])
+ end
+ end
+
+ posix_agents.each do |agent|
+ it "#{agent} should delete an entry for an SSH authorized key" do
+ args = ['ensure=absent',
+ 'user=$LOGNAME',
+ "type='rsa'",
+ "key='mykey'"]
+ on(agent, puppet_resource('ssh_authorized_key', name.to_s, args))
+
+ on(agent, "cat #{auth_keys}") do |_res|
+ expect(stdout).not_to include(name.to_s)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/tests/resource/ssh_authorized_key/modify.rb b/spec/acceptance/tests/resource/ssh_authorized_key/modify.rb
deleted file mode 100644
index 0a50c31..0000000
--- a/spec/acceptance/tests/resource/ssh_authorized_key/modify.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-test_name "should update an entry for an SSH authorized key"
-
-tag 'audit:medium',
- 'audit:refactor', # Use block style `test_run`
- 'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
-
-confine :except, :platform => ['windows']
-
-auth_keys = '~/.ssh/authorized_keys'
-name = "pl#{rand(999999).to_i}"
-
-agents.each do |agent|
- teardown do
- #(teardown) restore the #{auth_keys} file
- on(agent, "mv /tmp/auth_keys #{auth_keys}", :acceptable_exit_codes => [0,1])
- end
-
- #------- SETUP -------#
- step "(setup) backup #{auth_keys} file"
- on(agent, "cp #{auth_keys} /tmp/auth_keys", :acceptable_exit_codes => [0,1])
-
- step "(setup) create an authorized key in the #{auth_keys} file"
- on(agent, "echo '' >> #{auth_keys} && echo 'ssh-rsa mykey #{name}' >> #{auth_keys}")
- on(agent, "chown $LOGNAME #{auth_keys}")
-
- #------- TESTS -------#
- step "update an authorized key entry with puppet (present)"
- args = ['ensure=present',
- "user=$LOGNAME",
- "type='rsa'",
- "key='mynewshinykey'",
- ]
- on(agent, puppet_resource('ssh_authorized_key', "#{name}", args))
-
- step "verify entry updated in #{auth_keys}"
- on(agent, "cat #{auth_keys}") do |res|
- fail_test "didn't find the updated key for #{name}" unless stdout.include? "mynewshinykey #{name}"
- fail_test "Found old key mykey #{name}" if stdout.include? "mykey #{name}"
- end
-
-end
diff --git a/spec/acceptance/tests/resource/ssh_authorized_key/modify_spec.rb b/spec/acceptance/tests/resource/ssh_authorized_key/modify_spec.rb
new file mode 100644
index 0000000..3a46374
--- /dev/null
+++ b/spec/acceptance/tests/resource/ssh_authorized_key/modify_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper_acceptance'
+
+RSpec.context 'sshkeys: Modify' do
+ let(:auth_keys) { '~/.ssh/authorized_keys' }
+ let(:name) { "pl#{rand(999_999).to_i}" }
+
+ before(:each) do
+ posix_agents.each do |agent|
+ on(agent, "cp #{auth_keys} /tmp/auth_keys", acceptable_exit_codes: [0, 1])
+ on(agent, "echo '' >> #{auth_keys} && echo 'ssh-rsa mykey #{name}' >> #{auth_keys}")
+ on(agent, "chown $LOGNAME #{auth_keys}")
+ end
+ end
+
+ after(:each) do
+ posix_agents.each do |agent|
+ # (teardown) restore the #{auth_keys} file
+ on(agent, "mv /tmp/auth_keys #{auth_keys}", acceptable_exit_codes: [0, 1])
+ end
+ end
+
+ posix_agents.each do |agent|
+ it "#{agent} should update an entry for an SSH authorized key" do
+ args = ['ensure=present',
+ 'user=$LOGNAME',
+ "type='rsa'",
+ "key='mynewshinykey'"]
+ on(agent, puppet_resource('ssh_authorized_key', name.to_s, args))
+
+ on(agent, "cat #{auth_keys}") do |_res|
+ expect(stdout).to include("mynewshinykey #{name}")
+ expect(stdout).not_to include("mykey #{name}")
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/tests/resource/ssh_authorized_key/query.rb b/spec/acceptance/tests/resource/ssh_authorized_key/query.rb
deleted file mode 100644
index 8caff85..0000000
--- a/spec/acceptance/tests/resource/ssh_authorized_key/query.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-test_name "should be able to find an existing SSH authorized key"
-
-tag 'audit:medium',
- 'audit:refactor', # Use block style `test_run`
- 'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
-
-skip_test("This test is blocked by PUP-1605")
-
-confine :except, :platform => ['windows']
-
-auth_keys = '~/.ssh/authorized_keys'
-name = "pl#{rand(999999).to_i}"
-
-agents.each do |agent|
- teardown do
- #(teardown) restore the #{auth_keys} file
- on(agent, "mv /tmp/auth_keys #{auth_keys}", :acceptable_exit_codes => [0,1])
- end
-
- #------- SETUP -------#
- step "(setup) backup #{auth_keys} file"
- on(agent, "cp #{auth_keys} /tmp/auth_keys", :acceptable_exit_codes => [0,1])
-
- step "(setup) create an authorized key in the #{auth_keys} file"
- on(agent, "echo '' >> #{auth_keys} && echo 'ssh-rsa mykey #{name}' >> #{auth_keys}")
-
- #------- TESTS -------#
- step "verify SSH authorized key query with puppet"
- on(agent, puppet_resource('ssh_authorized_key', "/#{name}")) do |res|
- fail_test "Didn't find the ssh_authorized_key for #{name}" unless stdout.include? "#{name}"
- end
-
-end
diff --git a/spec/acceptance/tests/resource/sshkey/create.rb b/spec/acceptance/tests/resource/sshkey/create.rb
deleted file mode 100644
index 4e75379..0000000
--- a/spec/acceptance/tests/resource/sshkey/create.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-test_name "(PUP-5508) Should add an SSH key to the correct ssh_known_hosts file on OS X/macOS" do
-# TestRail test case C93370
-
-tag 'audit:medium',
- 'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
-
-confine :to, :platform => /osx/
-
-keyname = "pl#{rand(999999).to_i}"
-
-# FIXME: This is bletcherous
-macos_version = fact_on(agent, "os.macosx.version.major")
-if ["10.9","10.10"].include? macos_version
- ssh_known_hosts = '/etc/ssh_known_hosts'
-else
- ssh_known_hosts = '/etc/ssh/ssh_known_hosts'
-end
-
-teardown do
- puts "Restore the #{ssh_known_hosts} file"
- agents.each do |agent|
- # Is it present?
- rc = on(agent, "[ -e /tmp/ssh_known_hosts ]",
- :accept_all_exit_codes => true)
- if rc.exit_code == 0
- # It's present, so restore the original
- on(agent, "mv -fv /tmp/ssh_known_hosts #{ssh_known_hosts}",
- :accept_all_exit_codes => true)
- else
- # It's missing, which means there wasn't one to backup; just
- # delete the one we laid down
- on(agent, "rm -fv #{ssh_known_hosts}",
- :accept_all_exit_codes => true)
- end
- end
-end
-
-#------- SETUP -------#
-step "Backup #{ssh_known_hosts} file, if present" do
- # The 'cp' might fail because the source file doesn't exist
- on(agent, "cp -fv #{ssh_known_hosts} /tmp/ssh_known_hosts",
- :acceptable_exit_codes => [0,1])
-end
-
-#------- TESTS -------#
-step 'Verify that the default file is empty or non-existent' do
- # Is it even there?
- rc = on(agent, "[ ! -e #{ssh_known_hosts} ]",
- :acceptable_exit_codes => [0, 1])
- if rc.exit_code == 1
- # If it's there, it should be empty
- on(agent, "cat #{ssh_known_hosts}") do |res|
- fail_test "Default #{ssh_known_hosts} file not empty" \
- unless stdout.empty?
- end
- end
-end
-
-step "Add an sshkey to the default file" do
- args = [
- "ensure=present",
- "key=how_about_the_key_of_c",
- "type=ssh-rsa",
- ]
- on(agent, puppet_resource("sshkey", "#{keyname}", args))
-end
-
-step 'Verify the new entry in the default file' do
- on(agent, "cat #{ssh_known_hosts}") do |rc|
- fail_test "Didn't find the ssh_known_host entry for #{keyname}" \
- unless stdout.include? "#{keyname}"
- end
-end
-
-end
diff --git a/spec/acceptance/tests/resource/sshkey/create_spec.rb b/spec/acceptance/tests/resource/sshkey/create_spec.rb
new file mode 100644
index 0000000..f6534b8
--- /dev/null
+++ b/spec/acceptance/tests/resource/sshkey/create_spec.rb
@@ -0,0 +1,81 @@
+require 'spec_helper_acceptance'
+
+RSpec.context 'sshkeys: Create' do
+ let(:keyname) { "pl#{rand(999_999).to_i}" }
+
+ # FIXME: This is bletcherous
+ let(:macos_version) { fact_on(agent, 'os.macosx.version.major') }
+ let(:ssh_known_hosts) do
+ if ['10.9', '10.10'].include? macos_version
+ '/etc/ssh_known_hosts'
+ else
+ '/etc/ssh/ssh_known_hosts'
+ end
+ end
+
+ before(:each) do
+ osx_agents.each do |agent|
+ # The 'cp' might fail because the source file doesn't exist
+ on(
+ agent,
+ "cp -fv #{ssh_known_hosts} /tmp/ssh_known_hosts",
+ acceptable_exit_codes: [0, 1],
+ )
+ end
+ end
+
+ after(:each) do
+ osx_agents.each do |agent|
+ # Is it present?
+ rc = on(
+ agent,
+ '[ -e /tmp/ssh_known_hosts ]',
+ accept_all_exit_codes: true,
+ )
+ if rc.exit_code == 0
+ # It's present, so restore the original
+ on(
+ agent,
+ "mv -fv /tmp/ssh_known_hosts #{ssh_known_hosts}",
+ accept_all_exit_codes: true,
+ )
+ else
+ # It's missing, which means there wasn't one to backup; just
+ # delete the one we laid down
+ on(
+ agent,
+ "rm -fv #{ssh_known_hosts}",
+ accept_all_exit_codes: true,
+ )
+ end
+ end
+ end
+
+ osx_agents.each do |agent|
+ it "#{agent} should add an SSH key to the correct ssh_known_hosts file on OS X/macOS (PUP-5508)" do
+ # Is it even there?
+ rc = on(
+ agent,
+ "[ ! -e #{ssh_known_hosts} ]",
+ acceptable_exit_codes: [0, 1],
+ )
+ if rc.exit_code == 1
+ # If it's there, it should be empty
+ on(agent, "cat #{ssh_known_hosts}") do |_res|
+ expect(stdout).to be_empty
+ end
+ end
+
+ args = [
+ 'ensure=present',
+ 'key=how_about_the_key_of_c',
+ 'type=ssh-rsa',
+ ]
+ on(agent, puppet_resource('sshkey', keyname.to_s, args))
+
+ on(agent, "cat #{ssh_known_hosts}") do |_rc|
+ expect(stdout).to include(keyname.to_s)
+ end
+ end
+ end
+end