Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect error message when password is expired #616

Merged
merged 5 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions lib/train/platforms/detect/helpers/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,24 @@ def unix_file_exist?(path)
end

def command_output(cmd)
res = @backend.run_command(cmd).stdout
res = @backend.run_command(cmd)
stdout = res.stdout
stderr = res.stderr
# When you try to execute command using ssh connction as root user and you have provided ssh user identity file
# it gives standard output to login as authorised user other than root. To show this standard ouput as an error
# to user we are matching the string of stdout and raising the error here so that user gets exact information.
if @backend.class.to_s == "Train::Transports::SSH::Connection" && res =~ /Please login as the user/
raise Train::UserError, "SSH failed: #{res}"
if @backend.class.to_s == "Train::Transports::SSH::Connection"
if stdout =~ /Please login as the user/
raise Train::UserError, "SSH failed: #{stdout}"
end

if stderr =~ /WARNING: Your password has expired/
raise Train::UserError, "SSH failed: #{stderr}"
end
end

res.strip! unless res.nil?
res
stdout.strip! unless stdout.nil?
stdout
end

def unix_uname_s
Expand Down
6 changes: 3 additions & 3 deletions test/unit/platforms/detect/os_common_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ def initialize
describe "#detect_linux_arch" do
it "uname m call" do
be = mock("Backend")
be.stubs(:run_command).with("uname -m").returns(mock("Output", stdout: "x86_64\n"))
be.stubs(:run_command).with("uname -m").returns(mock("Output", stdout: "x86_64\n", stderr: ""))
detector.instance_variable_set(:@backend, be)
detector.instance_variable_set(:@uname, {})
_(detector.unix_uname_m).must_equal("x86_64")
end

it "uname s call" do
be = mock("Backend")
be.stubs(:run_command).with("uname -s").returns(mock("Output", stdout: "linux"))
be.stubs(:run_command).with("uname -s").returns(mock("Output", stdout: "linux", stderr: ""))
detector.instance_variable_set(:@backend, be)
detector.instance_variable_set(:@uname, {})
_(detector.unix_uname_s).must_equal("linux")
end

it "uname r call" do
be = mock("Backend")
be.stubs(:run_command).with("uname -r").returns(mock("Output", stdout: "17.0.0\n"))
be.stubs(:run_command).with("uname -r").returns(mock("Output", stdout: "17.0.0\n", stderr: ""))
detector.instance_variable_set(:@backend, be)
detector.instance_variable_set(:@uname, {})
_(detector.unix_uname_r).must_equal("17.0.0")
Expand Down