Skip to content

Commit

Permalink
Merge pull request #469 from Dan33l/enable_acceptance_tests
Browse files Browse the repository at this point in the history
enable acceptance tests
  • Loading branch information
Dan33l committed Dec 2, 2018
2 parents a9b9571 + a140987 commit c8f5eb6
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 91 deletions.
4 changes: 4 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
.travis.yml:
docker_sets:
- set: ubuntu1404-64
- set: centos7-64
- set: centos6-64
secure: "WcBaQ0iem0kLmgOHvOEYOsgAk6eFZcSJ/6AisPhS4Ty9gxaEcytE8if2d9ThOItRRua5XGAPk7WbYmTa/cy/EsH0LYwSDdP2eagI95CnmryGya5TShKwUMv1ETUOBFucRYxtcOo7URnTMe2d6IpxEazuZ87cwGLUV5taBRkEvkw="
55 changes: 55 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,61 @@ matrix:
- rvm: 2.4.4
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes
- rvm: 2.5.1
bundler_args: --without development release
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1404-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
bundler_args: --without development release
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1404-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
bundler_args: --without development release
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=ubuntu1404-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
bundler_args: --without development release
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos6-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
bundler_args: --without development release
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos6-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
bundler_args: --without development release
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=centos6-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
bundler_args: --without development release
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
bundler_args: --without development release
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos7-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
bundler_args: --without development release
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=centos7-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required

branches:
only:
- master
Expand Down
54 changes: 23 additions & 31 deletions spec/acceptance/basic_webhook_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require 'spec_helper_acceptance'
require 'json'

describe 'System Ruby with No SSL, Not protected, No mcollective' do
context 'default parameters' do
let(:pp) do
"
pp = %(
class { 'r10k':
remote => 'git@github.com:someuser/puppet.git',
}
Expand All @@ -17,8 +16,7 @@ class {'r10k::webhook::config':
class {'r10k::webhook':
require => Class['r10k::webhook::config'],
}
"
end
)

it 'applies with no errors' do
apply_manifest(pp, catch_failures: true)
Expand All @@ -30,38 +28,32 @@ class {'r10k::webhook':
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

# rubocop:disable RSpec/RepeatedExample
shell('/usr/bin/curl -d \'{ "repository": { "name": "puppetlabs-stdlib" } }\' -H "Accept: application/json" "http://localhost:8088/module" -k -q') do |r|
it { expect(r.stdout).to match(%r{^.*success.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command('/usr/bin/curl -d \'{ "repository": { "name": "puppetlabs-stdlib" } }\' -H "Accept: application/json" "http://localhost:8088/module" -k -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
shell('/usr/bin/curl -X POST -d \'{ "repository": { "full_name": "puppetlabs/puppetlabs-stdlib", "name": "PuppetLabs : StdLib" } }\' "http://localhost:8088/module" -k -q') do |r|
it { expect(r.stdout).to match(%r{^.*success.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command('/usr/bin/curl -X POST -d \'{ "repository": { "full_name": "puppetlabs/puppetlabs-stdlib", "name": "PuppetLabs : StdLib" } }\' "http://localhost:8088/module" -k -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
shell('/usr/bin/curl -d \'{ "ref": "refs/heads/production" }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do |r|
it { expect(r.stdout).to match(%r{^.*success.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command('/usr/bin/curl -d \'{ "ref": "refs/heads/production" }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
shell('/usr/bin/curl -X POST -d \'%7b%22ref%22%3a%22master%22%7d\' "http://localhost:8088/payload" -q') do |r|
it { expect(r.stdout).to match(%r{^.*success.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command('/usr/bin/curl -X POST -d \'%7b%22ref%22%3a%22maste%r22%7d\' "http://localhost:8088/payload" -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
shell('/usr/bin/curl -X POST -d \'{ "push": { "changes": [ { "new": { "name": "production" } } ] } }\' "http://localhost:8088/payload" -q') do |r|
it { expect(r.stdout).to match(%r{^.*success.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command('/usr/bin/curl -X POST -d \'{ "push": { "changes": [ { "new": { "name": "production" } } ] } }\' "http://localhost:8088/payload" -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
# rubocop:enable RSpec/RepeatedExample

# rubocop:disable RSpec/MultipleExpectations
it 'successfully locks when hammered with multiple requests' do
4.times do
Thread.new do
shell('/usr/bin/curl -d \'{ "ref": "refs/heads/production" }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do |r|
expect(r.stdout).to match(%r{^.*success.*$})
expect(r.exit_code).to eq(0)
end
4.times do
Thread.new do
describe command('/usr/bin/curl -d \'{ "ref": "refs/heads/production" }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
end
end
Expand Down
34 changes: 15 additions & 19 deletions spec/acceptance/prefix_webhook_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require 'spec_helper_acceptance'
require 'json'

describe 'Prefix Enabled,System Ruby with No SSL, Not protected, No mcollective' do
context 'default parameters' do
let(:pp) do
"
pp = %(
file {'/usr/local/bin/prefix_command.rb':
ensure => file,
mode => '0755',
Expand Down Expand Up @@ -46,8 +45,7 @@ class {'r10k::webhook::config':
class {'r10k::webhook':
require => Class['r10k::webhook::config'],
}
"
end
)

it 'applies with no errors' do
apply_manifest(pp, catch_failures: true)
Expand All @@ -60,23 +58,21 @@ class {'r10k::webhook':
it { is_expected.to be_running }
end

# rubocop:disable RSpec/RepeatedExample
shell('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/webteam/somerepo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do |r|
it { expect(r.stdout).to match(%r{^.*webteam_production.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/webteam/somerepo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
shell('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/secteam/someotherrepo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do |r|
it { expect(r.stdout).to match(%r{^.*secteam_production.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/secteam/someotherrepo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
shell('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/customprefix/repo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do |r|
it { expect(r.stdout).to match(%r{^.*custom_production.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/customprefix/repo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
shell('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/noprefix/repo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do |r|
it { expect(r.stdout).to match(%r{^.* production.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command('/usr/bin/curl -d \'{ "ref": "refs/heads/production", "repository": { "name": "puppet-control" , "url": "https://github.com/noprefix/repo.git"} }\' -H "Accept: application/json" "http://localhost:8088/payload" -k -q') do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
# rubocop:enable RSpec/RepeatedExample
end
end
26 changes: 10 additions & 16 deletions spec/acceptance/signature_webhook_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'spec_helper_acceptance'
require 'json'
require 'openssl'

describe 'GitHub Secret Enabled, System Ruby with No SSL, Not protected, No mcollective' do
context 'default parameters' do
let(:pp) do
"
pp = %(
class { 'r10k':
remote => 'git@github.com:someuser/puppet.git',
}
Expand All @@ -18,8 +17,7 @@ class {'r10k::webhook::config':
class {'r10k::webhook':
require => Class['r10k::webhook::config'],
}
"
end
)

it 'applies with no errors' do
apply_manifest(pp, catch_failures: true)
Expand All @@ -31,27 +29,23 @@ class {'r10k::webhook':
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

context 'supports style Github payloads via module end point with signature in header' do
HMAC_DIGEST = OpenSSL::Digest::Digest.new('sha1')
signature = 'sha1=' + OpenSSL::HMAC.hexdigest(HMAC_DIGEST, 'secret', '{ "repository": { "name": "puppetlabs-stdlib" } }')

shell("/usr/bin/curl -d '{ \"repository\": { \"name\": \"puppetlabs-stdlib\" } }' -H \"Accept: application/json\" \"http://localhost:8088/module\" -H \"X-Hub-Signature: #{signature}\" -k -q") do |r|
it { expect(r.stdout).to match(%r{^.*success.*$}) }
it { expect(r.exit_code).to eq(0) }
describe command("/usr/bin/curl -d '{ \"repository\": { \"name\": \"puppetlabs-stdlib\" } }' -H \"Accept: application/json\" \"http://localhost:8088/module\" -H \"X-Hub-Signature: #{signature}\" -k -q") do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
end
context 'supports style Github payloads via payload end point with signature in header' do
HMAC_DIGEST = OpenSSL::Digest::Digest.new('sha1')
signature = 'sha1=' + OpenSSL::HMAC.hexdigest(HMAC_DIGEST, 'secret', '{ "ref": "refs/heads/production" }')

shell("/usr/bin/curl -d '{ \"ref\": \"refs/heads/production\" }' -H \"Accept: application/json\" -H \"X-Hub-Signature: #{signature}\" \"http://localhost:8088/payload\" -k -q") do |r|
it { expect(r.stdout).to match(%r{^.*success.*$}) }
it { expect(r.exit_code).to eq(0) }
end
end
it '/heartbeat is successful' do
shell('/usr/bin/curl -H \"Accept: application/json\" \"http://localhost:8088/heartbeat\" -k -q') do |r|
expect(r.stdout).to match(%r{^.*success.*$})
describe command("/usr/bin/curl -d '{ \"ref\": \"refs/heads/production\" }' -H \"Accept: application/json\" -H \"X-Hub-Signature: #{signature}\" \"http://localhost:8088/payload\" -k -q") do
its(:stdout) { is_expected.not_to match %r{.*You shall not pass.*} }
its(:exit_status) { is_expected.to eq 0 }
end
end
end
Expand Down
39 changes: 14 additions & 25 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
require 'json'
require 'beaker-rspec/spec_helper'
require 'beaker-rspec/helpers/serverspec'
require 'beaker-rspec'
require 'beaker-puppet'
require 'beaker/puppet_install_helper'
require 'beaker/module_install_helper'

unless ENV['BEAKER_provision'] == 'no'
hosts.each do |host|
# Install Puppet
if host.is_pe?
install_pe
else
install_puppet
end
end
end
run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no'
install_module
install_module_dependencies

RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))

# Readable test descriptions
c.formatter = :documentation

# Configure all nodes in nodeset
c.before :suite do
# Install module and dependencies
puppet_module_install(source: proj_root, module_name: 'r10k')
hosts.each do |host|
JSON.parse(File.read('metadata.json'))['dependencies'].each do |dependency|
on host, puppet('module', 'install', dependency['name'].to_s), acceptable_exit_codes: [0, 1]
end
hosts.each do |_host|
ensure_puppet_user_exists = %(
user { 'puppet':
ensure => present,
}
)
apply_manifest(ensure_puppet_user_exists, catch_failures: true)
end
end
end

0 comments on commit c8f5eb6

Please sign in to comment.