MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestParseScope

Function TestParseScope

api/middleware/auth_test.go:848–894  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

846}
847
848func TestParseScope(t *testing.T) {
849 tests := []struct {
850 name string
851 scope string
852 expectedResource Resource
853 expectedAction Action
854 }{
855 {
856 name: "Valid scope ledgers:read",
857 scope: "ledgers:read",
858 expectedResource: ResourceLedgers,
859 expectedAction: ActionRead,
860 },
861 {
862 name: "Valid scope accounts:write",
863 scope: "accounts:write",
864 expectedResource: ResourceAccounts,
865 expectedAction: ActionWrite,
866 },
867 {
868 name: "Invalid scope - no colon",
869 scope: "ledgersread",
870 expectedResource: "",
871 expectedAction: "",
872 },
873 {
874 name: "Invalid scope - too many parts",
875 scope: "ledgers:read:extra",
876 expectedResource: "",
877 expectedAction: "",
878 },
879 {
880 name: "Empty scope",
881 scope: "",
882 expectedResource: "",
883 expectedAction: "",
884 },
885 }
886
887 for _, tt := range tests {
888 t.Run(tt.name, func(t *testing.T) {
889 resource, action := ParseScope(tt.scope)
890 assert.Equal(t, tt.expectedResource, resource)
891 assert.Equal(t, tt.expectedAction, action)
892 })
893 }
894}
895
896func TestRateLimitMiddleware(t *testing.T) {
897 gin.SetMode(gin.TestMode)

Callers

nothing calls this directly

Calls 1

ParseScopeFunction · 0.85

Tested by

no test coverage detected