Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
u3d/credentials: support empty passwords
Browse files Browse the repository at this point in the history
lacostej committed Sep 5, 2017
1 parent 26424fd commit 28d30df
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/u3d_core/credentials.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions spec/u3d_core/credentials_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 28d30df

Please sign in to comment.