Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deal with missing FOG_RC/HOME env vars better

  • Loading branch information...
commit 8dfc9beb0d40754a36faf4808eda2cda5d97337c 1 parent 27b2455
@outerim authored
Showing with 40 additions and 1 deletion.
  1. +4 −1 lib/fog/core/credentials.rb
  2. +36 −0 tests/core/credential_tests.rb
View
5 lib/fog/core/credentials.rb
@@ -18,7 +18,10 @@ def self.credential
# @return [String] The path for configuration_file
def self.credentials_path
- @credential_path ||= File.expand_path(ENV["FOG_RC"] || (ENV['HOME'] && '~/.fog'))
+ @credential_path ||= begin
+ path = ENV["FOG_RC"] || (ENV['HOME'] && '~/.fog')
+ File.expand_path(path) if path
+ end
end
# @return [String] The new path for credentials file
View
36 tests/core/credential_tests.rb
@@ -0,0 +1,36 @@
+Shindo.tests do
+ before do
+ @old_home = ENV['HOME']
+ @old_rc = ENV['FOG_RC']
+ Fog.instance_variable_set('@credential_path', nil) # kill memoization
+ end
+
+ after do
+ ENV['HOME'] = @old_home
+ ENV['FOG_RC'] = @ld_rc
+ end
+
+ tests('credentials_path') do
+ returns('/rc/path', 'FOG_RC takes precedence over HOME') {
+ ENV['HOME'] = '/home/path'
+ ENV['FOG_RC'] = '/rc/path'
+ }
+
+ returns('/expanded/path', 'properly expands paths') {
+ ENV['FOG_RC'] = '/expanded/subdirectory/../path'
+ Fog.credentials_path
+ }
+
+ returns('/home/me/.fog', 'falls back to home path if FOG_RC not set') {
+ ENV['HOME'] = '/home/me'
+ ENV.delete('FOG_RC')
+ Fog.credentials_path
+ }
+
+ returns(nil, 'returns nil when neither FOG_RC or HOME are set') {
+ ENV.delete('HOME')
+ ENV.delete('FOG_RC')
+ Fog.credentials_path
+ }
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.