-
Notifications
You must be signed in to change notification settings - Fork 497
/
Copy pathcommon_test.go
52 lines (44 loc) · 1.12 KB
/
common_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
46
47
48
49
50
51
52
package main
import (
"crypto/x509"
"sync"
"time"
"github.com/go-jose/go-jose/v4"
"github.com/spiffe/spire/pkg/common/pemutil"
)
var (
ec256Pubkey, _ = pemutil.ParsePublicKey([]byte(`-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEiSt7S4ih6QLodw9wf+zdPV8bmAlD
JBCRRy24/UAZY70ZviCRAJ4ePscJtnN1y1wDH13GgOAL2y52xIbtkshYmw==
-----END PUBLIC KEY-----`))
ec256PubkeyPKIX, _ = x509.MarshalPKIXPublicKey(ec256Pubkey)
)
type FakeKeySetSource struct {
mu sync.Mutex
jwks *jose.JSONWebKeySet
modTime time.Time
pollTime time.Time
}
func (s *FakeKeySetSource) SetKeySet(jwks *jose.JSONWebKeySet, modTime time.Time, pollTime time.Time) {
s.mu.Lock()
defer s.mu.Unlock()
s.jwks = jwks
s.modTime = modTime
s.pollTime = pollTime
}
func (s *FakeKeySetSource) FetchKeySet() (*jose.JSONWebKeySet, time.Time, bool) {
s.mu.Lock()
defer s.mu.Unlock()
if s.jwks == nil {
return nil, time.Time{}, false
}
return s.jwks, s.modTime, true
}
func (s *FakeKeySetSource) Close() error {
return nil
}
func (s *FakeKeySetSource) LastSuccessfulPoll() time.Time {
s.mu.Lock()
defer s.mu.Unlock()
return s.pollTime
}