Skip to content

Commit e2d6c2c

Browse files
committed
more unit tests
Signed-off-by: Huabing Zhao <[email protected]>
1 parent 4e33aa4 commit e2d6c2c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

internal/mcpproxy/authorization_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,13 @@ func TestAuthorizeRequest(t *testing.T) {
206206
backendName: "backend1",
207207
toolName: "tool1",
208208
args: map[string]any{
209-
"payload": map[string]any{"kind": "test", "value": 123},
209+
"payload": struct {
210+
Kind string `json:"kind"`
211+
Value int `json:"value"`
212+
}{
213+
Kind: "test",
214+
Value: 123,
215+
},
210216
},
211217
expectAllowed: true,
212218
},
@@ -377,6 +383,27 @@ func TestAuthorizeRequest(t *testing.T) {
377383
toolName: "tool1",
378384
expectAllowed: false,
379385
},
386+
{
387+
name: "invalid bearer token not allowed when rules exist",
388+
auth: &filterapi.MCPRouteAuthorization{
389+
DefaultAction: filterapi.AuthorizationActionAllow,
390+
Rules: []filterapi.MCPRouteAuthorizationRule{
391+
{
392+
Source: filterapi.MCPAuthorizationSource{
393+
JWTSource: filterapi.JWTSource{Scopes: []string{"read"}},
394+
},
395+
Target: filterapi.MCPAuthorizationTarget{
396+
Tools: []filterapi.ToolCall{{BackendName: "backend1", ToolName: "tool1"}},
397+
},
398+
Action: filterapi.AuthorizationActionDeny,
399+
},
400+
},
401+
},
402+
header: "Bearer invalid.token.here",
403+
backendName: "backend1",
404+
toolName: "tool1",
405+
expectAllowed: false,
406+
},
380407
{
381408
name: "multiple rules, first match applied - denied",
382409
auth: &filterapi.MCPRouteAuthorization{

0 commit comments

Comments
 (0)