Skip to content

Commit

Permalink
fix(config): server config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 2, 2023
1 parent 3db817b commit 89e36f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,11 @@ func (c *Config) validate() error {
func parseAuthKeys(aks []string) []ssh.PublicKey {
pks := make([]ssh.PublicKey, 0)
for _, key := range aks {
var ak string
if bts, err := os.ReadFile(key); err == nil {
// key is a file
ak = strings.TrimSpace(string(bts))
key = strings.TrimSpace(string(bts))
}
if pk, _, err := backend.ParseAuthorizedKey(ak); err == nil {
if pk, _, err := backend.ParseAuthorizedKey(key); err == nil {
pks = append(pks, pk)
}
}
Expand Down
10 changes: 5 additions & 5 deletions server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func TestParseMultipleKeys(t *testing.T) {
})
cfg := DefaultConfig()
is.Equal(cfg.InitialAdminKeys, []string{
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINMwLvyV3ouVrTysUYGoJdl5Vgn5BACKov+n9PlzfPwH a@b",
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxIobhwtfdwN7m1TFt9wx3PsfvcAkISGPxmbmbauST8 a@b",
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINMwLvyV3ouVrTysUYGoJdl5Vgn5BACKov+n9PlzfPwH",
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxIobhwtfdwN7m1TFt9wx3PsfvcAkISGPxmbmbauST8",
})
}

Expand All @@ -39,8 +39,8 @@ func TestMergeInitAdminKeys(t *testing.T) {
cfg, err := ParseConfig(fp)
is.NoErr(err)
is.Equal(cfg.InitialAdminKeys, []string{
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINMwLvyV3ouVrTysUYGoJdl5Vgn5BACKov+n9PlzfPwH a@b",
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxIobhwtfdwN7m1TFt9wx3PsfvcAkISGPxmbmbauST8 a@b",
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINMwLvyV3ouVrTysUYGoJdl5Vgn5BACKov+n9PlzfPwH",
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxIobhwtfdwN7m1TFt9wx3PsfvcAkISGPxmbmbauST8",
})
}

Expand All @@ -60,6 +60,6 @@ func TestValidateInitAdminKeys(t *testing.T) {
cfg, err := ParseConfig(fp)
is.NoErr(err)
is.Equal(cfg.InitialAdminKeys, []string{
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINMwLvyV3ouVrTysUYGoJdl5Vgn5BACKov+n9PlzfPwH a@b",
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINMwLvyV3ouVrTysUYGoJdl5Vgn5BACKov+n9PlzfPwH",
})
}

0 comments on commit 89e36f2

Please sign in to comment.