Skip to content

Commit

Permalink
Allow inputting ssh keys with an empty comment
Browse files Browse the repository at this point in the history
There is a test for adding an ssh key with an empty comment but that
includes a new line so it will be added successfully. When adding a key
manually it is in two parts as there is no comment included.

Closes #1298
  • Loading branch information
jelly committed Nov 10, 2023
1 parent 3e64bab commit c2c6f33
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/create-vm-dialog/createVmDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ const parseKey = debounce(500, (key, setKeyObject, setKeyInvalid) => {
.then(() => {
setKeyInvalid(false);
const parts = key.split(" ");
if (parts.length > 2) {
if (parts.length >= 2) {
setKeyObject({
type: parts[0],
data: parts[1],
Expand Down
10 changes: 2 additions & 8 deletions test/check-machines-create
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ class TestMachinesCreate(VirtualMachinesCase):
self.machine.execute("ssh-keygen -t rsa -N '' -f /tmp/rsakey")
rsakey = self.machine.execute("cat /tmp/rsakey.pub").strip()
self.addCleanup(self.machine.execute, "rm -f /tmp/rsakey*")
self.machine.execute("ssh-keygen -t dsa -N '' -C '' -f /tmp/dsakey") # public key with empty comment
self.machine.execute("ssh-keygen -t dsa -N '' -C '' -f /tmp/dsakey").strip() # public key with empty comment
dsakey = self.machine.execute("cat /tmp/dsakey.pub")
self.addCleanup(self.machine.execute, "rm -f /tmp/dsakey*")

# Try to create VM with one SSH key
# # Try to create VM with one SSH key
runner.createCloudBaseImageTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
storage_size=10, storage_size_unit='MiB',
location=config.VALID_DISK_IMAGE_PATH,
Expand Down Expand Up @@ -1153,8 +1153,6 @@ vnc_password= "{vnc_passwd}"

ssh_keys = self.expected_ssh_keys or self.ssh_keys
if ssh_keys is not None:
print("SSH KEYS", ssh_keys)
print(user_data)
for key in ssh_keys:
self.assertIn(key, user_data)

Expand Down Expand Up @@ -1321,16 +1319,12 @@ vnc_password= "{vnc_passwd}"
b.set_input_text("#create-vm-dialog-root-password-pw1", self.root_password)
if self.ssh_keys is not None:
for idx, key in enumerate(self.ssh_keys):
print(idx, key)
b.click("button:contains(Add SSH keys)")
b.set_input_text(f"#create-vm-dialog-ssh-key-{idx} textarea", key, value_check=False, blur=False)
import testlib
testlib.sit()
# Check that ssh key was validated
if self.ssh_key_invalid:
self.browser.wait_attr(f"#create-vm-dialog-ssh-key-{idx} .pf-v5-c-form__group", "testdata", "key-invalid")
else:
testlib.sit()
b.wait_visible(f"#create-vm-dialog-ssh-key-{idx} #validated")

if self.is_unattended:
Expand Down

0 comments on commit c2c6f33

Please sign in to comment.