File: token_options_test.go

package info (click to toggle)
golang-github-lestrrat-go-jwx 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,872 kB
  • sloc: sh: 222; makefile: 86; perl: 62
file content (44 lines) | stat: -rw-r--r-- 1,398 bytes parent folder | download
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
package jwt_test

import (
	"testing"

	"github.com/lestrrat-go/jwx/v2/jwt"
	"github.com/stretchr/testify/require"
)

func TestTokenOptions(t *testing.T) {
	t.Run("Option names", func(t *testing.T) {
		for i := uint64(1); i < jwt.MaxPerTokenOption.Value(); i <<= 1 {
			t.Logf("%s", jwt.TokenOption(i))
		}
	})
	t.Run("Sanity", func(t *testing.T) {
		// Vanilla set
		var opt jwt.TokenOptionSet

		// Initially, the option should be false
		require.False(t, opt.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be false`)

		// Flip this bit on
		opt.Enable(jwt.FlattenAudience)
		require.True(t, opt.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be true`)

		// Test copying
		var opt2 jwt.TokenOptionSet
		opt2.Set(opt)
		require.True(t, opt.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be true`)
		require.True(t, opt2.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be true`)

		// Flip this bit off
		opt.Disable(jwt.FlattenAudience)
		require.False(t, opt.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be false`)

		// The above should have not action at a distance effect on opt2
		require.True(t, opt2.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be true`)

		// Clear it
		opt2.Clear()
		require.False(t, opt2.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be false`)
	})
}