Skip to content

Commit

Permalink
Rudimentary system for full integration test (puppet + puppet-decrypt…
Browse files Browse the repository at this point in the history
… + hiera)
  • Loading branch information
maxlinc committed Jul 11, 2013
1 parent 8c724c8 commit 165ad94
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'cucumber'
require 'cucumber/rake/task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task :default => [:spec, :integration]

Cucumber::Rake::Task.new(:integration) do |t|
t.cucumber_opts = "features --format pretty"
end
4 changes: 4 additions & 0 deletions features/fixtures/data/overridden_secret_key.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
db_password:
value: 'ENC[blablabla==]'
secretkey: '/etc/some_other_key'
2 changes: 2 additions & 0 deletions features/fixtures/data/simple.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
db_password: 'ENC[okoNBVDGyHQaQQPKnTTJvA==]'
8 changes: 8 additions & 0 deletions features/fixtures/hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
:backends: yaml
:yaml:
:datadir: features/fixtures/data
:hierarchy:
- '%{::hiera_file}'
- common
:logger: console
5 changes: 5 additions & 0 deletions features/fixtures/manifests/overridden_secret_key.pp.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$decrypted = decrypt(hiera('db_password'))
notice($decrypted)
unless($decrypted == 'expected') {
fail("Expected 'expected', found $unexpected")
}
6 changes: 6 additions & 0 deletions features/fixtures/manifests/simple.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$decrypted = decrypt(hiera('db_password'))
notice($decrypted)
$expected = 'blablabla'
unless($decrypted == $expected) {
fail("Expected '$expected', found $unexpected")
}
11 changes: 11 additions & 0 deletions features/fixtures/secretkeys/encryptor_secret_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
idZdWf3d7s97FVG0iytPj03c2LhrumdUqk4T+aa1VVzp8vFmtQb7Vyy7SbjV4v4y
CLEat8x8jFb7IBl2yjW3KmC0TW1q1cKaeP8eHuYeqm9ZIQoUtDH+q+8KM5xso358
PAkDtxJcFmcRvD2SL47WYTd+xFjYEW5VxWhGCcNi/FRlmRSLL29sBcRGfJNhPBit
j3PiXxPrNIu4E1Ikm94C911x4YD/PO5yNOuhDQW5rs1z8G8TGmzXV64Vxg7rYcXc
8XK0auzDm+qTdSpP6vaLhFROcGgFVzFu5WWHZ0dpRL1UfDdjlQbHojRCfb4jZB+I
bXTS5BQFzClttcPYSwf44am3zwYCuLeZ5oWif2sxPBwUIubzPIoBObcdj/uIjljx
BBPcoPDW+zIbghVWxjoHkLinRdqtXQzMCS0pp8znRsT7v5mp7FZvzMLDO6belz+Q
LEd3YefLkOFU6B7kJq7XDrVP18G691SwhY08rSq0LyNlwEZ4E9ZD6hrUduHd3Bs7
yGNhGjvAEItfDv7MBcavkLZSO/q1QElbz5B7/3aiu2HPRfUmS/hiywJ3S1cxZp8Y
wVr0kqIxRxMoNfl4IqCaRsvlwGBeTHmpXqkcviQsQOuddMStGXKKptrXKxvhn4ca
72SUKYg7mvyCWD44mAxJyTfTso93Pkn95klRtyBunu0=
14 changes: 14 additions & 0 deletions features/hiera.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Puppet works

Scenario: Simple test
Given I have the following hiera data:
"""
---
db_password: ENC[wx0qTorBqPrTrgkbzYirlA==]
"""
When I execute this puppet manifest:
"""
$password = decrypt(hiera('db_password'))
notice($password)
"""
Then the output should include "Notice: Scope(Class[main]): max"
27 changes: 27 additions & 0 deletions features/step_definitions/puppet_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'tempfile'

Given /^I have the following hiera data:$/ do |hieradata|
hierafile = Thread.current[:hierafile]
hierafile.write(hieradata)
hierafile.close
end

When /^I execute this puppet manifest:$/ do |manifest|
hierafile = Thread.current[:hierafile]
file = Tempfile.new('test_manifest')
begin
file.write(manifest)
file.close
ENV['FACTER_HIERA_FILE'] = File.basename(hierafile, '.yaml')
ENV['PUPPET_DECRYPT_KEYDIR'] = 'features/fixtures/secretkeys'
@output = `puppet apply --noop #{file.path} --hiera_config=features/fixtures/hiera.yaml`
puts @output
ensure
file.unlink
end
$?.success?
end

Then /^the output should include "([^"]*)"$/ do |content|
@output.should include content
end
10 changes: 10 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Around do | scenario, block |
hierafile = Tempfile.new(['hierafile', '.yaml'], 'features/fixtures/data')
Thread.current[:hierafile] = hierafile
begin
block.call
ensure
hierafile.close
hierafile.unlink
end
end
2 changes: 1 addition & 1 deletion lib/puppet-decrypt/decryptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Decrypt

class Decryptor
ENCRYPTED_PATTERN = /^ENC:?(?<key>\w*)\[(?<value>.*)\]$/
KEY_DIR = '/etc/puppet-decrypt'
KEY_DIR = ENV['PUPPET_DECRYPT_KEYDIR'] || '/etc/puppet-decrypt'
DEFAULT_KEY = 'encryptor_secret_key'
DEFAULT_FILE = File.join(KEY_DIR, DEFAULT_KEY)

Expand Down
2 changes: 2 additions & 0 deletions puppet-decrypt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Gem::Specification.new do |gem|

gem.add_dependency('encryptor')
gem.add_development_dependency('rake')
gem.add_development_dependency('cucumber')
gem.add_development_dependency('relish')
gem.add_development_dependency('rspec')
gem.add_development_dependency('rspec-puppet')
gem.add_development_dependency('puppetlabs_spec_helper')
Expand Down

0 comments on commit 165ad94

Please sign in to comment.