mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
9 years ago
|
// Copyright 2014 The Go Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
// +build darwin dragonfly freebsd linux netbsd openbsd
|
||
|
|
||
|
package test
|
||
|
|
||
|
import (
|
||
|
"crypto/rand"
|
||
|
"testing"
|
||
|
|
||
|
"golang.org/x/crypto/ssh"
|
||
|
)
|
||
|
|
||
|
func TestCertLogin(t *testing.T) {
|
||
|
s := newServer(t)
|
||
|
defer s.Shutdown()
|
||
|
|
||
|
// Use a key different from the default.
|
||
|
clientKey := testSigners["dsa"]
|
||
|
caAuthKey := testSigners["ecdsa"]
|
||
|
cert := &ssh.Certificate{
|
||
|
Key: clientKey.PublicKey(),
|
||
|
ValidPrincipals: []string{username()},
|
||
|
CertType: ssh.UserCert,
|
||
|
ValidBefore: ssh.CertTimeInfinity,
|
||
|
}
|
||
|
if err := cert.SignCert(rand.Reader, caAuthKey); err != nil {
|
||
|
t.Fatalf("SetSignature: %v", err)
|
||
|
}
|
||
|
|
||
|
certSigner, err := ssh.NewCertSigner(cert, clientKey)
|
||
|
if err != nil {
|
||
|
t.Fatalf("NewCertSigner: %v", err)
|
||
|
}
|
||
|
|
||
|
conf := &ssh.ClientConfig{
|
||
|
User: username(),
|
||
|
}
|
||
|
conf.Auth = append(conf.Auth, ssh.PublicKeys(certSigner))
|
||
|
client, err := s.TryDial(conf)
|
||
|
if err != nil {
|
||
|
t.Fatalf("TryDial: %v", err)
|
||
|
}
|
||
|
client.Close()
|
||
|
}
|