Home / Function/ Test_TokenFromContext() — fiber Function Reference

Test_TokenFromContext() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

middleware/keyauth/keyauth_test.go lines 526–553

func Test_TokenFromContext(t *testing.T) {
	app := fiber.New()
	// Wire up keyauth middleware to set TokenFromContext now
	app.Use(New(Config{
		Extractor: extractors.FromAuthHeader("Basic"),
		Validator: func(_ fiber.Ctx, key string) (bool, error) {
			if key == CorrectKey {
				return true, nil
			}
			return false, ErrMissingOrMalformedAPIKey
		},
	}))
	// Define a test handler that checks TokenFromContext
	app.Get("/", func(c fiber.Ctx) error {
		return c.SendString(TokenFromContext(c))
	})

	req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
	req.Header.Add("Authorization", "Basic "+CorrectKey)
	// Send
	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)
	require.Equal(t, CorrectKey, string(body))
}

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free