From df4472acf6601eaa16ef8b8da9f346f5f0b966fc Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Tue, 7 Nov 2023 15:02:30 +0100 Subject: [PATCH] debug: authorized-keys --- pkg/users/authorized-keys-panel.js | 1 + pkg/users/authorized-keys.js | 3 + test/run | 2 +- test/verify/check-shell-keys | 905 +++++++++++++++++++++++++++++ 4 files changed, 910 insertions(+), 1 deletion(-) diff --git a/pkg/users/authorized-keys-panel.js b/pkg/users/authorized-keys-panel.js index 6cbe09330b6b..9c0028d2a3c0 100644 --- a/pkg/users/authorized-keys-panel.js +++ b/pkg/users/authorized-keys-panel.js @@ -68,6 +68,7 @@ function add_authorized_key_dialog(keys) { caption: _("Add"), style: "primary", clicked: () => { + console.log("adding key", state.text); return keys.add_key(state.text); } } diff --git a/pkg/users/authorized-keys.js b/pkg/users/authorized-keys.js index 1debf0cb786e..b3f7f011625e 100644 --- a/pkg/users/authorized-keys.js +++ b/pkg/users/authorized-keys.js @@ -99,6 +99,7 @@ function AuthorizedKeys (user_name, home_dir) { } self.add_key = function(key) { + console.log("adding key", key); return parse_pubkeys(key) .then(keys => { const obj = keys[0]; @@ -109,6 +110,8 @@ function AuthorizedKeys (user_name, home_dir) { // eslint-disable-next-line prefer-promise-reject-errors .catch(ex => Promise.reject(_("Error saving authorized keys: ") + ex)); // not-covered: OS error } else { + console.log("objects", keys); + console.log("key", key); return Promise.reject(_("The key you provided was not valid.")); } }); diff --git a/test/run b/test/run index f601b980c6bf..71b063089114 100755 --- a/test/run +++ b/test/run @@ -60,7 +60,7 @@ case "${TEST_SCENARIO:=}" in PREPARE_OPTS="$PREPARE_OPTS --quick" ;;& *other*) - RUN_OPTS="$RUN_OPTS $(echo "$ALL_TESTS" | grep -Ev "$RE_NETWORKING|$RE_STORAGE|$RE_EXPENSIVE")" + RUN_OPTS="$RUN_OPTS TestKeys.testAuthorizedKeys" ;;& esac diff --git a/test/verify/check-shell-keys b/test/verify/check-shell-keys index edc1bdd64126..29080e482507 100755 --- a/test/verify/check-shell-keys +++ b/test/verify/check-shell-keys @@ -26,6 +26,910 @@ KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEAkRTvQCSEZNPXpA5bP82ilQn3TMeQ6z2NO3 @testlib.skipDistroPackage() @testlib.nondestructive class TestKeys(testlib.MachineCase): + + def testAuthorizedKeys11(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys12(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys13(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys14(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys15(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys16(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys17(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys18(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys19(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys20(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys30(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys40(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys9(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys8(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys7(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys6(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys5(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys4(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys3(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys2(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + + def testAuthorizedKeys1(self): + m = self.machine + b = self.browser + + # Create a user without any role + m.execute("useradd user -s /bin/bash -m -c User") + m.execute("echo user:foobar | chpasswd") + + def login(user): + self.login_and_go("/users#/" + user, user=user, superuser=False) + b.wait_text("#account-user-name", user) + + def add_key(key, fp_sh256, comment): + print(key, fp_sh256, comment) + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", key) + b.click("#add-authorized-key-dialog button.apply") + b.wait_not_present("#add-authorized-key-dialog") + + b.wait_in_text("#account-authorized-keys-list", comment) + + b.wait_not_in_text("#account-authorized-keys-list", "no authorized public keys") + text = b.text("#account-authorized-keys-list") + self.assertIn(fp_sh256, text) + + # no keys + login("user") + b.wait_in_text("#account-authorized-keys", "no authorized public keys") + + # add bad + b.click('#authorized-key-add') + b.wait_visible("#add-authorized-key-dialog") + b.wait_val("#authorized-keys-text", "") + b.set_input_text("#authorized-keys-text", "bad") + b.click("#add-authorized-key-dialog button.apply") + b.wait_in_text("#add-authorized-key-dialog", "The key you provided was not valid") + b.click("#add-authorized-key-dialog button.cancel") + + # add good + add_key(KEY, FP_SHA256, "test-name") + def testAuthorizedKeys(self): m = self.machine b = self.browser @@ -39,6 +943,7 @@ class TestKeys(testlib.MachineCase): b.wait_text("#account-user-name", user) def add_key(key, fp_sh256, comment): + print("add_key", key, fp_sh256, comment) b.click('#authorized-key-add') b.wait_visible("#add-authorized-key-dialog") b.wait_val("#authorized-keys-text", "")