Skip to content

Commit

Permalink
Merge pull request #114 from imobach/fix-potential-id-collision
Browse files Browse the repository at this point in the history
Fix a potential Id collision on password widgets
  • Loading branch information
imobachgs committed Apr 27, 2015
2 parents 91683aa + ad72056 commit 80b10f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/include/autoinstall/ask.rb
Expand Up @@ -233,7 +233,7 @@ def askDialog
Ops.get_string(ask, "default", "")
)
widget2 = Password(
Id(:pass2), # FIXME: choose a better Id to avoid collisions
Id("#{entry_id}_pass2"),
Opt(:notify),
"",
Ops.get_string(ask, "default", "")
Expand Down Expand Up @@ -374,7 +374,7 @@ def askDialog
val = Builtins.tointeger(Convert.to_string(val))
end
if Ops.get_boolean(ask, "password", false) == true
pass2 = Convert.to_string(UI.QueryWidget(Id(:pass2), :Value))
pass2 = Convert.to_string(UI.QueryWidget(Id("#{entry_id}_pass2"), :Value))
if pass2 != Convert.to_string(val)
Popup.Error("The two passwords mismatch.")
runAgain = 1 # Run the same dialog again.
Expand Down
28 changes: 27 additions & 1 deletion test/include/ask_test.rb
Expand Up @@ -89,7 +89,7 @@ def initialize
with(Id("0_0"), Opt(:notify), ask["question"], ask["default"]).
and_call_original
expect(client).to receive(:Password).
with(Id(:pass2), Opt(:notify), "", ask["default"]).
with(Id("0_0_pass2"), Opt(:notify), "", ask["default"]).
and_call_original
client.askDialog
end
Expand Down Expand Up @@ -160,6 +160,21 @@ def initialize
client.askDialog
end
end

context "when ask-list contains more than one password question" do
let(:first_pass_ask) { BASE_ASK.merge("password" => true)}
let(:second_pass_ask) { BASE_ASK.merge("password" => true, "element" => 1)}
let(:ask_list) { [first_pass_ask, second_pass_ask] }

it "creates two password widgets for each question without repeating the Ids" do
expect(Yast::UI).to receive(:OpenDialog)
["0_0", "0_0_pass2", "0_1", "0_1_pass2"].each do |wid|
expect(client).to receive(:Password).
with(Id(wid), anything, anything, anything).and_call_original
end
client.askDialog
end
end
end

describe "dialogs actions" do
Expand Down Expand Up @@ -217,6 +232,17 @@ def initialize
client.askDialog
end
end

context "when asking for a 'password' and values don't match" do
let(:ask) { BASE_ASK.merge("password" => true) }

it "shows an error message and try run the dialog again" do
expect(Yast::UI).to receive(:QueryWidget).
with(Id("0_0_pass2"), :Value).and_return("some-other-thing", response)
expect(Yast::Popup).to receive(:Error).with("The two passwords mismatch.")
client.askDialog
end
end
end

context "when a script was specified" do
Expand Down

0 comments on commit 80b10f0

Please sign in to comment.