Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cashier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Lyda
cashier
Commits
cc3c74ff
Commit
cc3c74ff
authored
9 years ago
by
Niall Sheridan
Browse files
Options
Downloads
Patches
Plain Diff
SSH signer tests
parent
93da00c2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/signer/signer_test.go
+74
-0
74 additions, 0 deletions
server/signer/signer_test.go
with
74 additions
and
0 deletions
server/signer/signer_test.go
0 → 100644
+
74
−
0
View file @
cc3c74ff
package
signer
import
(
"bytes"
"reflect"
"testing"
"time"
"github.com/nsheridan/cashier/lib"
"github.com/nsheridan/cashier/testdata"
"golang.org/x/crypto/ssh"
)
var
(
key
,
_
=
ssh
.
ParsePrivateKey
(
testdata
.
Priv
)
signer
=
&
KeySigner
{
ca
:
key
,
validity
:
12
*
time
.
Hour
,
principals
:
[]
string
{
"ec2-user"
},
}
)
func
TestSign
(
t
*
testing
.
T
)
{
s
:=
&
lib
.
SignRequest
{
Key
:
string
(
testdata
.
Pub
),
Principal
:
"gopher1"
,
ValidUntil
:
time
.
Now
()
.
Add
(
1
*
time
.
Hour
),
}
ret
,
err
:=
signer
.
Sign
(
s
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
c
,
_
,
_
,
_
,
err
:=
ssh
.
ParseAuthorizedKey
([]
byte
(
ret
))
cert
,
ok
:=
c
.
(
*
ssh
.
Certificate
)
if
!
ok
{
t
.
Fatalf
(
"Expected type *ssh.Certificate, got %v (%T)"
,
cert
,
cert
)
}
}
func
TestCert
(
t
*
testing
.
T
)
{
r
:=
&
lib
.
SignRequest
{
Key
:
string
(
testdata
.
Pub
),
Principal
:
"gopher1"
,
ValidUntil
:
time
.
Now
()
.
Add
(
1
*
time
.
Hour
),
}
ret
,
err
:=
signer
.
Sign
(
r
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
c
,
_
,
_
,
_
,
err
:=
ssh
.
ParseAuthorizedKey
([]
byte
(
ret
))
cert
,
ok
:=
c
.
(
*
ssh
.
Certificate
)
if
!
ok
{
t
.
Fatalf
(
"Expected type *ssh.Certificate, got %v (%T)"
,
cert
,
cert
)
}
if
!
bytes
.
Equal
(
cert
.
SignatureKey
.
Marshal
(),
signer
.
ca
.
PublicKey
()
.
Marshal
())
{
t
.
Fatal
(
"Cert signer and server signer don't match"
)
}
var
principals
[]
string
principals
=
append
(
principals
,
r
.
Principal
)
principals
=
append
(
principals
,
signer
.
principals
...
)
if
!
reflect
.
DeepEqual
(
cert
.
ValidPrincipals
,
principals
)
{
t
.
Fatalf
(
"Expected %s, got %s"
,
cert
.
ValidPrincipals
,
principals
)
}
k1
,
_
,
_
,
_
,
err
:=
ssh
.
ParseAuthorizedKey
([]
byte
(
r
.
Key
))
k2
:=
cert
.
Key
if
!
bytes
.
Equal
(
k1
.
Marshal
(),
k2
.
Marshal
())
{
t
.
Fatal
(
"Cert key doesn't match public key"
)
}
if
cert
.
ValidBefore
!=
uint64
(
r
.
ValidUntil
.
Unix
())
{
t
.
Fatalf
(
"Invalid validity, expected %d, got %d"
,
r
.
ValidUntil
,
cert
.
ValidBefore
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment