-
Notifications
You must be signed in to change notification settings - Fork 2
/
token.go
41 lines (32 loc) · 801 Bytes
/
token.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
package test
import (
"context"
"errors"
"github.com/alexfalkowski/go-service/meta"
)
// NewGenerator for test.
func NewGenerator(token string, err error) *Generator {
return &Generator{token: token, err: err}
}
// Generator for test.
type Generator struct {
token string
err error
}
func (g *Generator) Generate(ctx context.Context) (context.Context, []byte, error) {
return ctx, []byte(g.token), g.err
}
// NewVerifier for test.
func NewVerifier(token string) *Verifier {
return &Verifier{token: token}
}
// Verifier for test.
type Verifier struct {
token string
}
func (v *Verifier) Verify(ctx context.Context, token []byte) (context.Context, error) {
if string(token) != v.token {
return ctx, errors.New("invalid token")
}
return WithTest(ctx, meta.String("auth")), nil
}