network/pkg/gateway/middleware_test.go
anonpenguin23 cf26c1af2c feat: integrate Olric distributed cache support
- Added Olric cache server integration, including configuration options for Olric servers and timeout settings.
- Implemented HTTP handlers for cache operations: health check, get, put, delete, and scan.
- Enhanced Makefile with commands to run the Olric server and manage its configuration.
- Updated README and setup scripts to include Olric installation and configuration instructions.
- Introduced tests for cache handlers to ensure proper functionality and error handling.
2025-11-05 07:31:50 +02:00

29 lines
666 B
Go

package gateway
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestExtractAPIKey(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/", nil)
r.Header.Set("Authorization", "Bearer ak_foo:ns")
if got := extractAPIKey(r); got != "ak_foo:ns" {
t.Fatalf("got %q", got)
}
r.Header.Set("Authorization", "ApiKey ak2")
if got := extractAPIKey(r); got != "ak2" {
t.Fatalf("got %q", got)
}
r.Header.Set("Authorization", "ak3raw")
if got := extractAPIKey(r); got != "ak3raw" {
t.Fatalf("got %q", got)
}
r.Header = http.Header{}
r.Header.Set("X-API-Key", "xkey")
if got := extractAPIKey(r); got != "xkey" {
t.Fatalf("got %q", got)
}
}