Skip to content

Commit

Permalink
Merge pull request #125 from yrudman/do-not-allow-empty-password-for-db
Browse files Browse the repository at this point in the history
Do not allow to enter empty passwords when configuring DB
(cherry picked from commit 728afb6a4e41cd7ad0c695cb467aed5311cb2a8d)

https://bugzilla.redhat.com/show_bug.cgi?id=1468593
  • Loading branch information
carbonin authored and simaishi committed Jul 7, 2017
1 parent 680aa8b commit d923273
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
15 changes: 10 additions & 5 deletions gems/pending/appliance_console/database_configuration.rb
Expand Up @@ -118,17 +118,22 @@ def ask_for_database_credentials
self.username = just_ask("username", username) unless local?
count = 0
loop do
count += 1
password1 = ask_for_password_or_none("database password on #{host}", password)
password1 = ask_for_password("database password on #{host}", password)
# if they took the default, just bail
break if (password1 == password)
password2 = ask_for_password("database password again")

if password1.strip.length == 0
say("\nPassword can not be empty, please try again")
next
end
password2 = ask_for_password("database password again")
if password1 == password2
self.password = password1
break
elsif count > 1 # only reprompt password once
raise ArgumentError, "passwords did not match"
elsif count > 0 # only reprompt password once
raise RuntimeError, "passwords did not match"
else
count += 1
say("\nThe passwords did not match, please try again")
end
end
Expand Down
4 changes: 2 additions & 2 deletions gems/pending/appliance_console/database_replication.rb
Expand Up @@ -100,15 +100,15 @@ def ask_for_cluster_database_credentials
count = 0
loop do
count += 1
password1 = ask_for_password_or_none("cluster database password", database_password)
password1 = ask_for_password("cluster database password", database_password)
# if they took the default, just bail
break if password1 == database_password
password2 = ask_for_password("cluster database password")
if password1 == password2
self.database_password = password1
break
elsif count > 1 # only reprompt password once
raise ArgumentError, "passwords did not match"
raise RuntimeError, "passwords did not match"
else
say("\nThe passwords did not match, please try again")
end
Expand Down
Expand Up @@ -208,7 +208,14 @@ def say(*_args)
it "should raise an error if passwords do not match twice" do
expect(subject).to receive(:just_ask).with(/password/i, anything).twice.and_return(*%w(pass1 pass2 pass3 pass4))

expect { subject.ask_for_database_credentials }.to raise_error(ArgumentError, "passwords did not match")
expect { subject.ask_for_database_credentials }.to raise_error(RuntimeError, "passwords did not match")
end

it "does not allow empty password" do
expect(subject).to receive(:just_ask).and_return(" ")
expect(subject).to receive(:say).with("\nPassword can not be empty, please try again")
expect(subject).to receive(:loop).and_yield
subject.ask_for_database_credentials
end
end

Expand Down
Expand Up @@ -33,8 +33,7 @@
it "should store the newly supplied values" do
expect(subject).to receive(:just_ask).with(/ name/i, "defaultdatabasename").and_return("newdatabasename")
expect(subject).to receive(:just_ask).with(/ user/i, "defaultuser").and_return("newuser")
expect(subject).to receive(:ask_for_password_or_none).with(/password/i, nil).and_return("newpassword")
expect(subject).to receive(:ask_for_password).with(/password/i).and_return("newpassword")
expect(subject).to receive(:ask_for_password).with(/password/i, any_args).twice.and_return("newpassword")
expect(subject)
.to receive(:ask_for_ip_or_hostname).with(/primary.*hostname/i, "defaultprimary").and_return("newprimary")

Expand Down

0 comments on commit d923273

Please sign in to comment.