Test_MultipleKeyAuth() — fiber Function Reference
Architecture documentation for the Test_MultipleKeyAuth() function in keyauth_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD cbfb61cd_b2ce_2f09_4d04_6c71fbda0a9f["Test_MultipleKeyAuth()"] 71f55784_a001_0646_0ce7_7ad97067c49c["keyauth_test.go"] cbfb61cd_b2ce_2f09_4d04_6c71fbda0a9f -->|defined in| 71f55784_a001_0646_0ce7_7ad97067c49c style cbfb61cd_b2ce_2f09_4d04_6c71fbda0a9f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/keyauth/keyauth_test.go lines 258–387
func Test_MultipleKeyAuth(t *testing.T) {
// set up the fiber endpoint
app := fiber.New()
// set up keyauth for /auth1
app.Use(New(Config{
Next: func(c fiber.Ctx) bool {
return c.Path() != "/auth1"
},
Extractor: extractors.FromAuthHeader("Bearer"),
Validator: func(_ fiber.Ctx, key string) (bool, error) {
if key == "password1" {
return true, nil
}
return false, errors.New("invalid key")
},
}))
// setup keyauth for /auth2
app.Use(New(Config{
Next: func(c fiber.Ctx) bool {
return c.Path() != "/auth2"
},
Extractor: extractors.FromAuthHeader("Bearer"),
Validator: func(_ fiber.Ctx, key string) (bool, error) {
if key == "password2" {
return true, nil
}
return false, errors.New("invalid key")
},
}))
app.Get("/", func(c fiber.Ctx) error {
return c.SendString("No auth needed!")
})
app.Get("/auth1", func(c fiber.Ctx) error {
return c.SendString("Successfully authenticated for auth1!")
})
app.Get("/auth2", func(c fiber.Ctx) error {
return c.SendString("Successfully authenticated for auth2!")
})
// define test cases
tests := []struct {
route string
description string
APIKey string
expectedBody string
expectedCode int
}{
// No auth needed for /
{
route: "/",
description: "No password needed",
APIKey: "",
expectedCode: 200,
expectedBody: "No auth needed!",
},
// auth needed for auth1
{
route: "/auth1",
description: "Normal Authentication Case",
APIKey: "password1",
expectedCode: 200,
expectedBody: "Successfully authenticated for auth1!",
},
{
route: "/auth1",
description: "Wrong API Key",
APIKey: "WRONG KEY",
expectedCode: 401,
expectedBody: ErrMissingOrMalformedAPIKey.Error(),
},
{
route: "/auth1",
description: "Wrong API Key",
APIKey: "", // NO KEY
expectedCode: 401,
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_MultipleKeyAuth() do?
Test_MultipleKeyAuth() is a function in the fiber codebase, defined in middleware/keyauth/keyauth_test.go.
Where is Test_MultipleKeyAuth() defined?
Test_MultipleKeyAuth() is defined in middleware/keyauth/keyauth_test.go at line 258.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free