forked from loft-sh/devpod
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathgit_ssh_signature_test.go
More file actions
57 lines (48 loc) · 2.01 KB
/
git_ssh_signature_test.go
File metadata and controls
57 lines (48 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package agent
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type GitSSHSignatureTestSuite struct {
suite.Suite
}
func TestGitSSHSignatureSuite(t *testing.T) {
suite.Run(t, new(GitSSHSignatureTestSuite))
}
func (s *GitSSHSignatureTestSuite) TestParseBasicSignArgs() {
args := []string{"-Y", "sign", "-n", "git", "-f", "/path/to/key.pub", "/tmp/buffer"}
result := parseSSHKeygenArgs(args)
assert.Equal(s.T(), "sign", result.command)
assert.Equal(s.T(), "git", result.namespace)
assert.Equal(s.T(), "/path/to/key.pub", result.certPath)
assert.Equal(s.T(), "/tmp/buffer", result.bufferFile)
}
func (s *GitSSHSignatureTestSuite) TestParseWithAgentFlag() {
// When the signing key is loaded in the ssh-agent, git passes -U (a boolean
// "use agent" flag) immediately before the buffer file. The buffer file must
// still be recognised as the last non-flag argument.
args := []string{"-Y", "sign", "-n", "git", "-f", "/path/to/key.pub", "-U", "/tmp/buffer"}
result := parseSSHKeygenArgs(args)
assert.Equal(s.T(), "sign", result.command)
assert.Equal(s.T(), "/path/to/key.pub", result.certPath)
assert.Equal(s.T(), "/tmp/buffer", result.bufferFile)
}
func (s *GitSSHSignatureTestSuite) TestParseNonSignCommand() {
args := []string{"-Y", "verify", "-n", "git", "-f", "/path/to/key.pub", "/tmp/buffer"}
result := parseSSHKeygenArgs(args)
assert.Equal(s.T(), "verify", result.command)
}
func (s *GitSSHSignatureTestSuite) TestParseMissingBufferFile() {
// All args end in a flag — no buffer file present.
args := []string{"-Y", "sign", "-n", "git", "-f", "/path/to/key.pub", "-U"}
result := parseSSHKeygenArgs(args)
assert.Equal(s.T(), "", result.bufferFile)
}
func (s *GitSSHSignatureTestSuite) TestParseDefaultsToSign() {
// If -Y is absent the command defaults to "sign".
args := []string{"-n", "git", "-f", "/path/to/key.pub", "/tmp/buffer"}
result := parseSSHKeygenArgs(args)
assert.Equal(s.T(), "sign", result.command)
assert.Equal(s.T(), "/tmp/buffer", result.bufferFile)
}