conjur-cli 6.1.0 → 6.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +10 -0
- data/.github/ISSUE_TEMPLATE/bug.md +42 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +27 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +21 -0
- data/.gitleaks.toml +216 -0
- data/CHANGELOG.md +69 -209
- data/CONTRIBUTING.md +81 -0
- data/Jenkinsfile +83 -40
- data/LICENSE +202 -0
- data/NOTICES.txt +421 -0
- data/README.md +278 -48
- data/Rakefile +0 -1
- data/SECURITY.md +42 -0
- data/VERSION +1 -1
- data/bin/conjur +3 -1
- data/bin/parse-changelog.sh +12 -0
- data/build-standalone +42 -3
- data/ci/cli-test.sh +5 -1
- data/ci/submit-coverage +36 -0
- data/ci/test.sh +1 -1
- data/conjur-cli.gemspec +15 -13
- data/dev/docker-compose.yml +1 -0
- data/dev/start.sh +3 -3
- data/docker-compose.yml +2 -1
- data/features/authorization/resource/check.feature +6 -0
- data/features/authorization/resource/exists.feature +10 -3
- data/features/hostfactory/tokens.feature +1 -1
- data/features/pubkeys/show.feature +0 -4
- data/features/step_definitions/authn_steps.rb +1 -1
- data/features/step_definitions/cli_steps.rb +0 -19
- data/features/step_definitions/overrides.rb +3 -5
- data/features/support/env.rb +3 -1
- data/features/support/hooks.rb +0 -11
- data/jenkins.sh +1 -1
- data/lib/conjur/cli.rb +4 -3
- data/lib/conjur/command/hosts.rb +1 -1
- data/lib/conjur/command/ldap_sync.rb +37 -0
- data/lib/conjur/command/rspec/describe_command.rb +26 -7
- data/lib/conjur/command/rspec/mock_services.rb +7 -1
- data/lib/conjur/command/users.rb +5 -1
- data/lib/conjur/version.rb +1 -1
- data/needs-publishing +28 -0
- data/push-image +46 -28
- data/spec/authn_spec.rb +4 -4
- data/spec/command/authn_spec.rb +2 -2
- data/spec/command/hosts_spec.rb +26 -3
- data/spec/command/init_spec.rb +28 -28
- data/spec/command/ldap_sync_spec.rb +38 -0
- data/spec/command/users_spec.rb +18 -2
- data/spec/spec_helper.rb +5 -2
- data/test.sh +6 -1
- metadata +80 -77
- data/LICENSE.md +0 -195
data/lib/conjur/command/hosts.rb
CHANGED
@@ -36,7 +36,7 @@ class Conjur::Command::Hosts < Conjur::Command
|
|
36
36
|
host_resourceid = full_resource_id("host:#{host}")
|
37
37
|
|
38
38
|
unless api.resource(host_resourceid).exists?
|
39
|
-
exit_now! "
|
39
|
+
exit_now! "Host '#{host}' not found"
|
40
40
|
end
|
41
41
|
|
42
42
|
# Prepend 'host/' if it wasn't passed in
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'conjur/command'
|
2
|
+
|
3
|
+
class Conjur::Command::LDAPSync < Conjur::Command
|
4
|
+
desc 'LDAP sync management commands'
|
5
|
+
command :'ldap-sync' do |cgrp|
|
6
|
+
|
7
|
+
cgrp.desc 'Manage the policy used to sync Conjur and the LDAP server'
|
8
|
+
cgrp.command :policy do |policy|
|
9
|
+
|
10
|
+
policy.desc 'Show the current policy'
|
11
|
+
policy.command :show do |show|
|
12
|
+
|
13
|
+
show.desc 'LDAP Sync profile to use (defined in UI)'
|
14
|
+
show.arg_name 'profile'
|
15
|
+
show.flag ['p', 'profile'], default_value: 'default'
|
16
|
+
|
17
|
+
show.action do |_,options,_|
|
18
|
+
begin
|
19
|
+
resp = api.ldap_sync_policy(config_name: options[:profile])
|
20
|
+
|
21
|
+
if (policy = resp['policy'])
|
22
|
+
if resp['ok']
|
23
|
+
puts(policy)
|
24
|
+
else
|
25
|
+
exit_now! 'Failed creating the policy.'
|
26
|
+
end
|
27
|
+
else
|
28
|
+
exit_now! resp['error']['message']
|
29
|
+
end
|
30
|
+
rescue RestClient::ResourceNotFound => ex
|
31
|
+
exit_now! "LDAP sync is not supported by the server #{Conjur.configuration.appliance_url}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -5,15 +5,34 @@ RSpec::Core::DSL.change_global_dsl do
|
|
5
5
|
|
6
6
|
before do
|
7
7
|
allow(cert_store).to receive(:add_file)
|
8
|
+
# Stub the constant OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE which is
|
9
|
+
# implicitly used in many places in the CLI and in conjur-api-ruby as the de facto
|
10
|
+
# cert store.
|
8
11
|
stub_const 'OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE', cert_store
|
12
|
+
|
13
|
+
# Reset the rest_client_options defaults to avoid using expired rspec doubles.
|
14
|
+
#
|
15
|
+
# Conjur.configuration is a lazy-loaded singleton. There is single CLI instance
|
16
|
+
# shared across this test suite. When Conjur.configuration is loaded for the first
|
17
|
+
# time it assumes the defaults value for Conjur.configuration.rest_client_options
|
18
|
+
# of:
|
19
|
+
# {
|
20
|
+
# :ssl_cert_store => OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE
|
21
|
+
# }
|
22
|
+
#
|
23
|
+
# Notice above that each test case stubs the constant
|
24
|
+
# OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE with a double. Without further
|
25
|
+
# modification this means the first time the CLI is run and Conjur.configuration
|
26
|
+
# is loaded Conjur.configuration.rest_client_options[:ssl_cert_store] it is set to
|
27
|
+
# the double associated with the test case at that point in time. Since
|
28
|
+
# Conjur.configuration is only loaded once, without modification, that double will
|
29
|
+
# be retained and its usage will result in a RSpec::Mocks::ExpiredTestDoubleError.
|
30
|
+
# To avoid this for each test case we must reset
|
31
|
+
# Conjur.configuration.rest_client_options[:ssl_cert_store] with the double for
|
32
|
+
# the current test case.
|
33
|
+
Conjur.configuration.rest_client_options[:ssl_cert_store] = cert_store
|
9
34
|
end
|
10
|
-
|
11
|
-
let(:cert_store_options) do
|
12
|
-
{
|
13
|
-
ssl_cert_store: cert_store
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
35
|
+
|
17
36
|
let(:invoke) do
|
18
37
|
Conjur::CLI.error_device = $stderr
|
19
38
|
# TODO: allow proper handling of description like "audit:send 'hello world'"
|
@@ -29,7 +29,13 @@ end
|
|
29
29
|
shared_context "when logged in", logged_in: true do
|
30
30
|
include_context "with mock authn"
|
31
31
|
before do
|
32
|
-
allow(api).to receive(:credentials)
|
32
|
+
allow(api).to receive(:credentials) do
|
33
|
+
{
|
34
|
+
:username => 'dknuth',
|
35
|
+
:headers => { :authorization => "fakeauth" },
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
33
39
|
netrc[authn_host] = [username, api_key]
|
34
40
|
allow(Conjur::Command).to receive_messages api: api
|
35
41
|
end
|
data/lib/conjur/command/users.rb
CHANGED
@@ -47,7 +47,11 @@ class Conjur::Command::Users < Conjur::Command
|
|
47
47
|
if api.username == options[:user]
|
48
48
|
exit_now! 'To rotate the API key of the currently logged-in user, use this command without any flags or options'
|
49
49
|
end
|
50
|
-
|
50
|
+
user_resource_id = [Conjur.configuration.account, "user", options[:user]].join(":")
|
51
|
+
unless api.resource(user_resource_id).exists?
|
52
|
+
exit_now! "User '#{options[:user]}' not found"
|
53
|
+
end
|
54
|
+
puts api.resource(user_resource_id).rotate_api_key
|
51
55
|
else
|
52
56
|
username, password = Conjur::Authn.read_credentials
|
53
57
|
new_api_key = Conjur::API.rotate_api_key username, password
|
data/lib/conjur/version.rb
CHANGED
data/needs-publishing
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/bin/bash -ex
|
2
|
+
|
3
|
+
echo "Determining if publishing is requested..."
|
4
|
+
|
5
|
+
VERSION=$(ruby -I lib -r conjur/version -e 'puts Conjur::VERSION')
|
6
|
+
echo Declared version: $VERSION
|
7
|
+
|
8
|
+
if curl -s https://rubygems.org/api/v1/versions/conjur-cli.json | jq -e ".[] | select(.number == \"$VERSION\")" >/dev/null; then
|
9
|
+
echo "Found $VERSION on rubygems, not republishing"
|
10
|
+
exit 1
|
11
|
+
fi
|
12
|
+
|
13
|
+
# Jenkins git plugin is broken and always fetches with `--no-tags`
|
14
|
+
# (or `--tags`, neither of which is what you want), so tags end up
|
15
|
+
# not being fetched. Try to fix that.
|
16
|
+
# (Unfortunately this fetches all remote heads, so we may have to find
|
17
|
+
# another solution for bigger repos.)
|
18
|
+
git fetch -q
|
19
|
+
|
20
|
+
# note when tag not found git rev-parse will just print its name
|
21
|
+
# TAG=`git rev-parse tags/v$VERSION 2>/dev/null || :`
|
22
|
+
TAG=`git rev-list -n 1 "v$VERSION" 2>/dev/null || :`
|
23
|
+
echo Tag v$VERSION: $TAG
|
24
|
+
|
25
|
+
HEAD=`git rev-parse HEAD`
|
26
|
+
echo HEAD: $HEAD
|
27
|
+
|
28
|
+
test "$HEAD" = "$TAG"
|
data/push-image
CHANGED
@@ -1,28 +1,46 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
readonly REGISTRY="cyberark"
|
6
|
+
readonly INTERNAL_REGISTRY="registry2.itci.conjur.net"
|
7
|
+
readonly VERSION="$(cat VERSION)"
|
8
|
+
readonly VERSION_TAG="5-${VERSION}"
|
9
|
+
readonly image_name="conjur-cli"
|
10
|
+
readonly full_image_name="${REGISTRY}/${image_name}:latest"
|
11
|
+
|
12
|
+
readonly TAGS=(
|
13
|
+
"5"
|
14
|
+
"5-latest"
|
15
|
+
"$VERSION_TAG"
|
16
|
+
)
|
17
|
+
|
18
|
+
# fetching tags is required for git_description to work
|
19
|
+
git fetch --tags
|
20
|
+
git_description=$(git describe)
|
21
|
+
|
22
|
+
# if it’s not a tagged commit, VERSION will have extra junk (i.e. -g666c4b2), so we won’t publish that commit
|
23
|
+
# only when tag matches the VERSION, push VERSION and latest releases
|
24
|
+
# and x and x.y releases
|
25
|
+
#Ex: v5-6.2.1
|
26
|
+
if [ "${git_description}" = "v${VERSION}" ]; then
|
27
|
+
echo "Revision ${git_description} matches version ${VERSION} exactly. Pushing to Dockerhub..."
|
28
|
+
|
29
|
+
for tag in "${TAGS[@]}"; do
|
30
|
+
echo "Tagging and pushing ${REGISTRY}/${image_name}:${tag}"
|
31
|
+
|
32
|
+
# push to dockerhub
|
33
|
+
docker tag "${full_image_name}" "${REGISTRY}/${image_name}:${tag}"
|
34
|
+
docker push "${REGISTRY}/${image_name}:${tag}"
|
35
|
+
|
36
|
+
# push to internal registry
|
37
|
+
# necessary because some cyberark teams/networks can't pull from dockerhub
|
38
|
+
docker tag "${full_image_name}" "${INTERNAL_REGISTRY}/${image_name}:${tag}"
|
39
|
+
docker push "${INTERNAL_REGISTRY}/${image_name}:${tag}"
|
40
|
+
|
41
|
+
done
|
42
|
+
|
43
|
+
# push to legacy `conjurinc/cli5` tag
|
44
|
+
docker tag "${full_image_name}" conjurinc/cli5:latest
|
45
|
+
docker push conjurinc/cli5:latest
|
46
|
+
fi
|
data/spec/authn_spec.rb
CHANGED
@@ -37,11 +37,11 @@ describe Conjur::Authn do
|
|
37
37
|
allow(ENV).to receive(:[]).with("CONJUR_AUTHN_LOGIN").and_return "the-login"
|
38
38
|
allow(ENV).to receive(:[]).with("CONJUR_AUTHN_API_KEY").and_return "the-api-key"
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
context "login and API key" do
|
42
42
|
it "are used to authn" do
|
43
43
|
expect(Conjur::Authn.get_credentials).to eq([ "the-login", "the-api-key" ])
|
44
|
-
|
44
|
+
|
45
45
|
expect(api.username).to eq('the-login')
|
46
46
|
expect(api.api_key).to eq('the-api-key')
|
47
47
|
end
|
@@ -94,7 +94,7 @@ describe Conjur::Authn do
|
|
94
94
|
before do
|
95
95
|
allow(Conjur::Config).to receive(:[]).with(:netrc_path).and_return path
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
context "with specified netrc_path" do
|
99
99
|
let(:path) { "/a/dummy/netrc/path" }
|
100
100
|
it "consults Conjur::Config for netrc_path" do
|
@@ -102,7 +102,7 @@ describe Conjur::Authn do
|
|
102
102
|
expect(Conjur::Authn.netrc).to eq(netrc)
|
103
103
|
end
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
context "without specified netrc_path" do
|
107
107
|
let(:path) { nil }
|
108
108
|
it "uses default netrc path" do
|
data/spec/command/authn_spec.rb
CHANGED
@@ -10,14 +10,14 @@ describe Conjur::Command::Authn do
|
|
10
10
|
describe_command "#{cmd}" do
|
11
11
|
it "prompts for username and password and logs in the user" do
|
12
12
|
expect(Conjur::Authn).to receive(:ask_for_credentials).with({}).and_return [ "the-user", "the-api-key" ]
|
13
|
-
|
13
|
+
|
14
14
|
expect { invoke }.to write("Logged in")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
describe_command "#{cmd} -u the-user" do
|
18
18
|
it "prompts for password and logs in the user" do
|
19
19
|
expect(Conjur::Authn).to receive(:ask_for_credentials).with({username: 'the-user'}).and_return [ "the-user", "the-api-key" ]
|
20
|
-
|
20
|
+
|
21
21
|
expect { invoke }.to write("Logged in")
|
22
22
|
end
|
23
23
|
end
|
data/spec/command/hosts_spec.rb
CHANGED
@@ -9,13 +9,21 @@ describe Conjur::Command::Hosts, logged_in: true do
|
|
9
9
|
expect(RestClient::Request).to receive(:execute).with({
|
10
10
|
method: :head,
|
11
11
|
url: "https://core.example.com/api/resources/#{account}/host/redis001",
|
12
|
-
headers: {
|
12
|
+
headers: {
|
13
|
+
authorization: "fakeauth",
|
14
|
+
},
|
15
|
+
username: "dknuth",
|
16
|
+
ssl_cert_store: cert_store
|
13
17
|
}).and_return true
|
14
18
|
expect(RestClient::Request).to receive(:execute).with({
|
15
19
|
method: :put,
|
16
20
|
url: "https://core.example.com/api/authn/#{account}/api_key?role=#{account}:host:redis001",
|
17
|
-
headers: {
|
18
|
-
|
21
|
+
headers: {
|
22
|
+
authorization: "fakeauth",
|
23
|
+
},
|
24
|
+
payload: '',
|
25
|
+
username: "dknuth",
|
26
|
+
ssl_cert_store: cert_store
|
19
27
|
}).and_return double(:response, body: 'new api key')
|
20
28
|
end
|
21
29
|
|
@@ -23,5 +31,20 @@ describe Conjur::Command::Hosts, logged_in: true do
|
|
23
31
|
invoke
|
24
32
|
end
|
25
33
|
end
|
34
|
+
|
35
|
+
describe_command 'host rotate_api_key --host non-existing' do
|
36
|
+
before do
|
37
|
+
expect(RestClient::Request).to receive(:execute).with({
|
38
|
+
method: :head,
|
39
|
+
url: "https://core.example.com/api/resources/#{account}/host/non-existing",
|
40
|
+
headers: {authorization: "fakeauth"},
|
41
|
+
username: username,
|
42
|
+
ssl_cert_store: cert_store
|
43
|
+
}).and_raise RestClient::ResourceNotFound
|
44
|
+
end
|
45
|
+
it 'rotate_api_key with non-existing --host option' do
|
46
|
+
expect { invoke }.to raise_error(GLI::CustomExit, /Host 'non-existing' not found/i)
|
47
|
+
end
|
48
|
+
end
|
26
49
|
end
|
27
50
|
end
|
data/spec/command/init_spec.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'highline'
|
3
3
|
|
4
|
-
GITHUB_FP = "SHA1 Fingerprint=
|
4
|
+
GITHUB_FP = "SHA1 Fingerprint=84:63:B3:A9:29:12:CC:FD:1D:31:47:05:98:9B:EC:13:99:37:D0:D7"
|
5
5
|
GITHUB_CERT = <<EOF
|
6
6
|
-----BEGIN CERTIFICATE-----
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
/
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
7
|
+
MIIFBjCCBK2gAwIBAgIQDovzdw2S0Zbwu2H5PEFmvjAKBggqhkjOPQQDAjBnMQsw
|
8
|
+
CQYDVQQGEwJVUzEXMBUGA1UEChMORGlnaUNlcnQsIEluYy4xPzA9BgNVBAMTNkRp
|
9
|
+
Z2lDZXJ0IEhpZ2ggQXNzdXJhbmNlIFRMUyBIeWJyaWQgRUNDIFNIQTI1NiAyMDIw
|
10
|
+
IENBMTAeFw0yMTAzMjUwMDAwMDBaFw0yMjAzMzAyMzU5NTlaMGYxCzAJBgNVBAYT
|
11
|
+
AlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2Nv
|
12
|
+
MRUwEwYDVQQKEwxHaXRIdWIsIEluYy4xEzARBgNVBAMTCmdpdGh1Yi5jb20wWTAT
|
13
|
+
BgcqhkjOPQIBBggqhkjOPQMBBwNCAASt9vd1sdNJVApdEHG93CUGSyIcoiNOn6H+
|
14
|
+
udCMvTm8DCPHz5GmkFrYRasDE77BI3q5xMidR/aW4Ll2a1A2ZvcNo4IDOjCCAzYw
|
15
|
+
HwYDVR0jBBgwFoAUUGGmoNI1xBEqII0fD6xC8M0pz0swHQYDVR0OBBYEFCexfp+7
|
16
|
+
JplQ2PPDU1v+MRawux5yMCUGA1UdEQQeMByCCmdpdGh1Yi5jb22CDnd3dy5naXRo
|
17
|
+
dWIuY29tMA4GA1UdDwEB/wQEAwIHgDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYB
|
18
|
+
BQUHAwIwgbEGA1UdHwSBqTCBpjBRoE+gTYZLaHR0cDovL2NybDMuZGlnaWNlcnQu
|
19
|
+
Y29tL0RpZ2lDZXJ0SGlnaEFzc3VyYW5jZVRMU0h5YnJpZEVDQ1NIQTI1NjIwMjBD
|
20
|
+
QTEuY3JsMFGgT6BNhktodHRwOi8vY3JsNC5kaWdpY2VydC5jb20vRGlnaUNlcnRI
|
21
|
+
aWdoQXNzdXJhbmNlVExTSHlicmlkRUNDU0hBMjU2MjAyMENBMS5jcmwwPgYDVR0g
|
22
|
+
BDcwNTAzBgZngQwBAgIwKTAnBggrBgEFBQcCARYbaHR0cDovL3d3dy5kaWdpY2Vy
|
23
|
+
dC5jb20vQ1BTMIGSBggrBgEFBQcBAQSBhTCBgjAkBggrBgEFBQcwAYYYaHR0cDov
|
24
|
+
L29jc3AuZGlnaWNlcnQuY29tMFoGCCsGAQUFBzAChk5odHRwOi8vY2FjZXJ0cy5k
|
25
|
+
aWdpY2VydC5jb20vRGlnaUNlcnRIaWdoQXNzdXJhbmNlVExTSHlicmlkRUNDU0hB
|
26
|
+
MjU2MjAyMENBMS5jcnQwDAYDVR0TAQH/BAIwADCCAQUGCisGAQQB1nkCBAIEgfYE
|
27
|
+
gfMA8QB2ACl5vvCeOTkh8FZzn2Old+W+V32cYAr4+U1dJlwlXceEAAABeGq/vRoA
|
28
|
+
AAQDAEcwRQIhAJ7miER//DRFnDJNn6uUhgau3WMt4vVfY5dGigulOdjXAiBIVCfR
|
29
|
+
xjK1v4F31+sVaKzyyO7JAa0fzDQM7skQckSYWQB3ACJFRQdZVSRWlj+hL/H3bYbg
|
30
|
+
IyZjrcBLf13Gg1xu4g8CAAABeGq/vTkAAAQDAEgwRgIhAJgAEkoJQRivBlwo7x67
|
31
|
+
3oVsf1ip096WshZqmRCuL/JpAiEA3cX4rb3waLDLq4C48NSoUmcw56PwO/m2uwnQ
|
32
|
+
prb+yh0wCgYIKoZIzj0EAwIDRwAwRAIgK+Kv7G+/KkWkNZg3PcQFp866Z7G6soxo
|
33
|
+
a4etSZ+SRlYCIBSiXS20Wc+yjD111nPzvQUCfsP4+DKZ3K+2GKsERD6d
|
34
34
|
EOF
|
35
35
|
|
36
36
|
describe Conjur::Command::Init do
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conjur::Command::LDAPSync, logged_in: true do
|
4
|
+
let (:policy_response) { { 'ok' => true, 'events' => [], 'policy' => <<eop
|
5
|
+
"---
|
6
|
+
- !user
|
7
|
+
annotations:
|
8
|
+
ldap-sync/source: ldap-server:389
|
9
|
+
ldap-sync/upstream-dn: CN=Administrator,OU=functest,OU=testdata,OU=dev-ci,DC=dev-ci,DC=conjur
|
10
|
+
id: Administrator
|
11
|
+
uidnumber:"}
|
12
|
+
eop
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
describe_command "ldap-sync policy show" do
|
17
|
+
|
18
|
+
context "on a server that supports LDAP sync" do
|
19
|
+
before do
|
20
|
+
expect_any_instance_of(Conjur::API).to receive(:ldap_sync_policy).with(config_name: '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
|
+
context "on a server that doesn't support LDAP sync" do
|
29
|
+
before do
|
30
|
+
expect_any_instance_of(Conjur::API).to receive(:ldap_sync_policy).and_raise(RestClient::ResourceNotFound)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "shows an error message" do
|
34
|
+
expect {invoke}.to raise_error(GLI::CustomExit, /LDAP sync is not supported by the server/)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/command/users_spec.rb
CHANGED
@@ -12,7 +12,8 @@ describe Conjur::Command::Users, logged_in: true do
|
|
12
12
|
user: username,
|
13
13
|
password: api_key,
|
14
14
|
headers: { },
|
15
|
-
payload: "new-password"
|
15
|
+
payload: "new-password",
|
16
|
+
ssl_cert_store: cert_store
|
16
17
|
})
|
17
18
|
end
|
18
19
|
|
@@ -40,7 +41,8 @@ describe Conjur::Command::Users, logged_in: true do
|
|
40
41
|
user: username,
|
41
42
|
password: api_key,
|
42
43
|
headers: {},
|
43
|
-
payload: ''
|
44
|
+
payload: '',
|
45
|
+
ssl_cert_store: cert_store
|
44
46
|
}).and_return double(:response, body: 'new api key')
|
45
47
|
expect(Conjur::Authn).to receive(:save_credentials).with({
|
46
48
|
username: username,
|
@@ -52,5 +54,19 @@ describe Conjur::Command::Users, logged_in: true do
|
|
52
54
|
invoke
|
53
55
|
end
|
54
56
|
end
|
57
|
+
describe_command 'user rotate_api_key --user non-existing' do
|
58
|
+
before do
|
59
|
+
expect(RestClient::Request).to receive(:execute).with({
|
60
|
+
method: :head,
|
61
|
+
url: "https://core.example.com/api/resources/#{account}/user/non-existing",
|
62
|
+
headers: {authorization: "fakeauth"},
|
63
|
+
username: username,
|
64
|
+
ssl_cert_store: cert_store
|
65
|
+
}).and_raise RestClient::ResourceNotFound
|
66
|
+
end
|
67
|
+
it 'rotate_api_key with non-existing --user option' do
|
68
|
+
expect { invoke }.to raise_error(GLI::CustomExit, /User 'non-existing' not found/i)
|
69
|
+
end
|
70
|
+
end
|
55
71
|
end
|
56
72
|
end
|