From 28d30dff832f4ba2978d39c7d55fb9b13a5f479c Mon Sep 17 00:00:00 2001 From: Jerome Lacoste Date: Tue, 5 Sep 2017 23:14:03 +0200 Subject: [PATCH] u3d/credentials: support empty passwords --- lib/u3d_core/credentials.rb | 6 +++--- spec/u3d_core/credentials_spec.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/u3d_core/credentials.rb b/lib/u3d_core/credentials.rb index 003f1c7c..f2221449 100644 --- a/lib/u3d_core/credentials.rb +++ b/lib/u3d_core/credentials.rb @@ -56,7 +56,7 @@ def password end end - if @password.to_s.empty? + if @password.nil? UI.verbose 'Could not retrieve password' if U3dCore::Globals.do_not_login? UI.verbose 'Login disabled' @@ -73,8 +73,8 @@ def login raise CredentialsError, 'No username specified' unless user - while @password.to_s.empty? - UI.verbose 'Password does not exist or is empty' + while @password.nil? + UI.verbose 'Password does not exist' raise CredentialsError, 'Password missing and context is not interactive. Please make sure it is correct' unless UI.interactive? @password = UI.password "Password for #{user}:" end diff --git a/spec/u3d_core/credentials_spec.rb b/spec/u3d_core/credentials_spec.rb index 17c16f09..9606d2d2 100644 --- a/spec/u3d_core/credentials_spec.rb +++ b/spec/u3d_core/credentials_spec.rb @@ -32,6 +32,11 @@ expect(c.password).to eq(password) end + it "allows setting an empty password" do + c = U3dCore::Credentials.new(user: user, password: '') + expect(c.password).to eq('') + end + it "loads the user from the new 'U3D_USER' variable" do ENV['U3D_USER'] = user c = U3dCore::Credentials.new @@ -46,6 +51,13 @@ ENV.delete('U3D_PASSWORD') end + it "loads an empty password from the new 'U3D_PASSWORD' variable" do + ENV['U3D_PASSWORD'] = '' + c = U3dCore::Credentials.new + expect(c.password).to eq('') + ENV.delete('U3D_PASSWORD') + end + it "automatically loads the password from the keychain" do U3dCore::Globals.with_use_keychain(true) do ENV['U3D_USER'] = user