Files
Jay Brown 2ff6e05ffc Merged in feature/permit-integration-1 (pull request #172)
Permit integration - part 1

* WIP permit integration

* slim down build

* Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/permit-integration-1

* omit swagger from auth

* clean build

* comment

* part 1 completed

this is the initial permitio parts and tests without integration. Also testing.md since we have a new test target `task test:permitio`

* feature flag for no jwt validation

* permit integration

* fix ci unit tests

* ci fix

* build fix

* fix home handler

* fix redirect

* test fix

* update docs for auth
2025-07-11 19:27:14 +00:00

112 lines
1.9 KiB
Go

package cognitoauth
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestGetResourceFromRoute tests the resource mapping function
func TestGetResourceFromRoute(t *testing.T) {
tests := []struct {
name string
route string
expected string
}{
{
name: "SimpleRoute",
route: "/document",
expected: "document",
},
{
name: "RouteWithID",
route: "/document/123",
expected: "document",
},
{
name: "RouteWithMultipleSegments",
route: "/document/foo/123",
expected: "document",
},
{
name: "NestedRoute",
route: "/api/v1/document",
expected: "api",
},
{
name: "RootRoute",
route: "/",
expected: "",
},
{
name: "RouteWithoutLeadingSlash",
route: "document",
expected: "document",
},
{
name: "RouteWithoutLeadingSlashMultipleSegments",
route: "document/foo/123",
expected: "document",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := GetResourceFromRoute(tt.route)
assert.Equal(t, tt.expected, result)
})
}
}
// TestGetActionFromMethod tests the action mapping function
func TestGetActionFromMethod(t *testing.T) {
tests := []struct {
name string
method string
expected string
}{
{
name: "GET",
method: "GET",
expected: "get",
},
{
name: "POST",
method: "POST",
expected: "post",
},
{
name: "PUT",
method: "PUT",
expected: "put",
},
{
name: "DELETE",
method: "DELETE",
expected: "delete",
},
{
name: "PATCH",
method: "PATCH",
expected: "patch",
},
{
name: "LowercaseMethod",
method: "get",
expected: "get",
},
{
name: "MixedCaseMethod",
method: "GeT",
expected: "get",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := GetActionFromMethod(tt.method)
assert.Equal(t, tt.expected, result)
})
}
}