conjur-cli 5.6.6 → 6.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Command::Elevate do
4
- describe_command "elevate user show alice" do
5
- include_context "with mock authn"
6
-
7
- let(:token) { {login: 'dknuth'} }
8
- before{
9
- expect(Conjur::Authn).to receive(:connect).and_return(api)
10
- }
11
- it "invokes the sub-command with X-Conjur-Privilege header" do
12
- allow_any_instance_of(Conjur::API).to receive(:token).and_return(token)
13
- expect(Conjur::Command).to receive(:api=) do |api|
14
- expect(api.api_key).to eq("sekrit")
15
- expect(api.privilege).to eq("elevate")
16
- end.and_call_original
17
-
18
- expect(RestClient::Request).to receive(:execute).with({
19
- method: :get,
20
- url: "https://core.example.com/api/users/alice",
21
- username: "dknuth",
22
- headers: {:authorization=>"Token token=\"eyJsb2dpbiI6ImRrbnV0aCJ9\"", x_conjur_privilege: "elevate"}
23
- }).and_return(double(:response, body: "[]"))
24
-
25
- invoke
26
- end
27
- end
28
- end
@@ -1,168 +0,0 @@
1
- require 'spec_helper'
2
- require 'conjur/conjurenv'
3
- require 'tempfile'
4
-
5
-
6
- shared_examples_for "processes environment definition" do |cmd, options|
7
- before { # suspend all interaction with the environment
8
- allow(Kernel).to receive(:system).and_return(true)
9
- }
10
- let(:stub_object) { double(obtain:{}, check:{}) }
11
-
12
- describe_command "env:#{cmd} #{options}" do
13
- it "uses .conjurenv file by default" do
14
- expect(Conjur::Env).to receive(:new).with(file:".conjurenv").and_return(stub_object)
15
- invoke
16
- end
17
- end
18
-
19
- describe_command "env:#{cmd} -c somefile #{options}" do
20
- it "uses desired file" do
21
- expect(Conjur::Env).to receive(:new).with(file:"somefile").and_return(stub_object)
22
- invoke
23
- end
24
- end
25
-
26
- describe_command "env:#{cmd} --yaml someyaml #{options}" do
27
- it "uses inline yaml" do
28
- expect(Conjur::Env).to receive(:new).with(yaml:"someyaml").and_return(stub_object)
29
- invoke
30
- end
31
- end
32
-
33
- describe_command "env:#{cmd} -c somefile --yaml someyaml #{options}" do
34
- it "refuses to accept mutually exclusive options" do
35
- expect(Conjur::Env).not_to receive(:new)
36
- expect { invoke }.to raise_error /Options -c and --yaml can not be provided together/
37
- end
38
- end
39
- end
40
-
41
- shared_examples_for "accepts policy option" do |cmd, options|
42
- before { # suspend all interaction with the environment
43
- allow(Kernel).to receive(:system).and_return(true)
44
- }
45
- let(:stub_object) { double(obtain:{}, check:{}) }
46
- describe_command "env:#{cmd} --policy foobar #{options}" do
47
- it "uses .conjurenv file by default" do
48
- expect(Conjur::Env).to receive(:new).with(file:".conjurenv", substitutions: { "$policy" => "foobar" }).and_return(stub_object)
49
- invoke
50
- end
51
- end
52
- end
53
-
54
- describe Conjur::Command::Env, logged_in: true do
55
-
56
- let(:stub_env) { double() }
57
- describe ":check" do
58
- it_behaves_like "processes environment definition", "check", ''
59
- it_behaves_like "accepts policy option", "check", ''
60
-
61
- describe_command "env:check" do
62
- before { expect(Conjur::Env).to receive(:new).and_return(stub_env) }
63
- describe "without api errors" do
64
- let(:stub_result) { { "a" => :available, "b"=> :available } }
65
- before {
66
- expect(stub_env).to receive(:check).with(an_instance_of(Conjur::API)).and_return(stub_result)
67
- }
68
-
69
- describe "if all variables are available" do
70
- it "prints #check result to the output" do
71
- expect { invoke }.to write "a: available\nb: available\n"
72
- end
73
-
74
- it "does not crash" do
75
- expect { invoke }.to_not raise_error
76
- end
77
- end
78
-
79
- describe "if some variables are unavailable" do
80
- let(:stub_result) { { "a" => :unavailable, "b"=> :available } }
81
- it "prints #check result to the output" do
82
- expect { invoke rescue true }.to write "a: unavailable\nb: available\n"
83
- end
84
- it "crashes in the end" do
85
- expect { invoke }.to raise_error "Some variables are not available"
86
- end
87
- end
88
- end
89
- it 'does not rescue unexpected errors' do
90
- expect(stub_env).to receive(:check).with(an_instance_of(Conjur::API)) { raise "Custom error" }
91
- expect { invoke }.to raise_error "Custom error"
92
- end
93
- end
94
- end
95
-
96
- describe ":run" do
97
- it_behaves_like "processes environment definition", "run","-- extcmd"
98
- it_behaves_like "accepts policy option", "run", '-- extcmd'
99
- describe_command "env:run" do
100
- it 'fails because of missing argument' do
101
- expect(Kernel).not_to receive(:system)
102
- expect { invoke }.to raise_error "External command with optional arguments should be provided"
103
- end
104
- end
105
- describe_command "env:run -- extcmd --arg1 arg2" do
106
- before {
107
- expect(Conjur::Env).to receive(:new).and_return(stub_env)
108
- }
109
-
110
- describe "if no errors are raised" do
111
- let(:stub_result) { { "a" => "value_a", "b" => "value_b" } }
112
- before {
113
- expect(stub_env).to receive(:obtain).with(an_instance_of(Conjur::API)).and_return(stub_result)
114
- }
115
- it "performs #exec with environment (names in uppercase)" do
116
- expect(Kernel).to receive(:system).with({"A"=>"value_a", "B"=>"value_b"}, "extcmd", "--arg1","arg2").and_return(true)
117
- invoke
118
- end
119
- end
120
- it "does not rescue unexpected errors" do
121
- expect(stub_env).to receive(:obtain).with(an_instance_of(Conjur::API)) { raise "Custom error" }
122
- expect { invoke }.to raise_error "Custom error"
123
- end
124
- end
125
- end
126
-
127
- describe ":template" do
128
- context do
129
- before { # prevent real operation
130
- allow(File).to receive(:readable?).with("config.erb").and_return(true)
131
- allow(File).to receive(:read).with("config.erb").and_return("template")
132
- allow(ERB).to receive(:new).and_return(double(result:''))
133
- allow(Tempfile).to receive(:new).and_return(double(write: true, close: true, path: 'somepath'))
134
- allow(FileUtils).to receive(:copy).and_return(true)
135
- }
136
- it_behaves_like "processes environment definition", "template","config.erb"
137
- it_behaves_like "accepts policy option", "template", 'config.erb'
138
- end
139
- describe_command "env:template" do
140
- it 'fails because of missing argument' do
141
- expect(Tempfile).not_to receive(:new)
142
- expect { invoke }.to raise_error "Location of readable ERB template should be provided"
143
- end
144
- end
145
- describe_command "env:template config.erb" do
146
- let(:erb_template) { """
147
- variable <%= conjurenv['a'] %>
148
- other variable <%= conjurenv['b'] %>
149
- """
150
- }
151
- before {
152
- allow(File).to receive(:readable?).with("config.erb").and_return(true)
153
- allow(File).to receive(:read).with("config.erb").and_return(erb_template)
154
- expect(Conjur::Env).to receive(:new).and_return(stub_env)
155
- expect(stub_env).to receive(:obtain).with(an_instance_of(Conjur::API)).and_return( {"a"=>"value_a","b"=>"value_b","c"=>"value_c"} )
156
- }
157
-
158
- it "creates persistent tempfile, saves rendered template into it, prints out name of the file" do
159
- stubpath="/tmp/temp.file"
160
- tempfile=double(close: true, path: stubpath)
161
- expect(Tempfile).to receive(:new).and_return(tempfile)
162
- expect(tempfile).to receive(:write).with("\nvariable value_a\nother variable value_b\n")
163
- expect(FileUtils).to receive(:copy).with(stubpath,stubpath+'.saved') # avoid garbage collection
164
- expect { invoke }.to write stubpath+".saved"
165
- end
166
- end
167
- end
168
- end
@@ -1,77 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Command::Groups, logged_in: true do
4
- describe_command 'group create --gidnumber 12345 some-group' do
5
- it "creates the group with a specified gidnumber" do
6
- expect_any_instance_of(Conjur::API).to receive(:create_group).with('some-group', gidnumber: 12345).and_return "something"
7
- expect { invoke }.to write "something"
8
- end
9
- end
10
-
11
- describe_command 'group update --gidnumber 12345 some-group' do
12
- it "updates the gid" do
13
- expect_any_instance_of(Conjur::API).to \
14
- receive(:group).with('some-group').and_return(group = double("group"))
15
- expect(group).to receive(:update).with(gidnumber: 12_345)
16
- expect { invoke }.to write "GID set"
17
- end
18
- end
19
-
20
- context "lookup by GID" do
21
- let(:search_result) { %w(g1 g2) }
22
- describe_command "group gidsearch 12345" do
23
- it "finds the groups" do
24
- expect_any_instance_of(Conjur::API).to \
25
- receive(:find_groups).with(gidnumber: 12_345).and_return search_result
26
- expect { invoke }.to write(JSON.pretty_generate(search_result))
27
- end
28
- end
29
- end
30
-
31
- describe_command "group:members:add group user:alice" do
32
- it "adds the role to the group" do
33
- expect(RestClient::Request).to receive(:execute).with({
34
- method: :put,
35
- url: "https://authz.example.com/the-account/roles/group/group/?members&member=user:alice",
36
- headers: {},
37
- payload: nil
38
- })
39
- invoke
40
- end
41
- end
42
-
43
- describe_command "group:members:add -a group user:alice" do
44
- it "adds the role to the group with admin option" do
45
- expect(RestClient::Request).to receive(:execute).with({
46
- method: :put,
47
- url: "https://authz.example.com/the-account/roles/group/group/?members&member=user:alice",
48
- headers: {},
49
- payload: { admin_option: true }
50
- })
51
- invoke
52
- end
53
- end
54
- describe_command "group:members:add -a group alice" do
55
- it "assumes that a nake member name is a user" do
56
- expect(RestClient::Request).to receive(:execute).with({
57
- method: :put,
58
- url: "https://authz.example.com/the-account/roles/group/group/?members&member=user:alice",
59
- headers: {},
60
- payload: { admin_option: true }
61
- })
62
- invoke
63
- end
64
- end
65
-
66
- describe_command "group:members:add -r group alice" do
67
- it "revokes the admin rights" do
68
- expect(RestClient::Request).to receive(:execute).with({
69
- method: :put,
70
- url: "https://authz.example.com/the-account/roles/group/group/?members&member=user:alice",
71
- headers: {},
72
- payload: { admin_option: false }
73
- })
74
- invoke
75
- end
76
- end
77
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
- require 'conjur/command/host_factories'
3
-
4
- describe Conjur::Command::HostFactories, :logged_in => true do
5
- let (:group_memberships) { double(:group_memberships, :roleid => 'the-account:group:security_admin') }
6
- let (:current_role) { double(:current_role, roleid: 'the-account:user:dknuth', :memberships => [ double(:current_role_role, roleid: 'the-account:user:dknuth') ]) }
7
- let (:group_members) { double(:layer_members, :member => double(:member, :roleid => 'the-account:user:dknuth'), :admin_option => true ) }
8
- let (:group) { double(:group, roleid: 'the-account:group:the-group', :exists? => true, :memberships => [group_memberships], :members => [group_members]) }
9
- let (:layer_members) { double(:layer_members, :member => double(:member, :roleid => 'the-account:group:security_admin'), :admin_option => true ) }
10
- let (:layer_role) { double(:layer_role, roleid: 'the-account:layer:layer1', :members => [layer_members]) }
11
- let (:layer) { double(:layer, :exists? => true, :role => layer_role) }
12
-
13
- before do
14
- allow(Conjur::Command.api).to receive(:role).with("user:dknuth").and_return current_role
15
- allow(Conjur::Command.api).to receive(:role).with("the-account:group:the-group").and_return group
16
- allow(Conjur::Command.api).to receive(:layer).with("layer1").and_return layer
17
- end
18
-
19
- describe_command 'hostfactory:create --as-group the-group --layer layer1 hf1 ' do
20
- it 'calls api.create_host_factory and prints the results' do
21
- expect_any_instance_of(Conjur::API).to receive(:create_host_factory).and_return '{}'
22
- expect { invoke }.to write('{}')
23
- end
24
- end
25
-
26
- context 'command-line errors' do
27
- describe_command 'hostfactory:create hf1' do
28
- it "fails without owner" do
29
- expect {invoke}.to raise_error('Use --as-group or --as-role to indicate the host factory role')
30
- end
31
- end
32
- describe_command 'hostfactory:create --as-group the-group hf' do
33
- it "fails without layer" do
34
- expect {invoke}.to raise_error('Provide at least one layer')
35
- end
36
- end
37
- end
38
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Command::Layers, logged_in: true do
4
- let(:layer) { double(:layer) }
5
-
6
- [ "layer hosts add", "layer:hosts:add" ].each do |cmd|
7
- describe_command "#{cmd} the-layer the-host" do
8
- it "adds a host id to the layer" do
9
- expect_any_instance_of(Conjur::API).to receive(:layer).with("the-layer").and_return layer
10
- expect(layer).to receive(:add_host).with("the-account:host:the-host")
11
-
12
- expect { invoke }.to write("Host added")
13
- end
14
- end
15
- describe_command "#{cmd} the-layer host:the-host" do
16
- it "adds a qualified host id to the layer" do
17
- expect_any_instance_of(Conjur::API).to receive(:layer).with("the-layer").and_return layer
18
- expect(layer).to receive(:add_host).with("host:the-host")
19
-
20
- expect { invoke }.to write("Host added")
21
- end
22
- end
23
- end
24
-
25
- [ "layer hosts remove", "layer:hosts:remove" ].each do |cmd|
26
- describe_command "#{cmd} the-layer the-host" do
27
- it "adds a host to the layer" do
28
- expect_any_instance_of(Conjur::API).to receive(:layer).with("the-layer").and_return layer
29
- expect(layer).to receive(:remove_host).with("the-account:host:the-host")
30
-
31
- expect { invoke }.to write("Host removed")
32
- end
33
- end
34
- end
35
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Command::LDAPSync, logged_in: true do
4
-
5
- let (:policy_response) { { 'ok' => true, 'events' => [], 'policy' => <<eop
6
- "---
7
- - !user
8
- annotations:
9
- ldap-sync/source: ldap-server:389
10
- ldap-sync/upstream-dn: CN=Administrator,OU=functest,OU=testdata,OU=dev-ci,DC=dev-ci,DC=conjur
11
- id: Administrator
12
- uidnumber:"}
13
- eop
14
- }
15
- }
16
-
17
- describe_command "ldap-sync policy show" do
18
-
19
- before do
20
- expect_any_instance_of(Conjur::API).to receive(:ldap_sync_policy).with('default').and_return policy_response
21
- end
22
-
23
- it "shows the policy" do
24
- expect { invoke }.to write policy_response['policy']
25
- end
26
- end
27
-
28
- end
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
- require 'conjur/dsl/runner'
3
-
4
- describe Conjur::Command::RubyDSL do
5
- context "when logged in", logged_in: true do
6
- let(:role) do
7
- double("role", exists?: true, api_key: "the-api-key", roleid: "the-role")
8
- end
9
- let(:resource) do
10
- double("resource", exists?: true).as_null_object
11
- end
12
- before {
13
- allow(File).to receive(:read).and_call_original
14
- allow(File).to receive(:exists?).and_call_original
15
- allow(File).to receive(:exists?).with("policy.rb").and_return true
16
- allow(File).to receive(:read).with("policy.rb").and_return "{}"
17
- allow_any_instance_of(Conjur::DSL::Runner).to receive(:api).and_return api
18
- }
19
- before {
20
- allow(api).to receive(:role).and_call_original
21
- allow(api).to receive(:resource).and_call_original
22
- allow(api).to receive(:role).with("the-account:policy:#{collection}/the-policy-1.0.0").and_return role
23
- allow(api).to receive(:resource).with("the-account:policy:#{collection}/the-policy-1.0.0").and_return resource
24
- }
25
-
26
- describe_command 'rubydsl:load --collection the-collection http://example.com/policy.rb' do
27
- let(:collection) { "the-collection" }
28
- before {
29
- allow(File).to receive(:exists?).with("http://example.com/policy.rb").and_return false
30
- allow(URI).to receive(:parse).with("http://example.com/policy.rb").and_return double(:uri, read: "{}")
31
- }
32
- it "creates the policy" do
33
- expect(invoke).to eq(0)
34
- end
35
- end
36
- describe_command 'rubydsl:load --collection the-collection policy.rb' do
37
- let(:collection) { "the-collection" }
38
- it "creates the policy" do
39
- expect(invoke).to eq(0)
40
- end
41
- end
42
- context "default collection" do
43
- let(:collection) { "alice@localhost" }
44
- before {
45
- stub_const("ENV", "USER" => "alice", "HOSTNAME" => "localhost")
46
- }
47
- describe_command 'rubydsl:load --as-group the-group policy.rb' do
48
- let(:group) { double(:group, exists?: true) }
49
- it "creates the policy" do
50
- allow(Conjur::Command.api).to receive(:role).with("the-account:group:the-group").and_return group
51
- expect_any_instance_of(Conjur::DSL::Runner).to receive(:owner=).with("the-account:group:the-group")
52
-
53
- expect(invoke).to eq(0)
54
- end
55
- end
56
- describe_command 'rubydsl:load policy.rb' do
57
- it "creates the policy with default collection" do
58
- expect(invoke).to eq(0)
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,164 +0,0 @@
1
- require 'spec_helper'
2
- require 'conjur/command/variables'
3
-
4
- describe Conjur::Command::Variables, :logged_in => true do
5
- let (:variable) { double(:name => 'foo') }
6
- let (:incompatible_server_msg) { /not supported/ }
7
-
8
- context "expiring a variable" do
9
-
10
- let (:duration) { nil }
11
-
12
- context "with valid arguments" do
13
- before do
14
- expect(RestClient::Request).to receive(:execute).with({
15
- :method => :post,
16
- :url => 'https://core.example.com/api/variables/foo/expiration',
17
- :headers => {},
18
- :payload => {:duration => duration}
19
- }).and_return(double('response', :body => '{}'))
20
- end
21
-
22
- shared_examples 'it sets variable expiration' do
23
- it do
24
- expect {invoke}.to write
25
- end
26
- end
27
-
28
- describe_command 'variable:expire --now foo' do
29
- let (:duration) { 'P0Y' }
30
- it_behaves_like 'it sets variable expiration'
31
- end
32
-
33
- describe_command 'variable:expire --days 1 foo' do
34
- let (:duration) { 'P1D' }
35
- it_behaves_like 'it sets variable expiration'
36
- end
37
-
38
- describe_command 'variable:expire --months 1 foo' do
39
- let (:duration) { 'P1M' }
40
- it_behaves_like 'it sets variable expiration'
41
- end
42
-
43
- describe_command 'variable:expire --in PT1M foo' do
44
- let (:duration) { 'PT1M' }
45
- it_behaves_like 'it sets variable expiration'
46
- end
47
-
48
- end
49
-
50
- describe_command 'variable:expire --now --days 1 foo' do
51
- it "fails" do
52
- expect { invoke_silently }.to raise_error GLI::CustomExit
53
- end
54
-
55
- end
56
-
57
- describe_command 'variable:expire' do
58
- it 'should fail' do
59
- expect { invoke_silently }.to raise_error RuntimeError
60
- end
61
- end
62
-
63
- end
64
-
65
- context "getting variable expirations" do
66
- context "with valid arguments" do
67
- let (:expected_params) { nil }
68
- let (:expected_headers) { {}.tap {|h| h.merge!(:params => expected_params) if expected_params} }
69
- before do
70
- expect(RestClient::Request).to receive(:execute).with({
71
- :method => :get,
72
- :url => 'https://core.example.com/api/variables/expirations',
73
- :headers => expected_headers
74
- }).and_return(double('response', :body => '[]'))
75
- end
76
-
77
- shared_examples 'it writes expiration list' do
78
- it do
79
- expect { invoke }.to write "[\n\n]\n"
80
- end
81
- end
82
-
83
- describe_command 'variable:expirations' do
84
- it_behaves_like 'it writes expiration list'
85
- end
86
-
87
- describe_command 'variable:expirations --days 1' do
88
- let (:expected_params) { { :duration => 'P1D' } }
89
- it_behaves_like 'it writes expiration list'
90
- end
91
-
92
- describe_command 'variable:expirations --months 1' do
93
- let (:expected_params) { { :duration => 'P1M' } }
94
- it_behaves_like 'it writes expiration list'
95
- end
96
-
97
- describe_command 'variable:expirations --in P1D' do
98
- let (:expected_params) { { :duration => 'P1D' } }
99
- it_behaves_like 'it writes expiration list'
100
- end
101
-
102
- end
103
- end
104
-
105
- let(:certificate) do
106
- OpenSSL::X509::Certificate.new.tap do |cert|
107
- key = OpenSSL::PKey::RSA.new 512
108
- cert.public_key = key.public_key
109
- cert.not_before = Time.now
110
- cert.not_after = 1.minute.from_now
111
- cert.sign key, OpenSSL::Digest::SHA256.new
112
- end
113
- end
114
-
115
- let(:certfile) do
116
- Tempfile.new("cert").tap do |file|
117
- file.write certificate.to_pem
118
- file.close
119
- end
120
- end
121
-
122
- context 'connecting to incompatible server version while' do
123
- before do
124
- allow(Conjur.config).to receive_messages \
125
- cert_file: certfile.path,
126
- appliance_url: core_host
127
-
128
- expect(RestClient::Request).to receive(:execute).with({
129
- :method => :get,
130
- :url => "https://core.example.com/info",
131
- :headers => {}
132
- }).and_raise(RestClient::ResourceNotFound)
133
- end
134
-
135
- context 'setting variable expiration' do
136
- describe_command 'variable:expire --days 1 foo' do
137
- it 'should display error message' do
138
- expect(RestClient::Request).to receive(:execute).with({
139
- :method => :post,
140
- :url => "https://core.example.com/api/variables/foo/expiration",
141
- :headers => {},
142
- :payload => anything
143
- }).and_raise(RestClient::ResourceNotFound)
144
- expect { invoke }.to raise_error(RestClient::ResourceNotFound)
145
- .and write(incompatible_server_msg).to(:stderr)
146
- end
147
- end
148
- end
149
-
150
- context 'getting variable expirations' do
151
- describe_command 'variable:expirations' do
152
- it 'should display error message' do
153
- expect(RestClient::Request).to receive(:execute).with({
154
- :method => :get,
155
- :url => 'https://core.example.com/api/variables/expirations',
156
- :headers => {}
157
- }).and_raise(RestClient::ResourceNotFound)
158
- expect { invoke }.to raise_error(RestClient::ResourceNotFound)
159
- .and write(incompatible_server_msg).to(:stderr)
160
- end
161
- end
162
- end
163
- end
164
- end