Home / Function/ Test_AuthSchemeToken() — fiber Function Reference

Test_AuthSchemeToken() — fiber Function Reference

Architecture documentation for the Test_AuthSchemeToken() function in keyauth_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  88d58068_7c8b_d1cf_3b3d_62430f96765d["Test_AuthSchemeToken()"]
  71f55784_a001_0646_0ce7_7ad97067c49c["keyauth_test.go"]
  88d58068_7c8b_d1cf_3b3d_62430f96765d -->|defined in| 71f55784_a001_0646_0ce7_7ad97067c49c
  style 88d58068_7c8b_d1cf_3b3d_62430f96765d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/keyauth/keyauth_test.go lines 555–588

func Test_AuthSchemeToken(t *testing.T) {
	app := fiber.New()

	app.Use(New(Config{
		Extractor: extractors.FromAuthHeader("Token"),
		Validator: func(_ fiber.Ctx, key string) (bool, error) {
			if key == CorrectKey {
				return true, nil
			}
			return false, ErrMissingOrMalformedAPIKey
		},
	}))

	// Define a test handler
	app.Get("/", func(c fiber.Ctx) error {
		return c.SendString("API key is valid")
	})

	// Create a request with a valid API key in the "Token" Authorization header
	req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
	req.Header.Add("Authorization", "Token "+CorrectKey)

	// Send the request to the app
	res, err := app.Test(req)
	require.NoError(t, err)

	// Read the response body into a string
	body, err := io.ReadAll(res.Body)
	require.NoError(t, err)

	// Check that the response has the expected status code and body
	require.Equal(t, http.StatusOK, res.StatusCode)
	require.Equal(t, "API key is valid", string(body))
}

Domain

Subdomains

Frequently Asked Questions

What does Test_AuthSchemeToken() do?
Test_AuthSchemeToken() is a function in the fiber codebase, defined in middleware/keyauth/keyauth_test.go.
Where is Test_AuthSchemeToken() defined?
Test_AuthSchemeToken() is defined in middleware/keyauth/keyauth_test.go at line 555.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free