-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanager_test.go
More file actions
121 lines (106 loc) · 3.39 KB
/
Copy pathmanager_test.go
File metadata and controls
121 lines (106 loc) · 3.39 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package git
import (
"testing"
"github.com/go-git/go-git/v6/plumbing/transport"
)
const sshScheme = "ssh"
const testEd25519PrivateKey = `-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACDAtq/Kt1/J1J/YivGDJIO57fFW1v68f1eq1N1Vr77BLAAAALB+/pd5fv6X
eQAAAAtzc2gtZWQyNTUxOQAAACDAtq/Kt1/J1J/YivGDJIO57fFW1v68f1eq1N1Vr77BLA
AAAEDDodLIs7cKTLW+FFH5jgfGo2b2iae1w5lbsIXiu8UZKcC2r8q3X8nUn9iK8YMkg7nt
8VbW/rx/V6rU3VWvvsEsAAAAKmNzdGFibGVyQGNzdGFibGVyLXRoaW5rcGFkcDFnZW43Ln
JtdGRlLmNzYgECAw==
-----END OPENSSH PRIVATE KEY-----`
func TestGetClientOptions_HTTPToken(t *testing.T) {
m := &managerImpl{}
secret := map[string][]byte{"token": []byte("my-token")}
opts, tmpFile := m.getClientOptions("https", secret)
if len(opts) != 1 {
t.Fatalf("expected 1 option, got %d", len(opts))
}
if tmpFile != "" {
t.Fatalf("expected no temp file, got %s", tmpFile)
}
}
func TestGetClientOptions_HTTPUsernamePassword(t *testing.T) {
m := &managerImpl{}
secret := map[string][]byte{"username": []byte("user"), "password": []byte("pass")}
opts, _ := m.getClientOptions("http", secret)
if len(opts) != 1 {
t.Fatalf("expected 1 option, got %d", len(opts))
}
}
func TestGetClientOptions_HTTPEmpty(t *testing.T) {
m := &managerImpl{}
opts, _ := m.getClientOptions("https", nil)
if opts != nil {
t.Fatalf("expected nil options, got %v", opts)
}
}
func TestGetClientOptions_SSHNoSecret(t *testing.T) {
m := &managerImpl{}
opts, _ := m.getClientOptions(sshScheme, nil)
if len(opts) != 1 {
t.Fatalf("expected 1 option for insecure SSH, got %d", len(opts))
}
}
func TestGetClientOptions_SSHEmptySecret(t *testing.T) {
m := &managerImpl{}
opts, _ := m.getClientOptions(sshScheme, map[string][]byte{})
if len(opts) != 1 {
t.Fatalf("expected 1 option for insecure SSH, got %d", len(opts))
}
}
func TestGetClientOptions_SSHWithPrivateKey(t *testing.T) {
m := &managerImpl{}
secret := map[string][]byte{"sshPrivateKey": []byte(testEd25519PrivateKey)}
opts, _ := m.getClientOptions(sshScheme, secret)
if len(opts) != 1 {
t.Fatalf("expected 1 option, got %d", len(opts))
}
}
func TestGetClientOptions_SSHWithInvalidKey(t *testing.T) {
m := &managerImpl{}
secret := map[string][]byte{"sshPrivateKey": []byte("not-a-valid-key")}
opts, _ := m.getClientOptions(sshScheme, secret)
if opts != nil {
t.Fatalf("expected nil options for invalid key, got %v", opts)
}
}
func TestParseURL_SCPStyle(t *testing.T) {
u, err := transport.ParseURL("git@github.com:owner/repo.git")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if u.Scheme != sshScheme {
t.Fatalf("expected scheme ssh, got %s", u.Scheme)
}
}
func TestParseURL_SSHScheme(t *testing.T) {
u, err := transport.ParseURL("ssh://git@github.com/owner/repo.git")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if u.Scheme != sshScheme {
t.Fatalf("expected scheme ssh, got %s", u.Scheme)
}
}
func TestParseURL_HTTPSScheme(t *testing.T) {
u, err := transport.ParseURL("https://github.com/owner/repo.git")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if u.Scheme != "https" {
t.Fatalf("expected scheme https, got %s", u.Scheme)
}
}
func TestParseURL_HTTPScheme(t *testing.T) {
u, err := transport.ParseURL("http://github.com/owner/repo.git")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if u.Scheme != "http" {
t.Fatalf("expected scheme http, got %s", u.Scheme)
}
}