Skip to content

Commit 718e172

Browse files
committed
test(windows): initial commit of Windows testing using kitchen-vagrant
1 parent 6bbabf5 commit 718e172

File tree

9 files changed

+259
-0
lines changed

9 files changed

+259
-0
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ source "https://rubygems.org"
33
gem 'kitchen-docker', '>= 2.9'
44
gem 'kitchen-salt', '>= 0.6.0'
55
gem 'kitchen-inspec', '>= 1.1'
6+
gem "rspec-retry"
67

kitchen.windows.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
# For help on this file's format, see https://kitchen.ci/
5+
driver:
6+
name: vagrant
7+
linked_clone: true
8+
9+
# Make sure the platforms listed below match up with
10+
# the `env.matrix` instances defined in `.travis.yml`
11+
platforms:
12+
- name: windows
13+
driver:
14+
box: mwrock/Windows2012R2
15+
network:
16+
private_network:
17+
ip: 192.168.10.20
18+
provision: true
19+
vagrantfiles:
20+
- test/vagrant/Vagrantfile.rb
21+
- name: ubuntu
22+
driver:
23+
box: ubuntu/bionic64
24+
network:
25+
private_network:
26+
ip: 192.168.10.10
27+
28+
provisioner:
29+
name: salt_solo
30+
log_level: info
31+
require_chef: false
32+
formula: openvpn
33+
salt_copy_filter:
34+
- .kitchen
35+
- .git
36+
37+
verifier:
38+
# https://www.inspec.io/
39+
name: inspec
40+
sudo: true
41+
# cli, documentation, html, progress, json, json-min, json-rspec, junit
42+
reporter:
43+
- cli
44+
45+
suites:
46+
- name: default
47+
provisioner:
48+
state_top:
49+
base:
50+
'*':
51+
- openvpn.config
52+
pillars:
53+
top.sls:
54+
base:
55+
'*':
56+
- openvpn
57+
pillars_from_files:
58+
openvpn.sls: test/salt/pillar/windows.sls
59+
verifier:
60+
inspec_tests:
61+
- path: test/integration/windows

test/integration/windows/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# InSpec Profile: `windows`
2+
3+
This shows the implementation of the `windows` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md).
4+
5+
## Verify a profile
6+
7+
InSpec ships with built-in features to verify a profile structure.
8+
9+
```bash
10+
$ inspec check windows
11+
Summary
12+
-------
13+
Location: windows
14+
Profile: profile
15+
Controls: 4
16+
Timestamp: 2019-06-24T23:09:01+00:00
17+
Valid: true
18+
19+
Errors
20+
------
21+
22+
Warnings
23+
--------
24+
```
25+
26+
## Execute a profile
27+
28+
To run all **supported** controls on a local machine use `inspec exec /path/to/profile`.
29+
30+
```bash
31+
$ inspec exec windows
32+
..
33+
34+
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
35+
8 examples, 0 failures
36+
```
37+
38+
## Execute a specific control from a profile
39+
40+
To run one control from the profile use `inspec exec /path/to/profile --controls name`.
41+
42+
```bash
43+
$ inspec exec windows --controls package
44+
.
45+
46+
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
47+
1 examples, 0 failures
48+
```
49+
50+
See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
control 'OpenVPN client configuration' do
2+
title 'should match desired lines'
3+
4+
cfgfile = 'C:\Program Files\OpenVPN\config\myclient1.ovpn'
5+
6+
describe file(cfgfile) do
7+
it { should be_file }
8+
its('content') { should include '# OpenVPN client configuration' }
9+
its('content') { should include '# Managed by Salt' }
10+
end
11+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
control 'OpenVPN packages' do
2+
title 'should be installed'
3+
4+
describe package('OpenVPN') do
5+
it { should be_installed }
6+
end
7+
8+
describe package('TAP-Windows') do
9+
it { should be_installed }
10+
end
11+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
control 'OpenVPN service' do
2+
impact 0.5
3+
title 'should be running and enabled'
4+
5+
require 'rspec/retry'
6+
7+
describe service("OpenVPNService") do
8+
it { should be_enabled }
9+
it { should be_running }
10+
end
11+
12+
logfile = 'C:\ProgramData\OpenVPN\log\myclient1.log'
13+
14+
describe file(logfile) do
15+
it { should be_file }
16+
end
17+
18+
describe 'Initialization' do
19+
it 'should be completed', retry: 60, retry_wait: 1 do
20+
expect(file(logfile).content).to include 'Initialization Sequence Completed'
21+
end
22+
end
23+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: openvpn-windows
5+
title: OpenVPN Formula
6+
maintainer: SaltStack Formulas
7+
license: Apache-2.0
8+
summary: Verify that the openvpn formula is setup and configured correctly
9+
supports:
10+
- platform: windows

test/salt/pillar/windows.sls

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
openvpn:
2+
{% if salt['grains.get']('os_family') != 'Windows' %}
3+
lookup:
4+
user: openvpn
5+
group: openvpn
6+
manage_user: True
7+
manage_group: True
8+
external_repo_enabled: True
9+
dh_files: ['512']
10+
server:
11+
myserver1:
12+
port: 2000
13+
proto: udp
14+
topology: p2p
15+
dev: tun
16+
comp_lzo: "yes"
17+
ifconfig: 169.254.0.1 169.254.0.2
18+
log_append: /var/log/openvpn/myserver1.log
19+
secret: /etc/openvpn/myserver1_secret.key
20+
# /usr/sbin/openvpn --genkey --secret /dev/stdout
21+
secret_content: |
22+
#
23+
# 2048 bit OpenVPN static key
24+
#
25+
-----BEGIN OpenVPN Static key V1-----
26+
6b3e7b098232e9c885f8deed5c069b02
27+
47a966595178cc30ebcd4e1042e019ef
28+
fdfbed752e26ef7b0877e0e0a6e4e38b
29+
ffed3fd9da205ff6cd39825d0f8a99ec
30+
324848682062676868b57e4474791042
31+
4dc4ad7f3ff7ba8815e31f950c7443c8
32+
b52441384936cbf50d2f4d051d0c889a
33+
f118dec5c749398cdce859fced60a4eb
34+
4e78abb9939f8dbe1cbdbbcaa914b539
35+
6258235dce1a8ef044a29f8ce018f183
36+
4b83f17a42b788c583cf006cccb5050f
37+
a1c53b22688d98a2092fcd23b160b01a
38+
064d84f1355c605287b30b140c3c5fa7
39+
b5e2a0a8def6eb46b3ab4a11b5cb4c96
40+
4c099bf8e74b8bf4e6509de69b7a79ad
41+
7391b6cf3f4ae296ecf8b552144a2947
42+
-----END OpenVPN Static key V1-----
43+
{% else %}
44+
lookup:
45+
service: OpenVPNService
46+
client:
47+
myclient1:
48+
proto: udp
49+
dev: tun
50+
comp_lzo: "yes"
51+
pull: false
52+
tls_client: false
53+
nobind: false
54+
ifconfig: 169.254.0.2 169.254.0.1
55+
remote:
56+
- 192.168.10.10 2000
57+
log_append: '"C:\\ProgramData\\OpenVPN\\log\\myclient1.log"'
58+
secret: '"C:\\ProgramData\\OpenVPN\\config\\myclient1_secret.key"'
59+
# /usr/sbin/openvpn --genkey --secret /dev/stdout
60+
secret_content: |
61+
#
62+
# 2048 bit OpenVPN static key
63+
#
64+
-----BEGIN OpenVPN Static key V1-----
65+
6b3e7b098232e9c885f8deed5c069b02
66+
47a966595178cc30ebcd4e1042e019ef
67+
fdfbed752e26ef7b0877e0e0a6e4e38b
68+
ffed3fd9da205ff6cd39825d0f8a99ec
69+
324848682062676868b57e4474791042
70+
4dc4ad7f3ff7ba8815e31f950c7443c8
71+
b52441384936cbf50d2f4d051d0c889a
72+
f118dec5c749398cdce859fced60a4eb
73+
4e78abb9939f8dbe1cbdbbcaa914b539
74+
6258235dce1a8ef044a29f8ce018f183
75+
4b83f17a42b788c583cf006cccb5050f
76+
a1c53b22688d98a2092fcd23b160b01a
77+
064d84f1355c605287b30b140c3c5fa7
78+
b5e2a0a8def6eb46b3ab4a11b5cb4c96
79+
4c099bf8e74b8bf4e6509de69b7a79ad
80+
7391b6cf3f4ae296ecf8b552144a2947
81+
-----END OpenVPN Static key V1-----
82+
{% endif %}

test/vagrant/Vagrantfile.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$script = <<-SCRIPT
2+
# Workaround for error "The request was aborted: Could not create SSL/TLS secure channel."
3+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
4+
mkdir $env:TEMP\\kitchen\\srv\\salt\\win\\repo-ng
5+
wget https://github.com/saltstack/salt-winrepo-ng/raw/master/openvpn.sls -OutFile $env:TEMP\\kitchen\\srv\\salt\\win\\repo-ng\\openvpn.sls
6+
SCRIPT
7+
8+
Vagrant.configure("2") do |config|
9+
config.vm.provision "shell", inline: $script
10+
end

0 commit comments

Comments
 (0)