@@ -232,25 +232,25 @@ func TestInvalid(t *testing.T) {
232232 assert .True (t , ok )
233233 assert .NoError (t , err )
234234
235- // Invalid request path with wrong not enough parts in path for valid RPC request
235+ // Invalid request path with wrong not enough parts in path for valid RPC request, this will delegate to next handler and return no error
236236 ok , err = executeRequest (t , ctx , r , fmt .Sprintf ("/%s/%s" , ServiceName , MethodName ), accessKey (AccessKey ), jwt (authcontrol .S2SToken (JWTSecret , claims )))
237- assert .False (t , ok )
238- assert .ErrorIs (t , err , proto . ErrUnauthorized )
237+ assert .True (t , ok )
238+ assert .NoError (t , err )
239239
240- // Invalid request path with wrong "rpc"
240+ // Invalid request path with wrong "rpc", this will delegate to next handler and return no error
241241 ok , err = executeRequest (t , ctx , r , fmt .Sprintf ("/pcr/%s/%s" , ServiceName , MethodName ), accessKey (AccessKey ), jwt (authcontrol .S2SToken (JWTSecret , claims )))
242- assert .False (t , ok )
243- assert .ErrorIs (t , err , proto . ErrUnauthorized )
242+ assert .True (t , ok )
243+ assert .NoError (t , err )
244244
245- // Invalid Service
245+ // Invalid Service, this will delegate to next handler and return no error
246246 ok , err = executeRequest (t , ctx , r , fmt .Sprintf ("/rpc/%s/%s" , ServiceNameInvalid , MethodName ), accessKey (AccessKey ), jwt (authcontrol .S2SToken (JWTSecret , claims )))
247- assert .False (t , ok )
248- assert .ErrorIs (t , err , proto . ErrUnauthorized )
247+ assert .True (t , ok )
248+ assert .NoError (t , err )
249249
250- // Invalid Method
250+ // Invalid Method, this will delegate to next handler and return no error
251251 ok , err = executeRequest (t , ctx , r , fmt .Sprintf ("/rpc/%s/%s" , ServiceName , MethodNameInvalid ), accessKey (AccessKey ), jwt (authcontrol .S2SToken (JWTSecret , claims )))
252- assert .False (t , ok )
253- assert .ErrorIs (t , err , proto . ErrUnauthorized )
252+ assert .True (t , ok )
253+ assert .NoError (t , err )
254254
255255 // Expired JWT Token
256256 claims ["exp" ] = time .Now ().Add (- 5 * time .Minute ).Unix () // Note: Session() middleware allows some skew.
@@ -283,7 +283,7 @@ func TestCustomErrHandler(t *testing.T) {
283283
284284 ACLConfig := authcontrol.Config [authcontrol.ACL ]{
285285 ServiceName : {
286- MethodName : authcontrol .NewACL (proto .SessionType_Public .OrHigher ()... ),
286+ MethodName : authcontrol .NewACL (proto .SessionType_AccessKey .OrHigher ()... ),
287287 },
288288 }
289289
@@ -325,16 +325,15 @@ func TestCustomErrHandler(t *testing.T) {
325325
326326 r .Handle ("/*" , http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {}))
327327
328- var claims map [string ]any
329- claims = map [string ]any {"service" : "client_service" }
328+ claims := map [string ]any {"service" : "client_service" }
330329
331330 // Valid Request
332331 ok , err := executeRequest (t , ctx , r , fmt .Sprintf ("/rpc/%s/%s" , ServiceName , MethodName ), accessKey (AccessKey ), jwt (authcontrol .S2SToken (JWTSecret , claims )))
333332 assert .True (t , ok )
334333 assert .NoError (t , err )
335334
336- // Invalid service which should return custom error from overrided ErrHandler
337- ok , err = executeRequest (t , ctx , r , fmt .Sprintf ("/rpc/%s/%s" , ServiceNameInvalid , MethodName ), accessKey ( AccessKey ), jwt ( authcontrol . S2SToken ( JWTSecret , claims ) ))
335+ // Invalid Access, should return custom error
336+ ok , err = executeRequest (t , ctx , r , fmt .Sprintf ("/rpc/%s/%s" , ServiceName , MethodName ))
338337 assert .False (t , ok )
339338 assert .ErrorIs (t , err , customErr )
340339}
0 commit comments