conjur-api 4.31.0 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +1 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +22 -3
  5. data/Dockerfile +12 -3
  6. data/Gemfile +3 -3
  7. data/Jenkinsfile +69 -0
  8. data/LICENSE.md +195 -0
  9. data/README.md +16 -0
  10. data/Rakefile +34 -18
  11. data/ci/wait_for_server.sh +10 -0
  12. data/conjur-api.gemspec +6 -14
  13. data/dev/docker-compose.yml +23 -0
  14. data/dev/empty.yml +2 -0
  15. data/dev/start.sh +15 -0
  16. data/dev/stop.sh +6 -0
  17. data/docker-compose.yml +27 -0
  18. data/features/exists.feature +37 -0
  19. data/features/group.feature +11 -0
  20. data/features/host.feature +20 -0
  21. data/features/host_factory_create_host.feature +28 -0
  22. data/features/host_factory_token.feature +63 -0
  23. data/features/load_policy.feature +61 -0
  24. data/features/members.feature +51 -0
  25. data/features/new_api.feature +36 -0
  26. data/features/permitted.feature +43 -0
  27. data/features/permitted_roles.feature +30 -0
  28. data/features/public_keys.feature +11 -0
  29. data/features/resource_fields.feature +53 -0
  30. data/features/role_fields.feature +15 -0
  31. data/features/rotate_api_key.feature +13 -0
  32. data/features/step_definitions/api_steps.rb +4 -54
  33. data/features/step_definitions/policy_steps.rb +35 -0
  34. data/features/step_definitions/result_steps.rb +7 -0
  35. data/features/support/env.rb +14 -5
  36. data/features/support/hooks.rb +3 -0
  37. data/features/support/world.rb +5 -6
  38. data/features/update_password.feature +14 -0
  39. data/features/user.feature +17 -0
  40. data/features/variable_fields.feature +20 -0
  41. data/features/variable_value.feature +67 -0
  42. data/lib/conjur/acts_as_resource.rb +95 -65
  43. data/lib/conjur/acts_as_role.rb +102 -51
  44. data/lib/conjur/{audit-api.rb → acts_as_rolsource.rb} +10 -14
  45. data/lib/conjur/acts_as_user.rb +13 -22
  46. data/lib/conjur/api/authn.rb +37 -72
  47. data/lib/conjur/api/host_factories.rb +35 -55
  48. data/lib/conjur/api/policies.rb +56 -0
  49. data/lib/conjur/api/pubkeys.rb +36 -160
  50. data/lib/conjur/api/resources.rb +32 -116
  51. data/lib/conjur/api/roles.rb +28 -105
  52. data/lib/conjur/api/variables.rb +22 -91
  53. data/lib/conjur/api.rb +19 -46
  54. data/lib/conjur/base.rb +21 -132
  55. data/lib/conjur/base_object.rb +57 -0
  56. data/lib/conjur/{authn-api.rb → build_object.rb} +23 -11
  57. data/lib/conjur/cast.rb +12 -17
  58. data/lib/conjur/cert_utils.rb +1 -1
  59. data/lib/conjur/cidr.rb +1 -1
  60. data/lib/conjur/configuration.rb +13 -91
  61. data/lib/conjur/escape.rb +1 -2
  62. data/lib/conjur/group.rb +9 -65
  63. data/lib/conjur/has_attributes.rb +22 -59
  64. data/lib/conjur/host.rb +5 -35
  65. data/lib/conjur/host_factory.rb +40 -40
  66. data/lib/conjur/host_factory_token.rb +38 -23
  67. data/lib/conjur/id.rb +63 -0
  68. data/lib/conjur/layer.rb +5 -80
  69. data/lib/conjur/log.rb +1 -1
  70. data/lib/conjur/log_source.rb +1 -1
  71. data/lib/conjur/{secret.rb → policy.rb} +11 -14
  72. data/lib/conjur/{api/secrets.rb → policy_load_result.rb} +35 -22
  73. data/lib/conjur/query_string.rb +2 -1
  74. data/lib/conjur/resource.rb +5 -299
  75. data/lib/conjur/role.rb +5 -317
  76. data/lib/conjur/role_grant.rb +20 -28
  77. data/lib/conjur/user.rb +5 -63
  78. data/lib/conjur/variable.rb +31 -76
  79. data/lib/conjur/{authz-api.rb → webservice.rb} +8 -16
  80. data/lib/conjur-api/version.rb +2 -2
  81. data/publish.sh +7 -0
  82. data/spec/api_spec.rb +208 -0
  83. data/spec/cast_spec.rb +21 -0
  84. data/spec/{lib/cert_utils_spec.rb → cert_utils_spec.rb} +0 -0
  85. data/spec/{lib/cidr_spec.rb → cidr_spec.rb} +0 -0
  86. data/spec/{lib/configuration_spec.rb → configuration_spec.rb} +40 -140
  87. data/spec/{lib/has_attributes_spec.rb → has_attributes_spec.rb} +6 -2
  88. data/spec/{lib/log_source_spec.rb → log_source_spec.rb} +0 -0
  89. data/spec/{lib/log_spec.rb → log_spec.rb} +0 -0
  90. data/spec/roles_spec.rb +24 -0
  91. data/spec/spec_helper.rb +63 -78
  92. data/spec/ssl_spec.rb +3 -5
  93. data/spec/vendor/rest_client_spec.rb +0 -54
  94. data/test.sh +40 -0
  95. metadata +122 -281
  96. data/.kateproject +0 -5
  97. data/LICENSE +0 -22
  98. data/ci/test.sh +0 -9
  99. data/features/audit_resources.feature +0 -15
  100. data/features/audit_roles.feature +0 -15
  101. data/features/bootstrap.feature +0 -31
  102. data/features/step_definitions/cli_steps.rb +0 -5
  103. data/jenkins.sh +0 -27
  104. data/lib/conjur/acts_as_asset.rb +0 -88
  105. data/lib/conjur/annotations.rb +0 -186
  106. data/lib/conjur/api/audit.rb +0 -138
  107. data/lib/conjur/api/deputies.rb +0 -57
  108. data/lib/conjur/api/groups.rb +0 -111
  109. data/lib/conjur/api/hosts.rb +0 -109
  110. data/lib/conjur/api/info.rb +0 -126
  111. data/lib/conjur/api/layers.rb +0 -62
  112. data/lib/conjur/api/ldapsync.rb +0 -115
  113. data/lib/conjur/api/users.rb +0 -106
  114. data/lib/conjur/bootstrap.rb +0 -161
  115. data/lib/conjur/build_from_response.rb +0 -49
  116. data/lib/conjur/core-api.rb +0 -74
  117. data/lib/conjur/deputy.rb +0 -55
  118. data/lib/conjur/env.rb +0 -54
  119. data/lib/conjur/event_source.rb +0 -101
  120. data/lib/conjur/exists.rb +0 -60
  121. data/lib/conjur/graph.rb +0 -295
  122. data/lib/conjur/has_id.rb +0 -43
  123. data/lib/conjur/has_identifier.rb +0 -36
  124. data/lib/conjur/has_owner.rb +0 -51
  125. data/lib/conjur/host-factory-api.rb +0 -38
  126. data/lib/conjur/layer-api.rb +0 -13
  127. data/lib/conjur/ldap_sync_job.rb +0 -89
  128. data/lib/conjur/path_based.rb +0 -86
  129. data/lib/conjur/pubkeys-api.rb +0 -50
  130. data/lib/conjur/standard_methods.rb +0 -91
  131. data/reqspeed.rb +0 -20
  132. data/spec/api/authn_spec.rb +0 -81
  133. data/spec/api/graph_spec.rb +0 -117
  134. data/spec/api/groups_spec.rb +0 -40
  135. data/spec/api/hosts_spec.rb +0 -36
  136. data/spec/api/info_spec.rb +0 -89
  137. data/spec/api/layer_spec.rb +0 -18
  138. data/spec/api/ldapsync_spec.rb +0 -44
  139. data/spec/api/pubkeys_spec.rb +0 -66
  140. data/spec/api/resources_spec.rb +0 -92
  141. data/spec/api/roles_spec.rb +0 -100
  142. data/spec/api/secrets_spec.rb +0 -16
  143. data/spec/api/users_spec.rb +0 -71
  144. data/spec/api/variables_spec.rb +0 -112
  145. data/spec/cas_rest_client.rb +0 -17
  146. data/spec/cidr_helper.rb +0 -24
  147. data/spec/lib/acts_as_user_spec.rb +0 -27
  148. data/spec/lib/annotations_spec.rb +0 -109
  149. data/spec/lib/api_spec.rb +0 -480
  150. data/spec/lib/asset_spec.rb +0 -80
  151. data/spec/lib/audit_spec.rb +0 -155
  152. data/spec/lib/build_from_response_spec.rb +0 -49
  153. data/spec/lib/deputy_spec.rb +0 -25
  154. data/spec/lib/exists_spec.rb +0 -24
  155. data/spec/lib/group_spec.rb +0 -18
  156. data/spec/lib/host_spec.rb +0 -31
  157. data/spec/lib/resource_spec.rb +0 -240
  158. data/spec/lib/role_grant_spec.rb +0 -13
  159. data/spec/lib/role_spec.rb +0 -231
  160. data/spec/lib/standard_methods_spec.rb +0 -66
  161. data/spec/lib/user_spec.rb +0 -77
  162. data/spec/standard_methods_helper.rb +0 -41
  163. data/spec/variable_spec.rb +0 -101
  164. data/spec/vcr_cassettes/Conjur_Resource/_create/with_path-like_identifier.yml +0 -87
  165. data/spec/vcr_cassettes/Conjur_Resource/_create/with_un-encoded_path-like_identifier.yml +0 -87
  166. data/spec/vcr_cassettes/Conjur_Resource/_create/with_uuid_identifier.yml +0 -87
@@ -0,0 +1,28 @@
1
+ Feature: Create a host using a host factory token.
2
+
3
+ Background:
4
+ Given I run the code:
5
+ """
6
+ $conjur.load_policy 'root', <<-POLICY
7
+ - !policy
8
+ id: myapp
9
+ body:
10
+ - !layer
11
+
12
+ - !host-factory
13
+ layers: [ !layer ]
14
+ POLICY
15
+ @expiration = (DateTime.now + 1.hour).change(sec: 0)
16
+ @host_factory = $conjur.resource('cucumber:host_factory:myapp')
17
+ @token = @host_factory.create_token @expiration
18
+ """
19
+
20
+ Scenario: I can create a host from the token
21
+ When I run the code:
22
+ """
23
+ Conjur::API.host_factory_create_host(@token.token, "app-01")
24
+ """
25
+ Then the JSON should have "id"
26
+ And the JSON should have "permissions"
27
+ And the JSON should have "owner"
28
+ And the JSON should have "api_key"
@@ -0,0 +1,63 @@
1
+ Feature: Working with host factory tokens.
2
+
3
+ Background:
4
+ Given I run the code:
5
+ """
6
+ $conjur.load_policy 'root', <<-POLICY
7
+ - !policy
8
+ id: myapp
9
+ body:
10
+ - !layer
11
+
12
+ - !host-factory
13
+ layers: [ !layer ]
14
+ POLICY
15
+ @expiration = (DateTime.now + 1.hour).change(sec: 0)
16
+ @host_factory = $conjur.resource('cucumber:host_factory:myapp')
17
+ """
18
+
19
+ @wip
20
+ Scenario: Create a new host factory token.
21
+ When I run the code:
22
+ """
23
+ @token = @host_factory.create_token @expiration
24
+ """
25
+ Then I can run the code:
26
+ """
27
+ expect(@token).to be_instance_of(Conjur::HostFactoryToken)
28
+ expect(@token.token).to be_instance_of(String)
29
+ expiration = @token.expiration
30
+ expiration = expiration.change(sec: 0)
31
+ expect(expiration).to eq(@expiration)
32
+ """
33
+ And I can run the code:
34
+ """
35
+ expect(@host_factory.tokens).to eq([@token])
36
+ """
37
+
38
+ Scenario: Create multiple new host factory tokens.
39
+ When I run the code:
40
+ """
41
+ @host_factory.create_tokens @expiration, count: 2
42
+ """
43
+ Then the JSON should have 2 items
44
+
45
+ Scenario: Revoke a host factory token using the token object.
46
+ When I run the code:
47
+ """
48
+ @token = @host_factory.create_token @expiration
49
+ """
50
+ Then I can run the code:
51
+ """
52
+ @token.revoke
53
+ """
54
+
55
+ Scenario: Revoke a host factory token using the API.
56
+ When I run the code:
57
+ """
58
+ @token = @host_factory.create_token @expiration
59
+ """
60
+ Then I can run the code:
61
+ """
62
+ $conjur.revoke_host_factory_token @token.token
63
+ """
@@ -0,0 +1,61 @@
1
+ Feature: Load a policy.
2
+
3
+ Scenario: Policy can be loaded into a policy id.
4
+ Then I can run the code:
5
+ """
6
+ policy = <<-POLICY
7
+ - !group security_admin
8
+
9
+ - !policy
10
+ id: myapp
11
+ body:
12
+ - !layer
13
+
14
+ - !host-factory
15
+ layers: [ !layer ]
16
+
17
+ - !host app-01
18
+
19
+ - !grant
20
+ role: !layer myapp
21
+ member: !host app-01
22
+ POLICY
23
+
24
+ $conjur.load_policy 'root', policy
25
+ """
26
+
27
+ Scenario: The policy load reports the API keys of created roles.
28
+ Then I can run the code:
29
+ """
30
+ $conjur.load_policy 'root', <<-POLICY
31
+ - !host app-#{random_hex}
32
+ POLICY
33
+ """
34
+ Then the JSON should have "version"
35
+ And the JSON should have "created_roles"
36
+ And the JSON at "created_roles" should have 1 item
37
+
38
+ Scenario: Policy contents can be replaced using POLICY_METHOD_PUT.
39
+ Given I run the code:
40
+ """
41
+ $conjur.load_policy 'root', <<-POLICY
42
+ - !group developers
43
+ - !group operations
44
+ POLICY
45
+ """
46
+ And I run the code:
47
+ """
48
+ $conjur.load_policy 'root', <<-POLICY, method: Conjur::API::POLICY_METHOD_PUT
49
+ --- []
50
+ POLICY
51
+ """
52
+ And I run the code:
53
+ """
54
+ $conjur.resources.map(&:id)
55
+ """
56
+ Then the JSON should be:
57
+ """
58
+ [
59
+ "cucumber:policy:root"
60
+ ]
61
+ """
@@ -0,0 +1,51 @@
1
+ Feature: Display role members and memberships.
2
+
3
+ Background:
4
+ Given I run the code:
5
+ """
6
+ $conjur.load_policy 'root', <<-POLICY
7
+ - !group everyone
8
+ - !group developers
9
+ - !grant
10
+ role: !group everyone
11
+ member: !group developers
12
+ POLICY
13
+ """
14
+
15
+ Scenario: Show a role's members.
16
+ When I run the code:
17
+ """
18
+ $conjur.role('cucumber:group:everyone').members.map(&:as_json)
19
+ """
20
+ Then the JSON should be:
21
+ """
22
+ [
23
+ {
24
+ "admin_option": true,
25
+ "member": "cucumber:user:admin",
26
+ "role": "cucumber:group:everyone"
27
+ },
28
+ {
29
+ "admin_option": false,
30
+ "member": "cucumber:group:developers",
31
+ "role": "cucumber:group:everyone"
32
+ }
33
+ ]
34
+ """
35
+
36
+ Scenario: Show a role's memberships.
37
+ When I run the code:
38
+ """
39
+ $conjur.role('cucumber:group:developers').memberships.map(&:as_json)
40
+ """
41
+ Then the JSON should be:
42
+ """
43
+ [
44
+ {
45
+ "id": "cucumber:group:developers"
46
+ },
47
+ {
48
+ "id": "cucumber:group:everyone"
49
+ }
50
+ ]
51
+ """
@@ -0,0 +1,36 @@
1
+ Feature: Constructing a new API object.
2
+ Background:
3
+ Given a new host
4
+
5
+ Scenario: From API key.
6
+ Then I run the code:
7
+ """
8
+ api = Conjur::API.new_from_key "host/#{@host_id}", @host_api_key
9
+ expect(api.token).to be_instance_of(Hash)
10
+ expect(api.resource("cucumber:host:#{@host_id}")).to exist
11
+ """
12
+
13
+ Scenario: From access token.
14
+ Given I run the code:
15
+ """
16
+ @token = Conjur::API.new_from_key("host/#{@host_id}", @host_api_key).token
17
+ """
18
+ Then I run the code:
19
+ """
20
+ api = Conjur::API.new_from_token @token
21
+ expect(api.resource("cucumber:host:#{@host_id}")).to exist
22
+ """
23
+
24
+ Scenario: From access token file.
25
+ Given I run the code:
26
+ """
27
+ token = Conjur::API.new_from_key("host/#{@host_id}", @host_api_key).token
28
+ @temp_file = Tempfile.new("token.json")
29
+ @temp_file.write(token.to_json)
30
+ @temp_file.flush
31
+ """
32
+ Then I run the code:
33
+ """
34
+ api = Conjur::API.new_from_token_file @temp_file.path
35
+ expect(api.resource("cucumber:host:#{@host_id}")).to exist
36
+ """
@@ -0,0 +1,43 @@
1
+ Feature: Check if a role has permission on a resource.
2
+
3
+ Background:
4
+ Given I run the code:
5
+ """
6
+ @host_id = "app-#{random_hex}"
7
+ response = $conjur.load_policy 'root', <<-POLICY
8
+ - !variable db-password
9
+
10
+ - !layer myapp
11
+
12
+ - !host #{@host_id}
13
+
14
+ - !permit
15
+ role: !layer myapp
16
+ privilege: execute
17
+ resource: !variable db-password
18
+ POLICY
19
+ @host_api_key = response.created_roles["cucumber:host:#{@host_id}"]['api_key']
20
+ expect(@host_api_key).to be
21
+ """
22
+
23
+ Scenario: Check if the current user has the privilege.
24
+ When I run the code:
25
+ """
26
+ $conjur.resource('cucumber:variable:db-password').permitted? 'execute'
27
+ """
28
+ Then the result should be "true"
29
+
30
+ Scenario: Check if a different user has the privilege.
31
+ When I run the code:
32
+ """
33
+ $conjur.resource('cucumber:variable:db-password').permitted? 'execute', role: "cucumber:host:#{@host_id}"
34
+ """
35
+ Then the result should be "false"
36
+
37
+ Scenario: Check if a different user has the privilege, while logged in as that user.
38
+ When I run the code:
39
+ """
40
+ host_api = Conjur::API.new_from_key "host/#{@host_id}", @host_api_key
41
+ host_api.resource('cucumber:variable:db-password').permitted? 'execute'
42
+ """
43
+ Then the result should be "false"
@@ -0,0 +1,30 @@
1
+ Feature: Enumerate roles which have a permission on a resource.
2
+
3
+ Background:
4
+ Given I run the code:
5
+ """
6
+ $conjur.load_policy 'root', <<-POLICY
7
+ - !variable db-password
8
+
9
+ - !layer myapp
10
+
11
+ - !permit
12
+ role: !layer myapp
13
+ privilege: execute
14
+ resource: !variable db-password
15
+ POLICY
16
+ """
17
+
18
+ @wip
19
+ Scenario: Permitted roles can be enumerated.
20
+ When I run the code:
21
+ """
22
+ $conjur.resource('cucumber:variable:db-password').permitted_roles 'execute'
23
+ """
24
+ Then the JSON should be:
25
+ """
26
+ [
27
+ "cucumber:layer:myapp",
28
+ "cucumber:user:admin"
29
+ ]
30
+ """
@@ -0,0 +1,11 @@
1
+ Feature: Fetch public keys for a user.
2
+
3
+ Background:
4
+ Given a new user
5
+
6
+ Scenario: User has a uidnumber.
7
+ When I run the code:
8
+ """
9
+ Conjur::API.public_keys @user.login
10
+ """
11
+ Then the result should be the public key
@@ -0,0 +1,53 @@
1
+ Feature: Display basic resource fields.
2
+
3
+ Background:
4
+ Given I run the code:
5
+ """
6
+ $conjur.load_policy 'root', <<-POLICY
7
+ - !group
8
+ id: developers
9
+ annotations:
10
+ gidnumber: 2000
11
+ POLICY
12
+ """
13
+
14
+ Scenario: Resource exposes id, kind, identifier, and attributes.
15
+ When I run the code:
16
+ """
17
+ resource = $conjur.resource('cucumber:group:developers')
18
+ [ resource.id, resource.account, resource.kind, resource.identifier, resource.attributes ]
19
+ """
20
+ Then the JSON should be:
21
+ """
22
+ [
23
+ "cucumber:group:developers",
24
+ "cucumber",
25
+ "group",
26
+ "developers",
27
+ {
28
+ "annotations": [
29
+ {
30
+ "name": "gidnumber",
31
+ "policy": "cucumber:policy:root",
32
+ "value": "2000"
33
+ }
34
+ ],
35
+ "owner": "cucumber:user:admin",
36
+ "permissions": [
37
+ ],
38
+ "policy": "cucumber:policy:root"
39
+ }
40
+ ]
41
+ """
42
+
43
+ Scenario: Resource#owner is the owner object
44
+ When I run the code:
45
+ """
46
+ $conjur.resource('cucumber:group:developers').owner.id
47
+ """
48
+ Then the result should be "cucumber:user:admin"
49
+ And I run the code:
50
+ """
51
+ $conjur.resource('cucumber:group:developers').class
52
+ """
53
+ Then the result should be "Conjur::Group"
@@ -0,0 +1,15 @@
1
+ Feature: Display basic role fields.
2
+
3
+ Scenario: Login of a user is the login name.
4
+ When I run the code:
5
+ """
6
+ $conjur.role('cucumber:user:alice').login
7
+ """
8
+ Then the result should be "alice"
9
+
10
+ Scenario: Login of a non-user is prefixed with the role kind.
11
+ When I run the code:
12
+ """
13
+ $conjur.role('cucumber:host:myapp').login
14
+ """
15
+ Then the result should be "host/myapp"
@@ -0,0 +1,13 @@
1
+ Feature: Rotate the API key.
2
+
3
+ Scenario: Logged-in user can rotate the API key.
4
+ When I run the code:
5
+ """
6
+ Conjur::API.rotate_api_key 'admin', $api_key
7
+ """
8
+ Then I can run the code:
9
+ """
10
+ $api_key = @result.strip
11
+ $conjur = Conjur::API.new_from_key $username, @result
12
+ $conjur.token
13
+ """
@@ -1,57 +1,7 @@
1
- Then(/^I bootstrap$/) do
2
- class Listener
3
- attr_accessor :messages
4
-
5
- def initialize
6
- @messages = []
1
+ When(/^I(?: can)? run the code:$/) do |code|
2
+ @result = eval(code).tap do |result|
3
+ if ENV['DEBUG']
4
+ puts result
7
5
  end
8
-
9
- def echo msg
10
- @messages.push msg
11
- end
12
- end
13
- @listener = Listener.new
14
-
15
- $conjur.bootstrap @listener
16
- end
17
-
18
- Then(/^expressions "([^"]*)" and "([^"]*)" are equal$/) do |code, test|
19
- expect(eval(code)).to eq(eval(test))
20
- end
21
-
22
- Then(/^expression "(.*?)" is equal to$/) do |code, test|
23
- step %Q{expressions "#{code}" and "#{test}" are equal}
24
- end
25
-
26
- Then(/^expression "([^"]*)" includes "([^"]*)"$/) do |code, test|
27
- expect(eval(code)).to include(eval(test))
28
- end
29
-
30
- Then(/^I evaluate the expression "([^"]*)"$/) do |code|
31
- eval(code)
32
- end
33
-
34
- Then(/^I evaluate the expression$/) do |code|
35
- step %Q{I evaluate the expression "#{code}"}
36
- end
37
-
38
- Then(/^I create the variable "(.*?)"$/) do |var|
39
- api.create_variable('text/plain', 'secret', :id => var)
40
- end
41
-
42
- Then(/^I create an api with the additional audit (role|resource)[s]* "(.*?)"$/) do |type, things|
43
- @api = api.send("with_audit_#{type}s", things.split(','))
44
- end
45
-
46
- Then(/^I check to see if I'm permitted to "(.*?)" variable "(.*?)"$/) do |priv, var|
47
- api.variable(var).resource.permitted?(priv)
48
- end
49
-
50
- Then(/^an audit event for variable "(.*?)" with action "(.*?)" and (role|resource)[s]* "(.*?)" is generated$/) do |var, action, type, things|
51
- resource_ids = things.split(',').collect {|id| api.resource(id).resourceid }
52
- event_found = api.audit_resource(api.resource("variable:#{var}")).any? do |e|
53
- e['action'] == action &&
54
- Set.new(e["#{type}s"]).superset?(Set.new(resource_ids))
55
6
  end
56
- expect(event_found).to be true
57
7
  end
@@ -0,0 +1,35 @@
1
+ Given(/^a new user$/) do
2
+ @user_id = "user-#{random_hex}"
3
+ @public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDd/PAcCL9rW/zAS7DRns/KYiAvRAEKxBu/0IF32z7x6YiMFcA2hmH4DMYaIY45Xlj7L9uTZamUlRZNjSS9Xm6Lhh7XGceIX2067/MDnH+or9xh5LZs6gb3x7QVtNz26Au5h5kP0xoJ+wpVxvY707BeSax/WQZI8akqd0fD1IqOoafWkcX0ucu5iIgDh08R7zq3vrDHEK7+SoYo9ncHfmOUJ5lmImGiU/WMqM0OzN3RsgxJi/aaHjW1IASTY8TmAtTtjEsxbQXxRVUCAP9vWUZg7p3aqIB6sEP8skgncCUtHBQxUtE1XN8Q8NeFOzau6+9sQTXlPl8c/L4Jc4K96C75 #{@user_id}@example.com"
4
+ response = $conjur.load_policy 'root', <<-POLICY
5
+ - !user
6
+ id: #{@user_id}
7
+ uidnumber: 1000
8
+ public_keys:
9
+ - #{@public_key}
10
+ POLICY
11
+ @user = $conjur.resource("cucumber:user:#{@user_id}")
12
+ @user_api_key = response.created_roles["cucumber:user:#{@user_id}"]['api_key']
13
+ expect(@user_api_key).to be
14
+ end
15
+
16
+ Given(/^a new group$/) do
17
+ @group_id = "group-#{random_hex}"
18
+ response = $conjur.load_policy 'root', <<-POLICY
19
+ - !group
20
+ id: #{@group_id}
21
+ gidnumber: 1000
22
+ POLICY
23
+ @group = $conjur.resource("cucumber:group:#{@group_id}")
24
+ end
25
+
26
+ Given(/^a new host$/) do
27
+ @host_id = "app-#{random_hex}"
28
+ response = $conjur.load_policy 'root', <<-POLICY
29
+ - !host #{@host_id}
30
+ POLICY
31
+ @host_api_key = response.created_roles["cucumber:host:#{@host_id}"]['api_key']
32
+ expect(@host_api_key).to be
33
+ @host = $conjur.resource("cucumber:host:#{@host_id}")
34
+ @host.attributes['api_key'] = @host_api_key
35
+ end
@@ -0,0 +1,7 @@
1
+ Then(/^the result should be "([^"]+)"$/) do |expected|
2
+ expect(@result.to_s).to eq(expected.to_s)
3
+ end
4
+
5
+ Then(/^the result should be the public key$/) do
6
+ expect(@result).to eq(@public_key + "\n")
7
+ end
@@ -1,6 +1,15 @@
1
- require 'aruba/cucumber'
2
- require 'conjur/cli'
1
+ require 'simplecov'
3
2
 
4
- Conjur::Config.load
5
- Conjur::Config.apply
6
- $conjur = Conjur::Authn.connect nil, noask: true
3
+ SimpleCov.start
4
+
5
+ require 'json_spec/cucumber'
6
+ require 'conjur/api'
7
+
8
+ Conjur.configuration.appliance_url = ENV['CONJUR_APPLIANCE_URL'] || 'http://localhost/api/v6'
9
+ Conjur.configuration.account = ENV['CONJUR_ACCOUNT'] || 'cucumber'
10
+
11
+ $username = ENV['CONJUR_AUTHN_LOGIN'] || 'admin'
12
+ $password = ENV['CONJUR_AUTHN_API_KEY'] || 'secret'
13
+
14
+ $api_key = Conjur::API.login $username, $password
15
+ $conjur = Conjur::API.new_from_key $username, $api_key
@@ -0,0 +1,3 @@
1
+ Before do
2
+ $conjur.load_policy 'root', "--- []"
3
+ end
@@ -1,13 +1,12 @@
1
1
  module ApiWorld
2
-
3
- def api
4
- @api ||= Conjur::Authn.connect(nil, :noask => true)
2
+ def last_json
3
+ @result.to_json
5
4
  end
6
5
 
7
- def namespace
8
- @namespace ||= api.create_variable('text/plain', 'id').id.tap {|ns| puts "namespace: #{ns}"}
6
+ def random_hex nbytes = 12
7
+ @random ||= Random.new
8
+ @random.bytes(nbytes).unpack('h*').first
9
9
  end
10
-
11
10
  end
12
11
 
13
12
  World ApiWorld
@@ -0,0 +1,14 @@
1
+ Feature: Change a user's password.
2
+ Background:
3
+ Given a new user
4
+
5
+ Scenario: A user can set/change her password using the current API key.
6
+ When I run the code:
7
+ """
8
+ Conjur::API.update_password @user_id, @user_api_key, 'secret'
9
+ @new_api_key = Conjur::API.login @user_id, 'secret'
10
+ """
11
+ Then I can run the code:
12
+ """
13
+ Conjur::API.new_from_key(@user_id, @new_api_key).token
14
+ """
@@ -0,0 +1,17 @@
1
+ Feature: Display User object fields.
2
+
3
+ Background:
4
+ Given a new user
5
+
6
+ Scenario: User has a uidnumber.
7
+ Then I run the code:
8
+ """
9
+ @user.uidnumber
10
+ """
11
+ Then the result should be "1000"
12
+
13
+ Scenario: Logged-in user is the current_role.
14
+ Then I run the code:
15
+ """
16
+ expect($conjur.current_role(Conjur.configuration.account).id.to_s).to eq("cucumber:user:admin")
17
+ """
@@ -0,0 +1,20 @@
1
+ Feature: Display Variable fields.
2
+
3
+ Background:
4
+ Given I run the code:
5
+ """
6
+ $conjur.load_policy 'root', <<-POLICY
7
+ - !variable
8
+ id: ssl-certificate
9
+ kind: SSL certificate
10
+ mime_type: application/x-pem-file
11
+ POLICY
12
+ """
13
+ And I run the code:
14
+ """
15
+ $conjur.resource('cucumber:variable:ssl-certificate')
16
+ """
17
+
18
+ Scenario: Display MIME type and kind
19
+ Then the JSON at "mime_type" should be "application/x-pem-file"
20
+ And the JSON at "kind" should be "SSL certificate"