Skip to content

Commit

Permalink
Parse SSH public key with correct function. (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Nov 13, 2024
1 parent 0d83e33 commit b792d60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/service/machine-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ func validateAllocationSpec(allocationSpec *machineAllocationSpec) error {
for _, pubKey := range allocationSpec.SSHPubKeys {
_, _, _, _, err := ssh.ParseAuthorizedKey([]byte(pubKey))
if err != nil {
return fmt.Errorf("invalid public SSH key: %s", pubKey)
return fmt.Errorf("invalid public SSH key: %s error:%w", pubKey, err)
}
}

Expand Down
13 changes: 12 additions & 1 deletion cmd/metal-api/internal/service/machine-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,20 @@ func Test_validateAllocationSpec(t *testing.T) {
Role: metal.RoleMachine,
},
isError: true,
expected: `invalid public SSH key: 42`,
expected: `invalid public SSH key: 42 error:ssh: no key found`,
name: "invalid ssh",
},
{
spec: machineAllocationSpec{
UUID: "43",
Creator: testEmail,
ProjectID: "123",
SSHPubKeys: []string{"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBH9uyBvRBTUJFFAOKB/ZH/5Mm/MrqEDhkB4wTPWbJaJ5zHirBrLS1qk2Ut0yEL4vZvfnafnrzsed3n75/1BSmSg= [email protected]"},
Role: metal.RoleMachine,
},
isError: false,
name: "valid ssh",
},
{
spec: machineAllocationSpec{
UUID: "gopher-uuid",
Expand Down

0 comments on commit b792d60

Please sign in to comment.