Home / File/ basicauth_test.go — fiber Source File

basicauth_test.go — fiber Source File

Architecture documentation for basicauth_test.go, a go file in the fiber codebase. 1 imports, 0 dependents.

File go FiberCore Adapters 1 imports 26 functions

Entity Profile

Dependency Diagram

graph LR
  c1fa52c0_acd4_56de_8c46_542417f3c9b8["basicauth_test.go"]
  f560810d_ddfe_4559_f474_4e92309e3488["sha256"]
  c1fa52c0_acd4_56de_8c46_542417f3c9b8 --> f560810d_ddfe_4559_f474_4e92309e3488
  style c1fa52c0_acd4_56de_8c46_542417f3c9b8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package basicauth

import (
	"crypto/sha256"
	"crypto/sha512"
	"encoding/base64"
	"encoding/hex"
	"fmt"
	"io"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"

	"github.com/gofiber/fiber/v3"
	"github.com/stretchr/testify/require"
	"github.com/valyala/fasthttp"
	"golang.org/x/crypto/bcrypt"
)

func sha256Hash(p string) string {
	sum := sha256.Sum256([]byte(p))
	return "{SHA256}" + base64.StdEncoding.EncodeToString(sum[:])
}

func sha512Hash(p string) string {
	sum := sha512.Sum512([]byte(p))
	return "{SHA512}" + base64.StdEncoding.EncodeToString(sum[:])
}

// go test -run Test_BasicAuth_Next
func Test_BasicAuth_Next(t *testing.T) {
	t.Parallel()
	app := fiber.New()
	app.Use(New(Config{
		Next: func(_ fiber.Ctx) bool {
			return true
		},
	}))

	resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
	require.NoError(t, err)
	require.Equal(t, fiber.StatusNotFound, resp.StatusCode)
}

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

	hashedJohn := sha256Hash("doe")
	hashedAdmin, err := bcrypt.GenerateFromPassword([]byte("123456"), bcrypt.MinCost)
	require.NoError(t, err)

	app.Use(New(Config{
		Users: map[string]string{
			"john":  hashedJohn,
			"admin": string(hashedAdmin),
		},
	}))

// ... (545 more lines)

Domain

Subdomains

Types

Dependencies

  • sha256

Frequently Asked Questions

What does basicauth_test.go do?
basicauth_test.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Adapters subdomain.
What functions are defined in basicauth_test.go?
basicauth_test.go defines 26 function(s): Benchmark_Middleware_BasicAuth, Benchmark_Middleware_BasicAuth_Upper, Test_BasicAuth_AuthorizerCtx, Test_BasicAuth_Charset, Test_BasicAuth_ControlChars, Test_BasicAuth_EmptyAuthorization, Test_BasicAuth_HashVariants, Test_BasicAuth_HashVariants_Invalid, Test_BasicAuth_HeaderControlCharEdges, Test_BasicAuth_HeaderLimit, and 16 more.
What does basicauth_test.go depend on?
basicauth_test.go imports 1 module(s): sha256.
Where is basicauth_test.go in the architecture?
basicauth_test.go is located at middleware/basicauth/basicauth_test.go (domain: FiberCore, subdomain: Adapters, directory: middleware/basicauth).

Analyze Your Own Codebase

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

Try Supermodel Free