Skip to content

Commit 6e5a441

Browse files
committed
Migrate tests to named_run_list
1 parent 701fae8 commit 6e5a441

File tree

16 files changed

+138
-270
lines changed

16 files changed

+138
-270
lines changed

cookbooks/boxcutter_onepassword/Policyfile.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
default_source :chef_repo, '../'
1212

1313
# run_list: chef-client will run these recipes in the order specified.
14-
run_list 'boxcutter_ohai', 'boxcutter_init', 'boxcutter_onepassword_test'
14+
run_list 'boxcutter_ohai', 'boxcutter_init', 'boxcutter_onepassword_test::cli'
15+
named_run_list 'boxcutter_onepassword_test_cli', 'boxcutter_ohai', 'boxcutter_init', 'boxcutter_onepassword_test::cli'
16+
named_run_list 'boxcutter_onepassword_test_service_account', 'boxcutter_ohai', 'boxcutter_init',
17+
'boxcutter_onepassword_test::service_account'
18+
named_run_list 'boxcutter_onepassword_test_connect_server', 'boxcutter_ohai', 'boxcutter_init',
19+
'boxcutter_onepassword_test::connect_server'
1520

1621
# Specify a custom source for a single cookbook:
1722
cookbook 'boxcutter_onepassword', path: '.'

cookbooks/boxcutter_onepassword/kitchen.yml

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ verifier:
3030
platforms:
3131
# @see https://github.com/chef-cookbooks/testing_examples/blob/main/kitchen.dokken.yml
3232
# @see https://hub.docker.com/u/dokken
33-
- name: ubuntu-20.04
33+
- name: ubuntu-22.04
3434
driver:
35-
image: boxcutter/dokken-ubuntu-20.04
35+
image: boxcutter/dokken-ubuntu-22.04
3636
pid_one_command: /bin/systemd
3737

38-
- name: ubuntu-22.04
38+
- name: ubuntu-24.04
3939
driver:
40-
image: boxcutter/dokken-ubuntu-22.04
40+
image: boxcutter/dokken-ubuntu-24.04
4141
pid_one_command: /bin/systemd
4242

4343
- name: centos-stream-9
@@ -51,21 +51,57 @@ platforms:
5151
- RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
5252

5353
suites:
54-
- name: default
55-
# run_list set in Policyfile.rb, this does nothing
56-
# run_list:
57-
# - recipe[boxcutter_ohai]
58-
# - recipe[boxcutter_init]
59-
# - recipe[boxcutter_onepassword::default]
54+
- name: cli
55+
named_run_list: boxcutter_onepassword_test_cli
6056
verifier:
6157
inspec_tests:
62-
- test/integration/default
58+
- test/integration/cli
59+
attributes:
60+
61+
- name: service-account
62+
named_run_list: boxcutter_onepassword_test_service_account
63+
verifier:
64+
inspec_tests:
65+
- test/integration/cli
6366
attributes:
6467
lifecycle:
68+
# op item get 'Service Account Auth Token: automation-org-readonly-blue' --vault Automation-Org --account PB5KE5S2ORAQTDUOLBDJTLAPVU
69+
# op item get mzqlddelxv6oe7dfz3vc7iad7m --vault Automation-Org --account PB5KE5S2ORAQTDUOLBDJTLAPVU --format json
70+
# export OP_SERVICE_ACCOUNT_TOKEN=$(op read 'op://Automation-Org/mzqlddelxv6oe7dfz3vc7iad7m/credential' --account PB5KE5S2ORAQTDUOLBDJTLAPVU)
6571
pre_converge:
6672
- remote: |
6773
bash -xc '
6874
set +x
69-
echo "<%= ENV['OP_SERVICE_ACCOUNT_TOKEN'] %>" > /opt/kitchen/op_service_account_token
75+
mkdir -p /etc/cinc
76+
ln -s /etc/cinc /etc/chef
77+
echo "<%= ENV['OP_SERVICE_ACCOUNT_TOKEN'] %>" > /etc/chef/op_service_account_token
7078
set -x
7179
'
80+
81+
- name: connect-server
82+
named_run_list: boxcutter_onepassword_test_connect_server
83+
verifier:
84+
inspec_tests:
85+
- test/integration/cli
86+
attributes:
87+
lifecycle:
88+
# op item get 'Service Account Auth Token: automation-org-readonly-blue' --vault Automation-Org --account PB5KE5S2ORAQTDUOLBDJTLAPVU
89+
# op item get mzqlddelxv6oe7dfz3vc7iad7m --vault Automation-Org --account PB5KE5S2ORAQTDUOLBDJTLAPVU --format json
90+
# export OP_SERVICE_ACCOUNT_TOKEN=$(op read 'op://Automation-Org/mzqlddelxv6oe7dfz3vc7iad7m/credential' --account PB5KE5S2ORAQTDUOLBDJTLAPVU)
91+
#
92+
# op item get 'sandbox-connect-server Access Token: sandbox-rw-blue' --vault Automation-Org --account PB5KE5S2ORAQTDUOLBDJTLAPVU
93+
# op item get nuhhhrxxzz4cjmssx3226ejfzm --vault Automation-Org --account PB5KE5S2ORAQTDUOLBDJTLAPVU --format json
94+
# export OP_CONNECT_TOKEN=$(op read 'op://Automation-Org/nuhhhrxxzz4cjmssx3226ejfzm/credential' --account PB5KE5S2ORAQTDUOLBDJTLAPVU)
95+
#
96+
# export OP_CONNECT_HOST=http://localhost:8080
97+
pre_converge:
98+
- remote: |
99+
bash -xc '
100+
set +x
101+
mkdir -p /etc/cinc
102+
ln -s /etc/cinc /etc/chef
103+
echo "<%= ENV['OP_CONNECT_HOST'] %>" > /etc/chef/op_connect_host
104+
echo "<%= ENV['OP_CONNECT_TOKEN'] %>" > /etc/chef/op_connect_token
105+
echo "<%= ENV['OP_SERVICE_ACCOUNT_TOKEN'] %>" > /etc/chef/op_service_account_token
106+
set -x
107+
'

cookbooks/boxcutter_onepassword/kitchen_digitalocean.yml

Lines changed: 0 additions & 91 deletions
This file was deleted.

cookbooks/boxcutter_onepassword/policyfiles/connect_server.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

cookbooks/boxcutter_onepassword/recipes/connect_server.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818

1919
connect_server_username = 'opuser'
2020

21+
node.default['fb_users']['users']['opuser'] = {
22+
'action' => :add,
23+
'home' => '/home/opuser',
24+
'shell' => '/bin/bash',
25+
}
26+
27+
node.default['fb_users']['groups']['opuser'] = {
28+
'members' => ['opuser'],
29+
'action' => :add,
30+
}
31+
2132
include_recipe 'boxcutter_docker'
2233

2334
node.default['fb_users']['groups']['docker']['members'] << 'opuser'

cookbooks/boxcutter_onepassword/recipes/user.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

cookbooks/boxcutter_onepassword/resources/zipfile.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
case node['kernel']['machine']
1616
when 'x86_64', 'amd64'
1717
package_info = {
18-
'url' => 'https://cache.agilebits.com/dist/1P/op2/pkg/v2.27.0/op_linux_amd64_v2.27.0.zip',
19-
'checksum' => 'e076905292bba0d6e459353f89fd1d29b626f37e610ee56299bcf8c9201e0405',
18+
'url' => 'https://cache.agilebits.com/dist/1P/op2/pkg/v2.30.3/op_linux_amd64_v2.30.3.zip',
19+
'checksum' => 'a16307ebcecb40fd091d7a6ff4f0c380c3c0897c4f4616de2c5d285e57d5ee28',
2020
}
2121
when 'aarch64', 'arm64'
2222
package_info = {
23-
'url' => 'https://cache.agilebits.com/dist/1P/op2/pkg/v2.27.0/op_linux_arm64_v2.27.0.zip',
24-
'checksum' => '3ee60ec19020fb2bb43c3a73a2aa1988d85dd651eedb195b72d555f329737502',
23+
'url' => 'https://cache.agilebits.com/dist/1P/op2/pkg/v2.30.3/op_linux_arm64_v2.30.3.zip',
24+
'checksum' => '39bd361b2cd4819ea757583624eeda33f6062ba5ccfc2b90ad0764aed94cd1c4',
2525
}
2626
end
2727

cookbooks/boxcutter_onepassword/spec/unit/recipes/user_spec.rb

Lines changed: 0 additions & 41 deletions
This file was deleted.

cookbooks/boxcutter_onepassword/test/cookbooks/boxcutter_onepassword_test/recipes/default.rb renamed to cookbooks/boxcutter_onepassword/test/cookbooks/boxcutter_onepassword_test/recipes/cli.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Cookbook:: boxcutter_onepassword_test
3-
# Recipe:: default
3+
# Recipe:: cli
44
#
55

66
include_recipe 'boxcutter_onepassword::cli'

cookbooks/boxcutter_onepassword/test/cookbooks/boxcutter_onepassword_test/recipes/connect_server.rb

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
# Recipe:: connect_server
44
#
55

6-
puts 'MISCHA: connect_server'
7-
include_recipe 'boxcutter_onepassword::user'
6+
# Configuring credentials in 1Password.com
7+
# 1. Sign into your account on 1Password.com.
8+
# 2. Select "Developer" from the sidebar.
9+
# 3. In "From" at the top, choose "Infrastructure Secrets Management > Other"
10+
# 4. Select "Create a Connect server"
11+
#
12+
# Set up an environment:
13+
# Environment Name: sandbox-connect-server
14+
# Vaults: Automation-Org / Read
15+
# Sandbox / Read-Write
16+
# Set up an access token:
17+
# Token Name: sandbox-rw-blue
18+
# Vaults: Automation-Org / Read
19+
# Sandbox / Read-Write
820

921
# 'sandbox-connect-server Credentials File', 'Automation-Org'
1022
# op document get 'sandbox-connect-server Credentials File' --vault Automation-Org
@@ -14,13 +26,25 @@
1426
'Automation-Org'
1527
include_recipe 'boxcutter_onepassword::connect_server'
1628

17-
# stuff = Boxcutter::OnePassword.op_read('op://Automation-Org/nexus admin blue/password', 'connect_server')
18-
# puts "MISCHA: stuff=#{stuff}"
19-
20-
# op item get 'sandbox-connect-server Access Token: sandbox-connect-server-access-token' --vault Automation-Org
21-
# op item get 7etjvtlft4u4wlbkxvprahvmzq --vault Automation-Org --format json
22-
# op read 'op://Automation-Org/7etjvtlft4u4wlbkxvprahvmzq/credential'
23-
# item = Boxcutter::OnePassword.op_read('op://Automation-Org/7etjvtlft4u4wlbkxvprahvmzq/credential')
29+
# There's no great ways to test these runtime functions that I know of.
30+
# Can't really use chefspec because it installs the 1Password CLI at
31+
# runtime and we don't want to install tools on the testing host running
32+
# rspec. So I'm just using the runtime functions to check known keys
33+
# and raising errors when they don't match.
34+
#
35+
# op item get 'craft SSH Key' --vault Automation-Org --format json
36+
public_key = Boxcutter::OnePassword.op_read('op://Automation-Org/craft SSH Key/public key', 'connect_server')
37+
if public_key != 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD2y6TEs9+Mc6FRUbRBDsb+6a3erlYnv39IDge7LxIvI' \
38+
'A1/XH5+6ChbQykSyge9gxZFlnVg92nvN82E+B5DKik9HUvkrN4CSOyOUb2ggkMXLLzHJFI29LjU3HruX7' \
39+
'DHIHwyJz2mZT9LDqBVX+/urAuRFRPe9hp4eHC0upWijgp2TmV+ghOOY7R8LxmuUbaG/QaxxXGVcYffmC5' \
40+
'kzalmOqqcEPue0JfHmWu/QdmMWEjrbVjZevjhLy7rb00hLWeDleURjK8OqupBGAHu16g50QFFXGs1TfzY' \
41+
'TFll2Ehy28ZL7gxKObHsJREyn+5eP9lrU4dcZqQZHb/aUUgAOAdYP0ZosUrXBqwf9Rcnck9U+dC8a8WY8' \
42+
'ibQvFJ5vtMsDDQhrUlPPAgVJpXf6BAhB+VH1SHBfDFBHOcv6w50/AlJUze6GXYZ6CQOF1K5CsoEInuiD5' \
43+
'SJCmDt92/2v5+EIe4GLPRKzed896CMgfRPfam59KzeaeNUNf5E1RMmPGbPleZMMa4yx5DpSkDvrXTalbT' \
44+
'DP1SYvrSLiHrFdl97XGx9nmF8yFUlDS+CrJK/W3eT9pt7qvR7FDIBI//HmFtICIkP5pu3gi978QHo5VYe' \
45+
'w6p4LPNVJ47LYU6yBfy3DVZv42y13EHlqxQXw0S3FT/t6Vb/y45h8FvAY0eMgU1cyN7KHP9Y1w=='
46+
fail 'Unable to read "craft SSH Key" - did you remember to set OP_CONNECT_TOKEN?'
47+
end
2448

2549
# export OP_API_TOKEN="<token>"
2650
# curl \
@@ -31,4 +55,4 @@
3155
# export OP_CONNECT_TOKEN=<token>
3256
# export OP_CONNECT_HOST=http://localhost:8080
3357
# op vault list <-- won't work
34-
# op read 'op://Automation-Org/nexus admin blue/password'
58+
# op read 'op://Automation-Org/craft SSH Key/public key'

0 commit comments

Comments
 (0)