LEFT | RIGHT |
(no file at all) | |
1 package test | 1 package test |
2 | 2 |
3 import ( | 3 import ( |
4 "crypto/x509" | |
5 "encoding/pem" | |
6 "reflect" | 4 "reflect" |
7 "strings" | 5 "strings" |
8 "testing" | 6 "testing" |
9 | 7 |
10 "code.google.com/p/go.crypto/ssh" | 8 "code.google.com/p/go.crypto/ssh" |
11 ) | 9 ) |
12 | 10 |
13 var ( | 11 var ( |
14 validKey = `AAAAB3NzaC1yc2EAAAADAQABAAABAQDEX/dPu4PmtvgK3La9zioCEDrJ` + | 12 validKey = `AAAAB3NzaC1yc2EAAAADAQABAAABAQDEX/dPu4PmtvgK3La9zioCEDrJ` + |
15 `yUr6xEIK7Pr+rLgydcqWTU/kt7w7gKjOw4vvzgHfjKl09CWyvgb+y5dCiTk` + | 13 `yUr6xEIK7Pr+rLgydcqWTU/kt7w7gKjOw4vvzgHfjKl09CWyvgb+y5dCiTk` + |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 values = append(values, r) | 162 values = append(values, r) |
165 } | 163 } |
166 | 164 |
167 if !reflect.DeepEqual(values, expected) { | 165 if !reflect.DeepEqual(values, expected) { |
168 t.Errorf("got %q, expected %q", values, expected) | 166 t.Errorf("got %q, expected %q", values, expected) |
169 } | 167 } |
170 | 168 |
171 } | 169 } |
172 | 170 |
173 func getTestPublicKey(t *testing.T) ssh.PublicKey { | 171 func getTestPublicKey(t *testing.T) ssh.PublicKey { |
174 » block, _ := pem.Decode([]byte(testClientPrivateKey)) | 172 » priv, err := ssh.ParsePrivateKey([]byte(testClientPrivateKey)) |
175 » if block == nil { | |
176 » » t.Fatalf("pem.Decode: %v", testClientPrivateKey) | |
177 » } | |
178 » priv, err := x509.ParsePKCS1PrivateKey(block.Bytes) | |
179 if err != nil { | 173 if err != nil { |
180 » » t.Fatalf("x509.ParsePKCS1PrivateKey: %v", err) | 174 » » t.Fatalf("ParsePrivateKey: %v", err) |
181 » } | 175 » } |
182 | 176 |
183 » return ssh.NewRSAPublicKey(&priv.PublicKey) | 177 » return priv.PublicKey() |
184 } | 178 } |
185 | 179 |
186 func TestAuth(t *testing.T) { | 180 func TestAuth(t *testing.T) { |
187 pub := getTestPublicKey(t) | 181 pub := getTestPublicKey(t) |
188 rest2 := strings.Join(authWithOptions[3:], "\n") | 182 rest2 := strings.Join(authWithOptions[3:], "\n") |
189 rest3 := strings.Join(authWithOptions[6:], "\n") | 183 rest3 := strings.Join(authWithOptions[6:], "\n") |
190 testAuthorizedKeys(t, []byte(authOptions), []authResult{ | 184 testAuthorizedKeys(t, []byte(authOptions), []authResult{ |
191 {pub, []string{`env="HOME=/home/root"`, "no-port-forwarding"}, "
user@host", rest2, true}, | 185 {pub, []string{`env="HOME=/home/root"`, "no-port-forwarding"}, "
user@host", rest2, true}, |
192 {pub, []string{`env="HOME=/home/root2"`}, "user2@host2", rest3,
true}, | 186 {pub, []string{`env="HOME=/home/root2"`}, "user2@host2", rest3,
true}, |
193 {nil, nil, "", "", false}, | 187 {nil, nil, "", "", false}, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 {pub, []string{`env="HOME=/home/root"`, `shared-control`}, "user
@host", "", true}, | 237 {pub, []string{`env="HOME=/home/root"`, `shared-control`}, "user
@host", "", true}, |
244 }) | 238 }) |
245 } | 239 } |
246 | 240 |
247 func TestInvalidEntry(t *testing.T) { | 241 func TestInvalidEntry(t *testing.T) { |
248 _, _, _, _, ok := ssh.ParseAuthorizedKey(authInvalid) | 242 _, _, _, _, ok := ssh.ParseAuthorizedKey(authInvalid) |
249 if ok { | 243 if ok { |
250 t.Errorf("Expected invalid entry, returned valid entry") | 244 t.Errorf("Expected invalid entry, returned valid entry") |
251 } | 245 } |
252 } | 246 } |
LEFT | RIGHT |