github.com/lestrrat-go/jwx/v2@v2.0.21/jwt/token_options_test.go (about) 1 package jwt_test 2 3 import ( 4 "testing" 5 6 "github.com/lestrrat-go/jwx/v2/jwt" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestTokenOptions(t *testing.T) { 11 t.Run("Option names", func(t *testing.T) { 12 for i := uint64(1); i < jwt.MaxPerTokenOption.Value(); i <<= 1 { 13 t.Logf("%s", jwt.TokenOption(i)) 14 } 15 }) 16 t.Run("Sanity", func(t *testing.T) { 17 // Vanilla set 18 var opt jwt.TokenOptionSet 19 20 // Initially, the option should be false 21 require.False(t, opt.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be false`) 22 23 // Flip this bit on 24 opt.Enable(jwt.FlattenAudience) 25 require.True(t, opt.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be true`) 26 27 // Test copying 28 var opt2 jwt.TokenOptionSet 29 opt2.Set(opt) 30 require.True(t, opt.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be true`) 31 require.True(t, opt2.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be true`) 32 33 // Flip this bit off 34 opt.Disable(jwt.FlattenAudience) 35 require.False(t, opt.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be false`) 36 37 // The above should have not action at a distance effect on opt2 38 require.True(t, opt2.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be true`) 39 40 // Clear it 41 opt2.Clear() 42 require.False(t, opt2.IsEnabled(jwt.FlattenAudience), `option FlattenAudience should be false`) 43 }) 44 }