Skip to content

Commit

Permalink
feat: Add test case for publickey_simple_withmultiple_keyfile (#396)
Browse files Browse the repository at this point in the history
This commit adds a new test case to cover the scenario where multiple key files are used for authentication with the publickey_simple user. It generates a temporary key file and attempts to SSH to the piper server using both the correct and incorrect key files. The test verifies that the correct key file allows the connection and writes a random text to a shared file.
  • Loading branch information
tg123 committed May 30, 2024
1 parent 6fe67e3 commit 305e816
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions e2e/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,55 @@ func TestYaml(t *testing.T) {
checkSharedFileContent(t, targetfie, randtext)
})

t.Run("publickey_simple_withmultiple_keyfile", func(t *testing.T) {
randtext := uuid.New().String()
targetfie := uuid.New().String()

wrongkeydir, err := os.MkdirTemp("", "")
if err != nil {
t.Errorf("failed to create temp key file: %v", err)
}

wrongkeyfile := path.Join(wrongkeydir, "key")

if err := runCmdAndWait(
"ssh-keygen",
"-N",
"",
"-f",
wrongkeyfile,
); err != nil {
t.Errorf("failed to generate key: %v", err)
}

c, _, _, err := runCmd(
"ssh",
"-v",
"-o",
"StrictHostKeyChecking=no",
"-o",
"UserKnownHostsFile=/dev/null",
"-p",
piperport,
"-l",
"publickey_simple",
"-i",
wrongkeyfile,
"-i",
path.Join(yamldir, "id_rsa_simple"),
"127.0.0.1",
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
)

if err != nil {
t.Errorf("failed to ssh to piper, %v", err)
}

defer killCmd(c)

time.Sleep(time.Second) // wait for file flush

checkSharedFileContent(t, targetfie, randtext)
})

}

0 comments on commit 305e816

Please sign in to comment.