forked from hashicorp/vault-plugin-auth-jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend_test.go
57 lines (52 loc) · 1.19 KB
/
backend_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
53
54
55
56
57
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package jwtauth
import (
"context"
"testing"
"github.com/hashicorp/cap/jwt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_jwtAuthBackend_jwtValidator(t *testing.T) {
type args struct {
config *jwtConfig
}
tests := []struct {
name string
args args
want *jwt.Validator
expectedErr string
}{
{
name: "invalid ca pem",
args: args{
config: &jwtConfig{
JWKSPairs: []interface{}{
map[string]any{
"jwks_url": "https://www.foobar.com/something",
"jwks_ca_pem": "defg",
},
map[string]any{
"jwks_url": "https://www.barbaz.com/something",
"jwks_ca_pem": "",
},
},
},
},
expectedErr: "could not parse CA PEM value successfully",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b := &jwtAuthBackend{}
b.providerCtx = context.TODO()
got, err := b.jwtValidator(tt.args.config)
if tt.expectedErr != "" {
require.ErrorContains(t, err, tt.expectedErr)
return
}
assert.Equalf(t, tt.want, got, "jwtValidator(%v)", tt.args.config)
})
}
}