-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgha_test.go
45 lines (35 loc) · 1 KB
/
gha_test.go
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
package ghasign
import (
"context"
"encoding/base64"
"fmt"
"testing"
"github.com/openpubkey/openpubkey/client"
"github.com/openpubkey/openpubkey/providers"
"github.com/openpubkey/openpubkey/verifier"
"github.com/stretchr/testify/require"
)
func TestGithub(t *testing.T) {
var op client.OpenIdProvider
var err error
op, err = providers.NewGithubOpFromEnvironment()
require.NoError(t, err)
c, err := client.New(op)
require.NoError(t, err)
pkt, err := c.Auth(context.TODO())
require.NoError(t, err)
require.NotNil(t, pkt)
fmt.Println("New PK token generated")
// For debugging purposes, lets us write the PK Token to the test log
outputPktToken := false
if outputPktToken {
pktCom, _ := pkt.Compact()
b64pktCom := base64.StdEncoding.EncodeToString(pktCom)
fmt.Println(string(b64pktCom))
require.False(t, true) // Println in tests are hidden unless test fails.
}
ver, err := verifier.New(op)
require.NoError(t, err)
err = ver.VerifyPKToken(context.TODO(), pkt)
require.NoError(t, err)
}