@@ -1250,6 +1250,19 @@ func TestGetPolicyIDFromToken(t *testing.T) {
1250
1250
spec .OAS .ExtractTo (spec .APIDefinition )
1251
1251
},
1252
1252
},
1253
+ {
1254
+ name : "is classic converted to oas without filling BasePolicyClaims" ,
1255
+ claims : jwt.MapClaims {
1256
+ "policy" : "mainpolicy" ,
1257
+ },
1258
+ expectedBool : true ,
1259
+ expected : "mainpolicy" ,
1260
+ modifySpec : func (spec * APISpec ) {
1261
+ spec .APIDefinition .JWTPolicyFieldName = "policy"
1262
+ spec .OAS .Fill (* spec .APIDefinition )
1263
+ spec .IsOAS = true
1264
+ },
1265
+ },
1253
1266
}
1254
1267
1255
1268
for _ , tc := range testCases {
@@ -2865,6 +2878,35 @@ func TestGetUserIDFromClaim(t *testing.T) {
2865
2878
})
2866
2879
})
2867
2880
2881
+ t .Run ("is classic and converted to oas" , func (t * testing.T ) {
2882
+ userIDKey := "user_id"
2883
+ var api apidef.APIDefinition
2884
+ api .EnableJWT = true
2885
+ api .AuthConfigs = map [string ]apidef.AuthConfig {
2886
+ apidef .JWTType : {
2887
+ Name : "jwtAuth" ,
2888
+ AuthHeaderName : "Authorization" ,
2889
+ },
2890
+ }
2891
+ api .JWTIdentityBaseField = userIDKey
2892
+
2893
+ var o oas.OAS
2894
+ o .Fill (api )
2895
+ api .IsOAS = true
2896
+ middleware := JWTMiddleware {& BaseMiddleware {Spec : & APISpec {
2897
+ OAS : o ,
2898
+ APIDefinition : & api ,
2899
+ }}}
2900
+
2901
+ jwtClaims := jwt.MapClaims {
2902
+ userIDKey : userID ,
2903
+ "iss" : "example.com" ,
2904
+ }
2905
+ identity , err := middleware .getUserIdFromClaim (jwtClaims )
2906
+ assert .NoError (t , err )
2907
+ assert .Equal (t , identity , userID )
2908
+ })
2909
+
2868
2910
t .Run ("is OAS" , func (t * testing.T ) {
2869
2911
testCases := []struct {
2870
2912
name string
0 commit comments