Extension of Parsing, this is to test out functionality specific to switching codecs with padding.
(t *testing.T)
| 798 | |
| 799 | // Extension of Parsing, this is to test out functionality specific to switching codecs with padding. |
| 800 | func TestSetPadding(t *testing.T) { |
| 801 | for _, data := range setPaddingTestData { |
| 802 | t.Run(data.name, func(t *testing.T) { |
| 803 | // If the token string is blank, use helper function to generate string |
| 804 | if data.tokenString == "" { |
| 805 | data.tokenString = signToken(data.claims, data.signingMethod) |
| 806 | } |
| 807 | |
| 808 | // Parse the token |
| 809 | var token *jwt.Token |
| 810 | var err error |
| 811 | var opts = []jwt.ParserOption{jwt.WithoutClaimsValidation()} |
| 812 | |
| 813 | if data.paddedDecode { |
| 814 | opts = append(opts, jwt.WithPaddingAllowed()) |
| 815 | } |
| 816 | if data.strictDecode { |
| 817 | opts = append(opts, jwt.WithStrictDecoding()) |
| 818 | } |
| 819 | |
| 820 | parser := jwt.NewParser(opts...) |
| 821 | |
| 822 | // Figure out correct claims type |
| 823 | token, err = parser.ParseWithClaims(data.tokenString, jwt.MapClaims{}, data.keyfunc) |
| 824 | |
| 825 | if (err == nil) != data.valid || token.Valid != data.valid { |
| 826 | t.Errorf("[%v] Error Parsing Token with decoding padding set to %v: %v", |
| 827 | data.name, |
| 828 | data.paddedDecode, |
| 829 | err, |
| 830 | ) |
| 831 | } |
| 832 | }) |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | func BenchmarkParseUnverified(b *testing.B) { |
| 837 | // Iterate over test data set and run tests |
nothing calls this directly
no test coverage detected