Commit 3d2ec89a authored by Geoff Meakin's avatar Geoff Meakin

Added Cucumber tests initial

parent a58d8547
......@@ -3,3 +3,4 @@
*.gradle
keys/*.pem
pkg/
tmp/
......@@ -3,3 +3,8 @@ source 'https://rubygems.org/'
gem 'highline'
gem 'trollop'
group :development do
gem "aruba"
end
GEM
remote: https://rubygems.org/
specs:
aruba (0.5.3)
childprocess (>= 0.3.6)
cucumber (>= 1.1.1)
rspec-expectations (>= 2.7.0)
builder (3.2.2)
childprocess (0.3.9)
ffi (~> 1.0, >= 1.0.11)
cucumber (1.3.5)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12.0)
multi_json (~> 1.7.5)
multi_test (>= 0.0.2)
diff-lcs (1.2.4)
ffi (1.9.0)
gherkin (2.12.0)
multi_json (~> 1.3)
highline (1.6.19)
multi_json (1.7.8)
multi_test (0.0.2)
rspec-expectations (2.14.0)
diff-lcs (>= 1.1.3, < 2.0)
trollop (2.0)
PLATFORMS
ruby
DEPENDENCIES
aruba
highline
trollop
Feature: eyaml encrypting
In order to encrypt data
As a developer using hiera-eyaml
I want to use the eyaml tool to ecnrypt data in various ways
Scenario: encrypt a simple string
When I run `eyaml -e -o string -s some_string`
Then the output should match /ENC\[PKCS7,(.*?)\]$/
Scenario: encrypt a simple file
When I run `eyaml -e -o string -f test_input.txt`
Then the output should match /ENC\[PKCS7,(.*?)\]$/
Scenario: encrypt a binary file
When I run `eyaml -e -o string -f test_input.bin`
Then the output should match /ENC\[PKCS7,(.*?)\]$/
Scenario: encrypt a password
When I run `./with_password eyaml -e -o string -p`
Then the file "password.output" should match /ENC\[PKCS7,(.*?)\]/
Feature: eyaml outputs
In order to better understand the link between eyaml and yaml files
As a developer using hiera-eyaml
I want to use the eyaml tool to output encrypted data in various yaml formats
Scenario: encrypt a simple string with default output
When I run `eyaml -e -s some_string`
Then the output should match /string: ENC\[PKCS7,(.*?)\]/
And the output should match /block: >\s*\n\s*ENC\[PKCS7,(.*?)\]/
Scenario: encrypt a simple string with examples output
When I run `eyaml -e -o examples -s some_string`
Then the output should match /string: ENC\[PKCS7,(.*?)\]/
And the output should match /block: >\s*\n\s*ENC\[PKCS7,(.*?)\]/
Scenario: encrypt a simple string with string output
When I run `eyaml -e -o string -s some_string`
Then the output should match /^ENC\[PKCS7,(.*?)\]$/
Scenario: encrypt a simple string with raw output
When I run `eyaml -e -o raw -s some_string`
Then the output should match /^ENC\[PKCS7,(.*?)\]$/
And the output should contain "\n"
Scenario: encrypt a simple string with block output
When I run `eyaml -e -o block -s some_string`
Then the output should match /^\s+ENC\[PKCS7,(.*?)\]$/
Given /^I have pkcs7 keys available in the keys subdir$/ do
# Dir.mkdir("tmp/aruba/keys")
# File.open("keys/private_key.pkcs7.pem", "w") {|private_key|
#private_key.puts '''
# -----BEGIN RSA PRIVATE KEY-----
# MIIEowIBAAKCAQEA0kX0qkf4FOHXuFqlVmbgo+UDrJdneH8XnmWM+stAs0XpzEQq
# ErelZUhEi2x5z16RAsEw3cjd2BG78WHz1lcu3NP25BM990YQDl6e9pvmeMNA+wCK
# 1bwD7fCWXrAKb7xIXPJVd0ivP82ZPe71CmkFtiFr14mqNWrEpP/d2eQ4PAaCimAE
# bBKyRRHHJzU6X+hOnq8GRZBwKh6Ljl31JYE2DG3KQ+ydM+r411jY2sjSykOovbeR
# b7FCyOPaLRgyNjiDIJSTRlWLVJbYj6KDSoUD2+R95Owb5Z1OUL9Yn/BRIv5RyDvf
# Br42sp0KR7t3pWGiHEuRYZkGDU5jKB/8bK7DRwIDAQABAoIBAERJKZp/AsatTSP2
# dAkqIbu37MiI5rZP97id2/m6NgnCI5oNbOhlMVZB8NiiYrCAUnFlkdwEll7L65AJ
# MmmiKHrYby5EPXRnEWHJQrBtkpwXNKwO0gd1JoWIAx0+6DS/HXTp0e2J8jezKhfd
# 2UAHOS6bje0SLO9p+/Blk4NmRQjgsYk5nunl463+IkRGU8cna7GIOnvExrT6H3FD
# UsL9hL1J/+f4cSmsJoNHtQfKV0OkmQhENpFFwVMunMJPDjGEbaliKqqX05ZnJ1Tu
# kDKG+QL1wJbehDNNpiwTGo+Ei8EbP8LYsSkKtMl0zVED636AiuQ259oNDGXo2f+t
# FG/1WOECgYEA8OTaHbWgUvtatGBsZ5PIw1VIRG7LZESF0HvlnkZOsCFg2NWrQ99U
# sL2gLC0DVi80Yijjk0Kvrp5zU010uU4CuJHzT9ZN/nlPlwTteL6kr8XIh2sTpuE6
# nfx4E309d366Hh5xy82AQ+jIeQZTAaPHlFmINrncS48WTfP6lxn5f3ECgYEA33WK
# OtImhr4RYRmzcsfybW7PgxxpMSnrex/omZPWEHB14Fa2J6ny3KI9qBP1x6/h6Jfe
# SonD4MZ48opiNljfWmgkJMSkqalpa3jDGc8vX1uWhn8NdAuFKAn5zLZC8mZ27VUI
# LXLcChjyKPKVTwRnaNe0+rq7MgsqJJ4jo2atgjcCgYEAxPr9+IlKXlC3LQQj4NaR
# tliITZ0jqAv4ODD35GKteYzxup2N/GQkxplo3na4YcMb3KB+5y4CppFe0GFn7xcB
# VpfSFBizkkD0ehNHdBLAbBMZFNLUMQO/gOyv64/fsVTpMDPI7dRO7DjvpTcsrQyV
# 6JMFtWpp30dT/85fvSs6P6ECgYB2Sp2rN7ZHW/SNR3K0T15pSeC2EmMpMHzEyAZ0
# zkrilvX/lUeGRbQX0hb7k91nIRdg7owxPy6fHdHG6zTEelV6YWjIwgQ9AD6bMult
# Dz2PqEdN2ZJAnRyXLni7Qry73zwTtRDIJmaPPddrj8c0ditb19ypYhJYkopzqfdJ
# t8AgDwKBgCyJLYU7pjhfJwOOVJjACa8ndtg0vIr+MGoe99/2hWm7QdX5PrOjDLOr
# PeopgafeF1G6chhs4Qqh4LCmDA2NeX+zWcHkjLrKUIXMwb2YPuna7WToyCCeAm8+
# K5Lnssm0P/UJI3CAef/4GXb30ZJYOhsU15/XwY5c8+f6IxRIpPEN
# -----END RSA PRIVATE KEY-----
# '''
# }
# File.open("keys/public_key.pkcs7.pem", "w") {|public_key|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end
\ No newline at end of file
ENV['RUBYLIB'] = File.dirname(__FILE__) + '/../../lib'
require 'rubygems'
require 'aruba/config'
require 'aruba/cucumber'
require 'fileutils'
require 'rspec/expectations'
Aruba.configure do |config|
config.before_cmd do |cmd|
Setup.create_inputs
end
end
class Setup
def self.create_inputs
Dir.mkdir("keys") unless Dir.exists?("keys")
File.open("keys/private_key.pkcs7.pem", "w") {|private_key|
private_key.puts '''
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA0kX0qkf4FOHXuFqlVmbgo+UDrJdneH8XnmWM+stAs0XpzEQq
ErelZUhEi2x5z16RAsEw3cjd2BG78WHz1lcu3NP25BM990YQDl6e9pvmeMNA+wCK
1bwD7fCWXrAKb7xIXPJVd0ivP82ZPe71CmkFtiFr14mqNWrEpP/d2eQ4PAaCimAE
bBKyRRHHJzU6X+hOnq8GRZBwKh6Ljl31JYE2DG3KQ+ydM+r411jY2sjSykOovbeR
b7FCyOPaLRgyNjiDIJSTRlWLVJbYj6KDSoUD2+R95Owb5Z1OUL9Yn/BRIv5RyDvf
Br42sp0KR7t3pWGiHEuRYZkGDU5jKB/8bK7DRwIDAQABAoIBAERJKZp/AsatTSP2
dAkqIbu37MiI5rZP97id2/m6NgnCI5oNbOhlMVZB8NiiYrCAUnFlkdwEll7L65AJ
MmmiKHrYby5EPXRnEWHJQrBtkpwXNKwO0gd1JoWIAx0+6DS/HXTp0e2J8jezKhfd
2UAHOS6bje0SLO9p+/Blk4NmRQjgsYk5nunl463+IkRGU8cna7GIOnvExrT6H3FD
UsL9hL1J/+f4cSmsJoNHtQfKV0OkmQhENpFFwVMunMJPDjGEbaliKqqX05ZnJ1Tu
kDKG+QL1wJbehDNNpiwTGo+Ei8EbP8LYsSkKtMl0zVED636AiuQ259oNDGXo2f+t
FG/1WOECgYEA8OTaHbWgUvtatGBsZ5PIw1VIRG7LZESF0HvlnkZOsCFg2NWrQ99U
sL2gLC0DVi80Yijjk0Kvrp5zU010uU4CuJHzT9ZN/nlPlwTteL6kr8XIh2sTpuE6
nfx4E309d366Hh5xy82AQ+jIeQZTAaPHlFmINrncS48WTfP6lxn5f3ECgYEA33WK
OtImhr4RYRmzcsfybW7PgxxpMSnrex/omZPWEHB14Fa2J6ny3KI9qBP1x6/h6Jfe
SonD4MZ48opiNljfWmgkJMSkqalpa3jDGc8vX1uWhn8NdAuFKAn5zLZC8mZ27VUI
LXLcChjyKPKVTwRnaNe0+rq7MgsqJJ4jo2atgjcCgYEAxPr9+IlKXlC3LQQj4NaR
tliITZ0jqAv4ODD35GKteYzxup2N/GQkxplo3na4YcMb3KB+5y4CppFe0GFn7xcB
VpfSFBizkkD0ehNHdBLAbBMZFNLUMQO/gOyv64/fsVTpMDPI7dRO7DjvpTcsrQyV
6JMFtWpp30dT/85fvSs6P6ECgYB2Sp2rN7ZHW/SNR3K0T15pSeC2EmMpMHzEyAZ0
zkrilvX/lUeGRbQX0hb7k91nIRdg7owxPy6fHdHG6zTEelV6YWjIwgQ9AD6bMult
Dz2PqEdN2ZJAnRyXLni7Qry73zwTtRDIJmaPPddrj8c0ditb19ypYhJYkopzqfdJ
t8AgDwKBgCyJLYU7pjhfJwOOVJjACa8ndtg0vIr+MGoe99/2hWm7QdX5PrOjDLOr
PeopgafeF1G6chhs4Qqh4LCmDA2NeX+zWcHkjLrKUIXMwb2YPuna7WToyCCeAm8+
K5Lnssm0P/UJI3CAef/4GXb30ZJYOhsU15/XwY5c8+f6IxRIpPEN
-----END RSA PRIVATE KEY-----
'''
} unless File.exists?("keys/private_key.pkcs7.pem")
File.open("keys/public_key.pkcs7.pem", "w") {|public_key|
public_key.puts '''-----BEGIN CERTIFICATE-----
MIIC2TCCAcGgAwIBAgIBADANBgkqhkiG9w0BAQUFADAAMCAXDTEzMDgwMTE3MzU0
NVoYDzIwNjMwNzIwMTczNTQ1WjAAMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEA0kX0qkf4FOHXuFqlVmbgo+UDrJdneH8XnmWM+stAs0XpzEQqErelZUhE
i2x5z16RAsEw3cjd2BG78WHz1lcu3NP25BM990YQDl6e9pvmeMNA+wCK1bwD7fCW
XrAKb7xIXPJVd0ivP82ZPe71CmkFtiFr14mqNWrEpP/d2eQ4PAaCimAEbBKyRRHH
JzU6X+hOnq8GRZBwKh6Ljl31JYE2DG3KQ+ydM+r411jY2sjSykOovbeRb7FCyOPa
LRgyNjiDIJSTRlWLVJbYj6KDSoUD2+R95Owb5Z1OUL9Yn/BRIv5RyDvfBr42sp0K
R7t3pWGiHEuRYZkGDU5jKB/8bK7DRwIDAQABo1wwWjAPBgNVHRMBAf8EBTADAQH/
MB0GA1UdDgQWBBR7PyZZ/WlaSjAf6GO2GLWXO5aINDAoBgNVHSMEITAfgBR7PyZZ
/WlaSjAf6GO2GLWXO5aINKEEpAIwAIIBADANBgkqhkiG9w0BAQUFAAOCAQEAspcX
VNb156OZqPxteosI2ijeewDH0sc3ogRDZnxbXqG6Pa44QzJNTUULaX3iEfmFw4TL
MW90NU4w4rzSIBGDGHTBOKZZBa2iTVRsYHuQ7Sd1A1MKc1dDFs9+Uj/6/vQ8Fkdx
v+iei5N/XFccgto4HiohXvEZhT4NjONIFR9UL+lWChp8OVb+ifOWCKF69iUUbMPC
uD7+UkrCYoVeVXkG1Rvw4E6BAbi75P6inX0lUnzNs4B0rvFynnV1Nsdb89cxI3pL
Q0yVE8/aIP9donqjXTu0h/GmOtVQH654NCQSs1dLD+K4+8mn591Nv4uLrCiNJzTM
zGRUV6zOPlUa3ye6Dg==
-----END CERTIFICATE-----
'''
} unless File.exists?("keys/public_key.pkcs7.pem")
File.open("with_password", "w") {|expect_script|
expect_script.puts '''#!/usr/bin/expect -f
log_file password.output
spawn bash -c "[lindex $argv]"
expect "Enter password"
send "secretme\n"
expect eof
'''
} unless File.exists?("with_password")
File.chmod(0755, "with_password")
File.open("test_input.txt", "w") {|input_file|
input_file.puts '''The quick brown
fox jumped over
the lazy dog'''
} unless File.exists?("test_input.txt")
File.open("test_input.bin", "wb") {|input_file|
input_file.puts ["89504e470d0a1a0a0000000d494844520000000a0000000a0802000000025058ea000000097048597300000b1300000b1301009a9c180000000774494d4507dd0801122a39c574bacb0000001d69545874436f6d6d656e7400000000004372656174656420776974682047494d50642e6507000000504944415418d3754f490e0021082bc4fff5ad7d211e341d4623a7862e94a82abc67184584b13dc39ca42e5d8abc39009256587a45f2003fda013d297b26c96e05b02b1ce7497ed5ee93ae167eb1ffed995e99262fb16f7a65000000004945"].pack('H*')
} unless File.exists?("test_input.bin")
end
end
Feature: eyaml encrypting is valid
Scenario: encrypt and decrypt a simple file
When I run `bash -c "eyaml -e -o string -f test_input.txt > test_output.txt"`
When I run `eyaml -d -f test_output.txt`
Then the output should match /BOO$/
Scenario: encrypt and decrypt a binary file
When I run `bash -c "eyaml -e -o string -f test_input.bin > test_output.txt"`
When I run `bash -c "eyaml -d -f test_output.txt > test_output.bin"`
When I run `file test_output.bin`
Then the output should match /PNG image data/
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