mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-30 02:46:30 +02:00
- Refactored middleware and request hander logging. - Request refactored to use context.Context. - Add helper (based on Alice) to allow middleware chaining. - Add helper scripts to generate elliptic curve self-signed certificate that can be used to sign JWT. - Changed LetsEncrypt scripts to use acme instead of certbot. - Add script to have LetsEncrypt sign an RSA based certificate. - Add documentation to explain how to verify headers. - Refactored internal/cryptutil signer's code to expect a valid EC priv key. - Changed JWT expiries to use default leeway period. - Update docs and add screenshots. - Replaced logging handler logic to use context.Context. - Removed specific XML error handling. - Refactored handler function signatures to prefer standard go idioms.
44 lines
954 B
Go
44 lines
954 B
Go
package cryptutil
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestES256Signer(t *testing.T) {
|
|
signer, err := NewES256Signer([]byte(pemECPrivateKeyP256), "destination-url")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if signer == nil {
|
|
t.Fatal("signer should not be nil")
|
|
}
|
|
rawJwt, err := signer.SignJWT("joe-user", "joe-user@example.com")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if rawJwt == "" {
|
|
t.Fatal("jwt should not be nil")
|
|
}
|
|
}
|
|
|
|
func TestNewES256Signer(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
name string
|
|
privKey []byte
|
|
audience string
|
|
wantErr bool
|
|
}{
|
|
{"working example", []byte(pemECPrivateKeyP256), "some-domain.com", false},
|
|
{"bad private key", []byte(garbagePEM), "some-domain.com", true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
_, err := NewES256Signer(tt.privKey, tt.audience)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("NewES256Signer() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
})
|
|
}
|
|
}
|