Skip to content

Commit

Permalink
static: Handle no-cockpit error
Browse files Browse the repository at this point in the history
When directly logging into a remote host without cockpit installed, the
login page showed an unhelpful and untranslatable fatal error message:

> Authentication failed: no-cockpit: [Errno 2] No such file or directory

This also left the user with nothing actionable other than reloading the
page.

Handle the "no-cockpit" problem code and show a proper error message.
Use the exact same one as in the shell's host switcher, to avoid
introducing another similar translatable string. This also goes back to
the login form, to either choose another host, or reattempt the login
after installing cockpit on the target.
  • Loading branch information
martinpitt committed Oct 17, 2024
1 parent fe19608 commit c7fddca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg/static/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,8 @@ function debug(...args) {
}
} else if (xhr.status == 403) {
login_failure(_(decodeURIComponent(xhr.statusText)) || _("Permission denied"));
} else if (xhr.status == 500 && xhr.statusText.indexOf("no-cockpit") > -1) {
login_failure(format(_("A compatible version of Cockpit is not installed on $0."), login_machine || "localhost"));
} else if (xhr.statusText) {
fatal(decodeURIComponent(xhr.statusText));
} else {
Expand Down
5 changes: 1 addition & 4 deletions test/verify/check-loopback
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ class TestLoopback(testlib.MachineCase):
b.set_val('#login-user-input', "admin")
b.set_val('#login-password-input', "foobar")
b.click('#login-button')
b.wait_visible('#login-fatal')
self.assertIn("no-cockpit", b.text('#login-fatal'))
b.wait_text("#login-error-message", "A compatible version of Cockpit is not installed on localhost.")

m.disconnect()
self.restore_dir("/etc/ssh", restart_unit=self.sshd_service)
m.execute("sed -i 's/.*PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config $(ls /etc/ssh/sshd_config.d/* 2>/dev/null || true)")
m.execute(self.restart_sshd)
m.wait_execute()

b.reload()
b.wait_visible("#login")
b.set_val('#login-user-input', "admin")
b.set_val('#login-password-input', "foobar")
b.click('#login-button')
Expand Down

0 comments on commit c7fddca

Please sign in to comment.