Skip to content

Commit

Permalink
Print Conjur version only on server startup (#1590)
Browse files Browse the repository at this point in the history
* Print Conjur version only on server startup

The print that we added didn't print the version only
on server startup, and actually printed it for every `conjurctl`
command. This commit changes this behaviour so the message is
printed only on server startup.

* Add changelog entry for printing Conjur version

* Add cucumber test for conjurctl retrieve-key

* Revert to original environment after each cucumber test

Some test manipulate the env so we need to revert to the original
one after each scenario.

Co-authored-by: John Tuttle <[email protected]>
  • Loading branch information
orenbm and John Tuttle authored Jun 7, 2020
1 parent ce00a8e commit 90b7e97
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- The Conjur version is now printed on server startup, after running `conjurctl server`
([cyberark/conjur#1590](https://github.com/cyberark/conjur/pull/1590))

## [1.7.1] - 2020-06-03

Expand Down
5 changes: 0 additions & 5 deletions app/domain/logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ module Util
code: "CONJ00023D"
)

ConjurVersionStartup = ::Util::TrackableLogMessageClass.new(
msg: "Conjur v{0-conjur-version} starting up...",
code: "CONJ00037I"
)

end
end
end
3 changes: 3 additions & 0 deletions bin/conjur-cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def test_select
end

Process.fork do
conjur_version = File.read(File.expand_path("../VERSION", File.dirname(__FILE__))).strip
puts "Conjur v#{conjur_version} starting up..."

exec "rails server -p #{options[:port]} -b #{options[:'bind-address']}"
end
Process.fork do
Expand Down
2 changes: 0 additions & 2 deletions config/initializers/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
require 'logs'

ENV["CONJUR_VERSION_DISPLAY"] = File.read(File.expand_path("../../VERSION", File.dirname(__FILE__)))

Rails.logger.info(LogMessages::Util::ConjurVersionStartup.new(ENV["CONJUR_VERSION_DISPLAY"].strip))
13 changes: 13 additions & 0 deletions cucumber/_authenticators_common/features/support/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@
# share this code, and to it the api way (probably)
creds.password = 'SEcret12!!!!'
creds.save(raise_on_save_failure: true)

# Save env to revert to it after the test
@env = {}
ENV.each do |key, value|
@env[key] = value
end
end

After do
# Revert to original env
@env.each do |key, value|
ENV[key] = value
end
end
14 changes: 14 additions & 0 deletions cucumber/api/features/retrieve_api_key.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Retrieving an API key with conjurctl

Background:
# We need to be in production environment to test this to demonstrate a real use-case
Given I set environment variable "RAILS_ENV" to "production"
And I set environment variable "CONJUR_LOG_LEVEL" to "info"

Scenario: Retrieve an API key
When I retrieve an API key for user "cucumber:user:admin" using conjurctl
Then the API key is correct

Scenario: Retrieve an API key of a non-existing user fails
When I retrieve an API key for user "cucumber:user:non-existing-user" using conjurctl
Then the stderr includes the error "role does not exist"
14 changes: 14 additions & 0 deletions cucumber/api/features/step_definitions/conjurctl_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'open3'

When(/^I retrieve an API key for user "([^"]*)" using conjurctl$/) do |user_id|
command = "conjurctl role retrieve-key #{user_id}"
@conjurctl_stdout, @conjurctl_stderr, = Open3.capture3(command)
end

Then(/^the API key is correct$/) do
expect(@conjurctl_stdout).to eq("#{Credentials['cucumber:user:admin'].api_key}\n")
end

Then(/^the stderr includes the error "([^"]*)"$/) do |error|
expect(@conjurctl_stderr).to include(error)
end
5 changes: 5 additions & 0 deletions cucumber/api/features/step_definitions/environment_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

Given(/^I set environment variable "([^"]*)" to "([^"]*)"$/) do |variable_name, variable_value|
ENV[variable_name] = variable_value
end
11 changes: 11 additions & 0 deletions cucumber/api/features/support/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@
Account.find_or_create_accounts_resource
admin_role = Role.create(role_id: "cucumber:user:admin")
Credentials.new(role: admin_role).save(raise_on_save_failure: true)

# Save env to revert to it after the test
@env = {}
ENV.each do |key, value|
@env[key] = value
end
end

After do
FileUtils.remove_dir('cuke_export') if Dir.exists?('cuke_export')

# Revert to original env
@env.each do |key, value|
ENV[key] = value
end
end

Before("@logged-in") do
Expand Down
13 changes: 13 additions & 0 deletions cucumber/authenticators/features/support/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@
# this code, and to it the api way (probably)
creds.password = 'SEcret12!!!!'
creds.save(raise_on_save_failure: true)

# Save env to revert to it after the test
@env = {}
ENV.each do |key, value|
@env[key] = value
end
end

After do
# Revert to original env
@env.each do |key, value|
ENV[key] = value
end
end
13 changes: 13 additions & 0 deletions cucumber/policy/features/support/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,17 @@
# this code, and to it the api way (probably)
creds.password = 'SEcret12!!!!'
creds.save(raise_on_save_failure: true)

# Save env to revert to it after the test
@env = {}
ENV.each do |key, value|
@env[key] = value
end
end

After do
# Revert to original env
@env.each do |key, value|
ENV[key] = value
end
end

0 comments on commit 90b7e97

Please sign in to comment.