spec/command/init_spec.rb in conjur-cli-5.6.6 vs spec/command/init_spec.rb in conjur-cli-6.0.0.rc1
- old
+ new
@@ -47,19 +47,19 @@
allow(File).to receive(:exists?).and_return false
}
context "auto-fetching fingerprint" do
before {
- allow_any_instance_of(HighLine).to receive(:ask).with("Enter the hostname (and optional port) of your Conjur endpoint: ").and_return "the-host"
+ allow_any_instance_of(HighLine).to receive(:ask).with("Enter the URL of your Conjur service: ").and_return "http://host.example.com"
allow(Conjur::Command::Init).to receive_messages get_certificate: ["the-fingerprint", nil]
allow_any_instance_of(HighLine).to receive(:ask).with(/^Trust this certificate/).and_return "yes"
}
describe_command 'init' do
- it "fetches account and writes config file" do
- # Stub hostname
- expect(Conjur::Core::API).to receive(:info).and_return "account" => "the-account"
+ it "writes config file" do
+ expect_any_instance_of(HighLine).to receive(:ask).with("Enter the URL of your Conjur service: ").and_return "http://host.example.com"
+ expect_any_instance_of(HighLine).to receive(:ask).with("Enter your organization account name: ").and_return "the-account"
expect(File).to receive(:open)
invoke
end
end
@@ -69,17 +69,22 @@
invoke
end
end
end
- describe_command 'init -a the-account -h foobar' do
+ describe_command 'init -a the-account -u https://nohost.example.com' do
it "can't get the cert" do
+ # GLI only raises CustomExit if GLI_DEBUG is set
+ ENV['GLI_DEBUG'] = 'true'
+
+ expect(TCPSocket).to receive(:new).and_raise "can't connect"
+
expect { invoke }.to raise_error(GLI::CustomExit, /unable to retrieve certificate/i)
end
end
- describe_command 'init -a the-account -h localhost -c the-cert' do
+ describe_command 'init -a the-account -u https://localhost -c the-cert' do
it "writes config and cert files" do
expect(File).to receive(:open).twice
expect(Conjur::Command::Init).to receive(:configure_cert_store).with "the-cert"
invoke
end
@@ -105,19 +110,19 @@
it "writes config and cert files" do
invoke
expect(YAML.load(File.read(file))).to eq({
account: 'the-account',
- appliance_url: "https://localhost/api",
+ appliance_url: "https://localhost",
cert_file: File.join(File.dirname(file), "conjur-the-account.pem"),
plugins: [],
}.stringify_keys)
end
end
context "default behavior" do
- describe_command "init -a the-account -h localhost -c the-cert" do
+ describe_command "init -a the-account -u https://localhost -c the-cert" do
before(:each) {
allow(File).to receive(:expand_path).and_call_original
allow(File).to receive(:expand_path).with('~/.conjurrc').and_return("#{tmpdir}/.conjurrc")
}
@@ -130,26 +135,26 @@
end
end
end
context "explicit output file" do
- describe_command "init -f #{tmpdir}/.conjurrc2 -a the-account -h localhost -c the-cert" do
+ describe_command "init -f #{tmpdir}/.conjurrc2 -a the-account -u https://localhost -c the-cert" do
include_examples "check config and cert files", File.join(tmpdir, ".conjurrc2")
it "prints the config file location" do
expect { invoke }.to write("Wrote configuration to #{tmpdir}/.conjurrc2")
end
end
end
context "to CONJURRC" do
- describe_command "init -a the-account -h localhost -c the-cert" do
+ describe_command "init -a the-account -u https://localhost -c the-cert" do
file = File.join(tmpdir, ".conjurrc_env")
include_examples "check config and cert files", file, file
end
end
context "explicit output file overrides CONJURRC" do
- describe_command "init -f #{tmpdir}/.conjurrc_2 -a the-account -h localhost -c the-cert" do
+ describe_command "init -f #{tmpdir}/.conjurrc_2 -a the-account -u https://localhost -c the-cert" do
ENV['CONJURRC'] = "#{tmpdir}/.conjurrc_env_2"
include_examples "check config and cert files", File.join(tmpdir, ".conjurrc_2")
end
end
end