mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
Auth is Hanzo IAM and nothing else, so the registry a provider name was once checked against is gone, and with it every check. A collection could declare a google login and save clean, while auth-methods answers iam whatever that collection stores. One name validates now, and it lives in core beside the check rather than as a literal in apis. The tests describing the removed registry are rewritten around the provider that exists, fixtures included. TestAnchorStatusAfterClose demanded an unchanged anchor height across a Close that joins the anchor goroutine, so a submit in flight still landed and it failed 4 runs in 60; it now asserts the height cannot rewind. Co-authored-by: Hanzo Dev <[email protected]>
108 lines
3.2 KiB
Go
108 lines
3.2 KiB
Go
package apis_test
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/base/apis"
|
|
"github.com/hanzoai/base/core"
|
|
"github.com/hanzoai/base/tests"
|
|
)
|
|
|
|
func TestRecordAuthMethodsList(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
scenarios := []tests.ApiScenario{
|
|
{
|
|
Name: "missing collection",
|
|
Method: http.MethodGet,
|
|
URL: "/v1/collections/missing/auth-methods",
|
|
ExpectedStatus: 404,
|
|
ExpectedContent: []string{`"data":{}`},
|
|
ExpectedEvents: map[string]int{"*": 0},
|
|
},
|
|
{
|
|
Name: "non auth collection",
|
|
Method: http.MethodGet,
|
|
URL: "/v1/collections/demo1/auth-methods",
|
|
ExpectedStatus: 404,
|
|
ExpectedContent: []string{`"data":{}`},
|
|
ExpectedEvents: map[string]int{"*": 0},
|
|
},
|
|
{
|
|
// the collection stores a disabled oauth2 config, and it makes no
|
|
// difference: auth is IAM, so every auth collection advertises IAM.
|
|
Name: "auth collection, IAM unconfigured",
|
|
Method: http.MethodGet,
|
|
URL: "/v1/collections/nologin/auth-methods",
|
|
ExpectedStatus: 200,
|
|
ExpectedContent: []string{
|
|
`"oauth2":{`,
|
|
`"providers":[{`,
|
|
`"name":"iam"`,
|
|
`"enabled":true`,
|
|
`"authURL":""`, // nowhere to send anyone until IAM is named
|
|
},
|
|
ExpectedEvents: map[string]int{"*": 0},
|
|
},
|
|
{
|
|
Name: "auth collection, IAM configured",
|
|
Method: http.MethodGet,
|
|
URL: "/v1/collections/users/auth-methods",
|
|
BeforeTestFunc: func(t testing.TB, app *tests.TestApp, e *core.ServeEvent) {
|
|
app.Store().Set(apis.StoreKeyJWKSURL, "https://iam.example.com/v1/iam/.well-known/jwks")
|
|
},
|
|
ExpectedStatus: 200,
|
|
ExpectedContent: []string{
|
|
`"name":"iam"`,
|
|
`"state":`,
|
|
`"displayName":`,
|
|
`"codeVerifier":`,
|
|
`"codeChallenge":`,
|
|
`"codeChallengeMethod":"S256"`,
|
|
`"authURL":"https://iam.example.com/v1/iam/oauth/authorize?response_type=code`,
|
|
`redirect_uri="`, // ensures that the redirect_uri is the last url param
|
|
},
|
|
ExpectedEvents: map[string]int{"*": 0},
|
|
},
|
|
|
|
// rate limit checks
|
|
// -----------------------------------------------------------
|
|
{
|
|
Name: "RateLimit rule - nologin:listAuthMethods",
|
|
Method: http.MethodGet,
|
|
URL: "/v1/collections/nologin/auth-methods",
|
|
BeforeTestFunc: func(t testing.TB, app *tests.TestApp, e *core.ServeEvent) {
|
|
app.Settings().RateLimits.Enabled = true
|
|
app.Settings().RateLimits.Rules = []core.RateLimitRule{
|
|
{MaxRequests: 100, Label: "abc"},
|
|
{MaxRequests: 100, Label: "*:listAuthMethods"},
|
|
{MaxRequests: 0, Label: "nologin:listAuthMethods"},
|
|
}
|
|
},
|
|
ExpectedStatus: 429,
|
|
ExpectedContent: []string{`"data":{}`},
|
|
ExpectedEvents: map[string]int{"*": 0},
|
|
},
|
|
{
|
|
Name: "RateLimit rule - *:listAuthMethods",
|
|
Method: http.MethodGet,
|
|
URL: "/v1/collections/nologin/auth-methods",
|
|
BeforeTestFunc: func(t testing.TB, app *tests.TestApp, e *core.ServeEvent) {
|
|
app.Settings().RateLimits.Enabled = true
|
|
app.Settings().RateLimits.Rules = []core.RateLimitRule{
|
|
{MaxRequests: 100, Label: "abc"},
|
|
{MaxRequests: 0, Label: "*:listAuthMethods"},
|
|
}
|
|
},
|
|
ExpectedStatus: 429,
|
|
ExpectedContent: []string{`"data":{}`},
|
|
ExpectedEvents: map[string]int{"*": 0},
|
|
},
|
|
}
|
|
|
|
for _, scenario := range scenarios {
|
|
scenario.Test(t)
|
|
}
|
|
}
|