conjur-cli 5.6.6 → 6.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +1 -1
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +1 -1
  5. data/APPLIANCE_VERSION +1 -1
  6. data/CHANGELOG.md +3 -42
  7. data/Gemfile +4 -7
  8. data/Humanfile.md +31 -0
  9. data/Jenkinsfile +34 -63
  10. data/README.md +41 -55
  11. data/Rakefile +5 -1
  12. data/bin/conjur +0 -2
  13. data/build-deb.sh +1 -3
  14. data/ci/cli-test.sh +6 -0
  15. data/ci/package.sh +3 -1
  16. data/ci/publish.sh +2 -2
  17. data/ci/secrets/publish.yml +2 -2
  18. data/ci/wait_for_server.sh +10 -0
  19. data/conjur-cli.gemspec +7 -7
  20. data/dev/docker-compose.yml +24 -0
  21. data/dev/start.sh +15 -0
  22. data/dev/stop.sh +5 -0
  23. data/docker-compose.yml +30 -0
  24. data/features/authentication/authenticate.feature +34 -0
  25. data/features/authentication/login.feature +13 -0
  26. data/features/authentication/logout.feature +15 -0
  27. data/{acceptance-features → features}/authentication/whoami.feature +0 -0
  28. data/features/authorization/resource/annotate.feature +22 -0
  29. data/features/authorization/resource/check.feature +47 -0
  30. data/{acceptance-features → features}/authorization/resource/exists.feature +18 -6
  31. data/features/authorization/resource/permitted_roles.feature +35 -0
  32. data/features/authorization/resource/show.feature +34 -0
  33. data/features/authorization/role/exists.feature +28 -0
  34. data/features/authorization/role/members.feature +45 -0
  35. data/features/authorization/role/memberships.feature +43 -0
  36. data/features/conjurenv/check.feature +34 -0
  37. data/features/conjurenv/run.feature +15 -0
  38. data/{acceptance-features → features}/conjurenv/template.feature +8 -3
  39. data/{acceptance-features → features}/directory/user/update_password.feature +8 -2
  40. data/{acceptance-features → features}/directory/variable/value.feature +9 -5
  41. data/{acceptance-features → features}/directory/variable/values-add.feature +8 -3
  42. data/features/hostfactory/tokens.feature +22 -0
  43. data/features/pubkeys/show.feature +18 -0
  44. data/features/step_definitions/authn_steps.rb +22 -0
  45. data/features/step_definitions/cli_steps.rb +28 -0
  46. data/features/step_definitions/file_steps.rb +12 -0
  47. data/features/step_definitions/flow_control_steps.rb +7 -0
  48. data/features/step_definitions/graph_steps.rb +4 -3
  49. data/{acceptance-features → features}/step_definitions/http_steps.rb +0 -0
  50. data/features/step_definitions/overrides.rb +9 -0
  51. data/features/step_definitions/policy_steps.rb +11 -0
  52. data/{acceptance-features → features}/step_definitions/trusted_proxy_steps.rb +0 -0
  53. data/features/support/blank.yml +1 -0
  54. data/features/support/env.rb +21 -7
  55. data/features/support/hooks.rb +31 -116
  56. data/features/support/world.rb +16 -76
  57. data/jenkins.sh +33 -0
  58. data/lib/conjur/authenticator.rb +83 -0
  59. data/lib/conjur/authn.rb +5 -20
  60. data/lib/conjur/cli.rb +13 -6
  61. data/lib/conjur/command.rb +30 -350
  62. data/lib/conjur/command/authn.rb +23 -15
  63. data/lib/conjur/command/host_factories.rb +2 -74
  64. data/lib/conjur/command/hosts.rb +6 -113
  65. data/lib/conjur/command/init.rb +20 -35
  66. data/lib/conjur/command/{secrets.rb → policies.rb} +33 -22
  67. data/lib/conjur/command/pubkeys.rb +3 -63
  68. data/lib/conjur/command/resources.rb +45 -162
  69. data/lib/conjur/command/roles.rb +11 -181
  70. data/lib/conjur/command/rspec/helpers.rb +0 -1
  71. data/lib/conjur/command/rspec/mock_services.rb +4 -4
  72. data/lib/conjur/command/users.rb +2 -159
  73. data/lib/conjur/command/variables.rb +5 -218
  74. data/lib/conjur/complete.rb +2 -2
  75. data/lib/conjur/config.rb +1 -11
  76. data/lib/conjur/conjurenv.rb +12 -9
  77. data/lib/conjur/identifier_manipulation.rb +3 -5
  78. data/lib/conjur/version.rb +2 -2
  79. data/{publish-rubygem.sh → publish.sh} +0 -4
  80. data/spec/authn_spec.rb +4 -0
  81. data/spec/command/hosts_spec.rb +2 -69
  82. data/spec/command/init_spec.rb +16 -11
  83. data/spec/command/pubkeys_spec.rb +1 -46
  84. data/spec/command/resources_spec.rb +21 -170
  85. data/spec/command/roles_spec.rb +5 -181
  86. data/spec/command/users_spec.rb +3 -79
  87. data/spec/command_spec.rb +1 -20
  88. data/spec/complete_spec.rb +1 -23
  89. data/spec/config_spec.rb +1 -1
  90. data/spec/spec_helper.rb +4 -5
  91. data/test.sh +29 -25
  92. metadata +92 -212
  93. data/.githooks/pre_commit/run_specs.rb +0 -23
  94. data/Dockerfile +0 -15
  95. data/Dockerfile.fpm +0 -18
  96. data/Dockerfile.publish +0 -12
  97. data/Dockerfile.standalone +0 -33
  98. data/Dockerfile.validate-packaging +0 -9
  99. data/VERSION +0 -1
  100. data/acceptance-features/audit/audit_event_send.feature +0 -107
  101. data/acceptance-features/audit/fetch.feature +0 -16
  102. data/acceptance-features/audit/send.feature +0 -51
  103. data/acceptance-features/authentication/authenticate.feature +0 -10
  104. data/acceptance-features/authentication/login.feature +0 -12
  105. data/acceptance-features/authentication/logout.feature +0 -13
  106. data/acceptance-features/authorization/resource/annotate.feature +0 -35
  107. data/acceptance-features/authorization/resource/check.feature +0 -24
  108. data/acceptance-features/authorization/resource/create.feature +0 -21
  109. data/acceptance-features/authorization/resource/deny.feature +0 -12
  110. data/acceptance-features/authorization/resource/give.feature +0 -24
  111. data/acceptance-features/authorization/resource/permit.feature +0 -20
  112. data/acceptance-features/authorization/resource/permitted_roles.feature +0 -16
  113. data/acceptance-features/authorization/resource/show.feature +0 -28
  114. data/acceptance-features/authorization/role/create.feature +0 -13
  115. data/acceptance-features/authorization/role/exists.feature +0 -19
  116. data/acceptance-features/authorization/role/grant_to.feature +0 -21
  117. data/acceptance-features/authorization/role/graph.feature +0 -57
  118. data/acceptance-features/authorization/role/members.feature +0 -23
  119. data/acceptance-features/authorization/role/memberships.feature +0 -27
  120. data/acceptance-features/bootstrap.feature +0 -13
  121. data/acceptance-features/conjurenv/check.feature +0 -21
  122. data/acceptance-features/conjurenv/run.feature +0 -10
  123. data/acceptance-features/directory/group/create.feature +0 -20
  124. data/acceptance-features/directory/group/retire.feature +0 -54
  125. data/acceptance-features/directory/host/create.feature +0 -23
  126. data/acceptance-features/directory/host/retire.feature +0 -6
  127. data/acceptance-features/directory/hostfactory/create.feature +0 -28
  128. data/acceptance-features/directory/hostfactory/tokens.feature +0 -16
  129. data/acceptance-features/directory/layer/create.feature +0 -10
  130. data/acceptance-features/directory/layer/hosts-add.feature +0 -9
  131. data/acceptance-features/directory/layer/hosts-remove.feature +0 -10
  132. data/acceptance-features/directory/layer/retire.feature +0 -43
  133. data/acceptance-features/directory/user/create.feature +0 -23
  134. data/acceptance-features/directory/user/retire.feature +0 -6
  135. data/acceptance-features/directory/variable/create.feature +0 -14
  136. data/acceptance-features/directory/variable/retire.feature +0 -17
  137. data/acceptance-features/dsl/policy_owner.feature +0 -45
  138. data/acceptance-features/dsl/resource_owner.feature +0 -17
  139. data/acceptance-features/dsl/retire.feature +0 -15
  140. data/acceptance-features/global-privilege/elevate.feature +0 -20
  141. data/acceptance-features/global-privilege/reveal.privilege +0 -20
  142. data/acceptance-features/pubkeys/add.feature +0 -22
  143. data/acceptance-features/pubkeys/delete.feature +0 -9
  144. data/acceptance-features/pubkeys/names.feature +0 -26
  145. data/acceptance-features/pubkeys/show.feature +0 -27
  146. data/acceptance-features/step_definitions/cli_steps.rb +0 -57
  147. data/acceptance-features/step_definitions/graph_steps.rb +0 -22
  148. data/acceptance-features/step_definitions/user_steps.rb +0 -51
  149. data/acceptance-features/support/env.rb +0 -23
  150. data/acceptance-features/support/hooks.rb +0 -178
  151. data/acceptance-features/support/world.rb +0 -176
  152. data/acceptance-features/trusted_proxies.feature +0 -82
  153. data/bin/conjurize +0 -26
  154. data/bin/jsonfield +0 -70
  155. data/build-standalone +0 -6
  156. data/deprecations.sh +0 -38
  157. data/features/conjurize.feature +0 -134
  158. data/features/dsl_context.feature +0 -36
  159. data/features/dsl_host_create.feature +0 -11
  160. data/features/dsl_ownership.feature +0 -30
  161. data/features/dsl_permission.feature +0 -45
  162. data/features/dsl_resource_create.feature +0 -23
  163. data/features/dsl_role_create.feature +0 -11
  164. data/features/dsl_user_create.feature +0 -23
  165. data/features/jsonfield.feature +0 -49
  166. data/features/role_graph.feature +0 -58
  167. data/features/step_definitions/conjurize_steps.rb +0 -5
  168. data/features/step_definitions/dsl_steps.rb +0 -52
  169. data/features/support/conjur.conf +0 -6
  170. data/lib/conjur/command/assets.rb +0 -121
  171. data/lib/conjur/command/audit.rb +0 -155
  172. data/lib/conjur/command/bootstrap.rb +0 -129
  173. data/lib/conjur/command/dsl_command.rb +0 -75
  174. data/lib/conjur/command/elevate.rb +0 -76
  175. data/lib/conjur/command/field.rb +0 -45
  176. data/lib/conjur/command/groups.rb +0 -208
  177. data/lib/conjur/command/ids.rb +0 -34
  178. data/lib/conjur/command/layers.rb +0 -211
  179. data/lib/conjur/command/ldapsync.rb +0 -118
  180. data/lib/conjur/command/rspec/audit_helpers.rb +0 -68
  181. data/lib/conjur/command/rubydsl.rb +0 -93
  182. data/lib/conjur/command/script.rb +0 -48
  183. data/lib/conjur/command/server.rb +0 -67
  184. data/lib/conjur/conjurize.rb +0 -71
  185. data/lib/conjur/conjurize/script.rb +0 -150
  186. data/lib/conjur/dsl/runner.rb +0 -273
  187. data/publish-deb.sh +0 -6
  188. data/push-image +0 -29
  189. data/spec/command/assets_spec.rb +0 -115
  190. data/spec/command/audit_spec.rb +0 -376
  191. data/spec/command/elevate_spec.rb +0 -28
  192. data/spec/command/env_spec.rb +0 -168
  193. data/spec/command/groups_spec.rb +0 -77
  194. data/spec/command/host_factories_spec.rb +0 -38
  195. data/spec/command/layers_spec.rb +0 -35
  196. data/spec/command/ldapsync_spec.rb +0 -28
  197. data/spec/command/rubydsl_spec.rb +0 -63
  198. data/spec/command/variable_expiration_spec.rb +0 -164
  199. data/spec/command/variables_spec.rb +0 -192
  200. data/spec/conjurize/script_spec.rb +0 -62
  201. data/spec/conjurize_spec.rb +0 -70
  202. data/spec/dsl/runner_spec.rb +0 -93
  203. data/spec/env_spec.rb +0 -214
@@ -0,0 +1,45 @@
1
+ Feature: List members of a role
2
+
3
+ Background:
4
+ Given I load the policy:
5
+ """
6
+ - !user alice
7
+
8
+ - !group cooks
9
+ """
10
+
11
+ Scenario: Role members list is initally just the creator of the role
12
+ When I successfully run `conjur role members group:cooks`
13
+ Then the JSON should be:
14
+ """
15
+ [
16
+ "cucumber:user:admin"
17
+ ]
18
+ """
19
+
20
+ Scenario: Members can be added to the role by granting them the role
21
+ Given I apply the policy:
22
+ """
23
+ - !grant
24
+ role: !group cooks
25
+ member: !user alice
26
+ """
27
+ When I successfully run `conjur role members group:cooks`
28
+ Then the JSON should have 2 entries
29
+
30
+ Scenario: Members list is not expanded transitively
31
+ Given I apply the policy:
32
+ """
33
+ - !group employees
34
+
35
+ - !grant
36
+ role: !group employees
37
+ member: !group cooks
38
+
39
+ - !grant
40
+ role: !group cooks
41
+ member: !user alice
42
+ """
43
+ When I successfully run `conjur role members group:cooks`
44
+ Then the JSON should have 2 entries
45
+
@@ -0,0 +1,43 @@
1
+ Feature: List memberships of a role
2
+
3
+ Scenario: The role memberships list includes the role itself
4
+ Given I load the policy:
5
+ """
6
+ - !group cooks
7
+ """
8
+ When I successfully run `conjur role memberships group:cooks`
9
+ Then the JSON should have 1 entries
10
+
11
+ Scenario: Memberships can be added to a role by granting it a new role
12
+ Given I load the policy:
13
+ """
14
+ - !group employees
15
+
16
+ - !group cooks
17
+
18
+ - !grant
19
+ role: !group employees
20
+ member: !group cooks
21
+ """
22
+ When I successfully run `conjur role memberships group:cooks`
23
+ Then the JSON should have 2 entries
24
+
25
+ Scenario: Members list is expanded transitively
26
+ Given I load the policy:
27
+ """
28
+ - !user alice
29
+
30
+ - !group employees
31
+
32
+ - !group cooks
33
+
34
+ - !grant
35
+ role: !group employees
36
+ member: !group cooks
37
+
38
+ - !grant
39
+ role: !group cooks
40
+ member: !user alice
41
+ """
42
+ When I successfully run `conjur role memberships user:alice`
43
+ Then the JSON should have 3 entries
@@ -0,0 +1,34 @@
1
+ Feature: Check an environment
2
+
3
+ Background:
4
+ Given I load the policy:
5
+ """
6
+ - !variable access_key
7
+ - !variable secret_key
8
+ - !variable ssh_private_key
9
+
10
+ - !user alice
11
+
12
+ - !permit
13
+ role: !user alice
14
+ privilege: execute
15
+ resources:
16
+ - !variable access_key
17
+ - !variable secret_key
18
+
19
+ """
20
+ And I run `conjur variable values add access_key ABCDEF`
21
+ And I run `conjur variable values add secret_key XYZQWER`
22
+ And I run `conjur variable values add ssh_private_key PRIVATE_KEY_BODY`
23
+ And I login as "alice"
24
+ And I reset the command list
25
+
26
+ Scenario: Check against permitted variables
27
+ When I run `conjur env check --yaml '{ aws_access_key: !var access_key, aws_secret_key: !var secret_key }'`
28
+ Then the exit status should be 0
29
+ And the stdout should contain "aws_access_key: available\naws_secret_key: available\n"
30
+
31
+ Scenario: Check against restricted variables
32
+ When I run `conjur env check --yaml '{ aws_access_key: !var access_key, ssh_private_key: !var ssh_private_key }'`
33
+ Then the exit status should be 1
34
+ And the stdout should contain "aws_access_key: available\nssh_private_key: unavailable\n"
@@ -0,0 +1,15 @@
1
+ Feature: Run command in an environment populated from Conjur variables
2
+
3
+ Background:
4
+ Given I load the policy:
5
+ """
6
+ - !variable access_key
7
+ - !variable secret_key
8
+ """
9
+ And I run `conjur variable values add access_key ABCDEF`
10
+ And I run `conjur variable values add secret_key XYZQWER`
11
+ And I reset the command list
12
+
13
+ Scenario:
14
+ When I run `bash -c "conjur env run --yaml '{ cloud_access_key: !var access_key , cloud_secret_key: !var secret_key }' -- env | grep CLOUD_"`
15
+ Then the stdout should contain exactly "CLOUD_ACCESS_KEY=ABCDEF\nCLOUD_SECRET_KEY=XYZQWER"
@@ -2,10 +2,15 @@ Feature: Embed values of Conjur variables into ERB template
2
2
 
3
3
  Background:
4
4
  Given a file named "template.erb" with: 'aws credentials: [<%= conjurenv["aws_access_key"] %>, <%= conjurenv["aws_secret_key"] %>]'
5
- And I run `conjur variable create $ns/access_key ABCDEF`
6
- And I run `conjur variable create $ns/secret_key XYZQWER`
5
+ And I load the policy:
6
+ """
7
+ - !variable access_key
8
+ - !variable secret_key
9
+ """
10
+ And I run `conjur variable values add access_key ABCDEF`
11
+ And I run `conjur variable values add secret_key XYZQWER`
7
12
  And I reset the command list
8
13
 
9
14
  Scenario:
10
- When I run `conjur env template --yaml '{ aws_access_key: !var $ns/access_key , aws_secret_key: !var $ns/secret_key }' template.erb `
15
+ When I run `conjur env template --yaml '{ aws_access_key: !var access_key , aws_secret_key: !var secret_key }' template.erb `
11
16
  Then it prints the path to temporary file which contains: 'aws credentials: [ABCDEF, XYZQWER]'
@@ -1,15 +1,21 @@
1
1
  Feature: Update the password of the logged-in user
2
2
 
3
3
  Background:
4
- Given I login as a new user
4
+ Given I load the policy:
5
+ """
6
+ - !user alice
7
+ """
8
+ And I login as "alice"
5
9
 
10
+ @restore-login
6
11
  Scenario: A user can update her own password
7
12
  And I run `conjur user update_password` interactively
8
13
  Then I can type and confirm a new password
9
14
 
15
+ @restore-login
10
16
  Scenario: The new password can be used to login
11
17
  And I run `conjur user update_password` interactively
12
18
  And I type and confirm a new password
13
- And I run `conjur authn login alice@$ns` interactively
19
+ And I run `conjur authn login alice` interactively
14
20
  And I enter the password
15
21
  Then the exit status should be 0
@@ -1,14 +1,18 @@
1
1
  Feature: Obtain value from variable
2
2
 
3
3
  Background:
4
- Given I successfully run `conjur variable create $ns/secret secretvalue`
5
- And I successfully run `conjur variable values add $ns/secret updatedvalue`
4
+ Given I load the policy:
5
+ """
6
+ - !variable secret
7
+ """
8
+ And I run `conjur variable values add secret secretvalue`
9
+ And I run `conjur variable values add secret updatedvalue`
6
10
  And I reset the command list
7
11
 
8
12
  Scenario: Recent value is obtained by default
9
- When I run `conjur variable value $ns/secret`
13
+ When I run `conjur variable value secret`
10
14
  Then the stdout should contain exactly "updatedvalue"
11
-
15
+
12
16
  Scenario: Previous values can be obtained by version
13
- When I run `conjur variable value -v 1 $ns/secret`
17
+ When I run `conjur variable value -v 1 secret`
14
18
  Then the stdout should contain exactly "secretvalue"
@@ -1,12 +1,17 @@
1
1
  Feature: Populate variable with values
2
2
 
3
3
  Background:
4
- Given I successfully run `conjur variable create $ns/secret initialvalue`
4
+ Given I load the policy:
5
+ """
6
+ - !variable secret
7
+ """
8
+ And I run `conjur variable values add secret initialvalue`
9
+ And I reset the command list
5
10
 
6
11
  Scenario: Value provided via command-line parameter
7
- When I run `conjur variable values add $ns/secret secretvalue`
12
+ When I run `conjur variable values add secret secretvalue`
8
13
  Then the output should contain "Value added"
9
14
 
10
15
  Scenario: Value provided via stdin
11
- When I run `bash -c 'echo "secretvalue" | conjur variable values add $ns/secret'`
16
+ When I run `bash -c 'echo "secretvalue" | conjur variable values add secret'`
12
17
  Then the output should contain "Value added"
@@ -0,0 +1,22 @@
1
+ Feature: Host factory tokens
2
+
3
+ Background:
4
+ Given I load the policy:
5
+ """
6
+ - !policy
7
+ id: myapp
8
+ body:
9
+ - !layer
10
+ - !host-factory
11
+ layers: [ !layer ]
12
+ """
13
+
14
+ Scenario: create a host factory token
15
+ When I successfully run `conjur hostfactory tokens create myapp`
16
+ Then the JSON should have "0/token"
17
+
18
+ Scenario: create a host using a token
19
+ When I successfully run `conjur hostfactory tokens create myapp`
20
+ And I keep the JSON response at "0/token" as "TOKEN"
21
+ Then I successfully run `conjur hostfactory hosts create %{TOKEN} host-01`
22
+ And the JSON should have "api_key"
@@ -0,0 +1,18 @@
1
+ Feature: Show public keys for a user
2
+
3
+ Background:
4
+ Given I load the policy:
5
+ """
6
+ - !user
7
+ id: alice
8
+ public_keys:
9
+ - ssh-rsa AAAAB3NzaC1yc2EAAAADAQ laptop
10
+ """
11
+
12
+ Scenario: After adding a key, the key is shown
13
+ When I run `conjur pubkeys show alice`
14
+ And the output should match /^ssh-rsa .* laptop$/
15
+
16
+ Scenario: Public keys can be listed using cURL, without authentication
17
+ When I successfully run `curl -k $conjur_url/public_keys/cucumber/user/alice`
18
+ Then the output should match /^ssh-rsa .* laptop$/
@@ -0,0 +1,22 @@
1
+ Then(/^I(?: can)? type and confirm a new password/) do
2
+ @password = SecureRandom.hex(12)
3
+ step %Q(I type "#{@password}")
4
+ step %Q(I type "#{@password}")
5
+ step "the exit status should be 0"
6
+ end
7
+
8
+ When(/^I enter the password/) do
9
+ raise "No current password" unless @password
10
+ step %Q(I type "#{@password}")
11
+ end
12
+
13
+ When(/^I type the API key for "(.*?)"$/) do |username|
14
+ step %Q(I type "#{api_key_of username}")
15
+ end
16
+
17
+ Given(/^I login as "(.*?)"$/) do |username|
18
+ api_key = api_key_of username
19
+
20
+ step %Q(I set the environment variable "CONJUR_AUTHN_LOGIN" to "#{username}")
21
+ step %Q(I set the environment variable "CONJUR_AUTHN_API_KEY" to "#{api_key}")
22
+ end
@@ -0,0 +1,28 @@
1
+ Transform /\$ns/ do |s|
2
+ s.gsub('$ns', namespace)
3
+ end
4
+
5
+ Transform /\$user_role/ do |s|
6
+ s.gsub('$user_role', test_user.role_id)
7
+ end
8
+
9
+ Transform /^table:/ do |table|
10
+ table.tap do |t|
11
+ t.hashes.each do |row|
12
+ row.each do |_,v|
13
+ v.gsub!('$ns', namespace)
14
+ v.gsub!('$user_role', test_user.role_id)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ When /^the command completes successfully/ do
21
+ last_command_started.wait
22
+ last_command_started.terminate
23
+ expect(last_command_started.exit_status).to eq(0)
24
+ end
25
+
26
+ Then /^the output from "([^"]*)" should match \/([^\/]*)\/$/ do |cmd, expected|
27
+ assert_matching_output(expected, output_from(cmd))
28
+ end
@@ -0,0 +1,12 @@
1
+ # this is step copypasted from https://github.com/cucumber/aruba/blob/master/lib/aruba/cucumber.rb#L24
2
+ # original has typo in regexp, which is fixed here
3
+ Given(/^a file named "([^"]*?)" with: '(.*?)'$/) do |file_name, file_content|
4
+ write_file(file_name, file_content)
5
+ end
6
+
7
+ Then /^it prints the path to temporary file which contains: '(.*)'$/ do |content|
8
+ filename = last_command_started.stdout.strip
9
+ tempfiles << filename
10
+ actual_content = File.read(filename)
11
+ expect(actual_content).to match(content)
12
+ end
@@ -0,0 +1,7 @@
1
+ When /^I clear the JSON response$/ do
2
+ clear_last_json
3
+ end
4
+
5
+ When /^I reset the command list/ do
6
+ aruba.command_monitor.clear
7
+ end
@@ -1,8 +1,9 @@
1
- Given /a graph with edges/ do |table|
1
+
2
+ Given /^a graph with edges$/ do |table|
2
3
  graph table.raw
3
4
  end
4
5
 
5
- Then %r{the graph JSON should be} do |json|
6
+ Then %r{^the graph JSON should be:$} do |json|
6
7
  json = expand_roles json
7
8
  last_graph = extract_filtered_graph json
8
9
  expect(last_graph.to_json).to be_json_eql(json)
@@ -18,4 +19,4 @@ When(/^I( successfully)? run with role expansion "(.*)"$/) do |successfully, cmd
18
19
  else
19
20
  step "I run `#{cmd}`"
20
21
  end
21
- end
22
+ end
@@ -0,0 +1,9 @@
1
+ # Use a json_spec style memorized value as an environment variable
2
+ When /I set the environment variable "(.*)" to memorized value "(.*)"/ do |key, value|
3
+ JsonSpec.memory.each do |k,v|
4
+ # JSON parser doesn't function properly on a JSON encoded string
5
+ v = v[1...-1] if v[0] == '"'
6
+ value.gsub! "%{#{k}}", v
7
+ end
8
+ set_environment_variable key, value
9
+ end
@@ -0,0 +1,11 @@
1
+ Given /^I load the policy:$/ do |policy|
2
+ load_policy 'root', policy, Conjur::API::POLICY_METHOD_PUT
3
+ end
4
+
5
+ Given /^I apply the policy:$/ do |policy|
6
+ load_policy 'root', policy, Conjur::API::POLICY_METHOD_PATCH
7
+ end
8
+
9
+ Given /^I add the policy:$/ do |policy|
10
+ load_policy 'root', policy, Conjur::API::POLICY_METHOD_POST
11
+ end
@@ -0,0 +1 @@
1
+ --- []
@@ -1,12 +1,26 @@
1
- require 'simplecov'
1
+ $LOAD_PATH.unshift File.expand_path('../..', File.dirname(__FILE__))
2
+
3
+ require 'json_spec/cucumber'
4
+
2
5
  require 'aruba/cucumber'
3
- require 'methadone/cucumber'
4
- require 'cucumber/rspec/doubles'
5
- require "json_spec/cucumber"
6
+ require 'json_spec/cucumber'
7
+ require 'simplecov'
6
8
 
7
9
  SimpleCov.start
8
10
 
9
- Aruba.configure do |config|
10
- config.exit_timeout = 15
11
- config.io_wait_timeout = 2
11
+ ENV['CONJUR_APPLIANCE_URL'] ||= 'http://localhost/api/v6'
12
+ ENV['CONJUR_ACCOUNT'] ||= 'cucumber'
13
+
14
+ require 'conjur/cli'
15
+
16
+ Conjur::Config.load
17
+ Conjur::Config.apply
18
+
19
+ $netrc_file_path = ENV['CONJURRC'] || File.expand_path('~/.netrc')
20
+ if File.exists?($netrc_file_path)
21
+ $netrc_file = File.read($netrc_file_path)
12
22
  end
23
+
24
+ $conjur = Conjur::Authn.connect nil, noask: true
25
+
26
+ puts "Performing CLI tests as user '#{$conjur.current_role(Conjur.configuration.account).login}'"
@@ -1,127 +1,42 @@
1
- require 'ostruct'
2
-
3
- class MockAPI
4
- attr_reader :things
5
-
6
- def initialize
7
- @things = {}
8
- end
9
-
10
- def thing(kind, id)
11
- (@things[kind.to_sym] || []).find{|r| r.id == id}
12
- end
13
-
14
- def thing_like(kind, id_pattern)
15
- (@things[kind.to_sym] || []).find{|r| id_pattern.match(r.id)}
16
- end
17
-
18
- def create_host(options = {})
19
- id = options.delete(:id)
20
- if id
21
- host = thing(:host, id)
22
- else
23
- id = SecureRandom.uuid
24
- end
25
- host ||= create_thing(:host, id, options, role: true, api_key: true)
26
- end
27
-
28
- def create_user(id, options = {})
29
- thing(:user, id) || create_thing(:user, id, options, role: true, api_key: true)
30
- end
31
-
32
- def create_variable(mime_type, kind)
33
- create_thing(:user, SecureRandom.uuid, mime_type: mime_type, kind: kind)
34
- end
35
-
36
- def create_resource(id, options = {})
37
- resource(id).tap do |resource|
38
- resource.send(:"exists?=", true)
39
- populate_options resource, options
40
- end
41
- end
42
-
43
- def create_role(id, options = {})
44
- role(id).tap do |role|
45
- role.send(:"exists?=", true)
46
- populate_options role, options
47
- end
48
- end
49
-
50
- [ :user, :host ].each do |kind|
51
- define_method kind do |id|
52
- thing(kind, id)
53
- end
54
- end
55
-
56
- def role(id)
57
- raise "Role id must be a string" unless id.is_a?(String)
58
- thing(:role, id) || create_thing(:role, id, { exists?: false }, role: true)
59
- end
60
-
61
- def resource(id)
62
- raise "Resource id must be a string" unless id.is_a?(String)
63
- thing(:resource, id) || create_thing(:resource, id, exists?: false)
64
- end
65
-
66
- protected
67
-
68
- def create_thing(kind, id, options, kind_options = {})
69
- thing = OpenStruct.new(kind: kind, id: id, exists?: true)
70
-
71
- class << thing
72
- def permit(privilege, role, options = {})
73
- (self.permissions ||= []) << OpenStruct.new(privilege: privilege, role: role.id, grant_option: !!options[:grant_option])
74
- end
75
- end
76
-
77
- if kind_options[:api_key]
78
- thing.api_key = SecureRandom.uuid
79
- end
80
- if kind_options[:role]
81
- thing.roleid = id
82
- class << thing
83
- def can(privilege, resource, options = {})
84
- resource.permit privilege, self, options
85
- end
86
- end
87
- end
88
-
89
- populate_options(thing, options)
90
-
91
- store_thing kind, thing
92
-
93
- thing
94
- end
1
+ # Future Aruba
2
+ Aruba.configure do |config|
3
+ config.exit_timeout = 15
4
+ config.io_wait_timeout = 2
5
+ end
95
6
 
96
- def populate_options(thing, options)
97
- options.each do |k,v|
98
- thing.send("#{k}=", v)
99
- end
100
- end
7
+ Transform /\$conjur_url/ do |statement|
8
+ statement.gsub "$conjur_url", Conjur.configuration.appliance_url
9
+ end
101
10
 
102
- def store_thing(kind, thing)
103
- (things[kind] ||= []) << thing
11
+ Transform /\%\{\w+\}/ do |statement|
12
+ JsonSpec.memory.each do |k,v|
13
+ statement = statement.gsub("%{#{k}}", v)
104
14
  end
15
+ statement
105
16
  end
106
17
 
107
- Before("@dsl") do
108
- puts "Using MockAPI"
109
- puts "Using account 'cucumber'"
18
+ Before('@conjurapi-log') do
19
+ set_env 'CONJURAPI_LOG', 'stderr'
20
+ end
110
21
 
111
- require 'conjur/api'
112
- require 'conjur/config'
113
- require 'conjur/dsl/runner'
22
+ Before do
23
+ step %Q(I set the environment variable "CONJUR_AUTHN_LOGIN" to "#{$conjur.username}")
24
+ step %Q(I set the environment variable "CONJUR_AUTHN_API_KEY" to "#{$conjur.api_key}")
114
25
 
115
- Conjur.stub(:env).and_return "ci"
116
- Conjur.stub(:stack).and_return "ci"
117
- Conjur.stub(:account).and_return "cucumber"
26
+ $conjur.load_policy "root", File.read(File.expand_path('blank.yml', File.dirname(__FILE__))), method: Conjur::API::POLICY_METHOD_PUT
27
+ end
118
28
 
119
- Conjur::Core::API.stub(:conjur_account).and_return 'cucumber'
120
- @mock_api ||= MockAPI.new
121
- Conjur::DSL::Runner.any_instance.stub(:api).and_return @mock_api
29
+ After '@restore-login' do
30
+ step %Q(I run `conjur authn login #{$conjur.username}` interactively)
31
+ step %Q(I type "#{$conjur.api_key}")
122
32
  end
123
33
 
124
- Before('@real-api') do
125
- Conjur::Config.load
126
- Conjur::Config.apply
34
+ After do
35
+ tempfiles.each { |tempfile| File.unlink(tempfile) unless tempfile.nil? }
36
+ if $netrc_file && File.read($netrc_file_path) != $netrc_file
37
+ $stderr.puts "Restoring #{$netrc_file_path}"
38
+ require 'fileutils'
39
+ File.write($netrc_file_path, $netrc_file)
40
+ FileUtils.chmod 0600, $netrc_file_path
41
+ end
127
42
  end