mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-25 06:35:21 +00:00
The server loaded the API key cache before it created the admin key from GOHOARDER_BOOTSTRAP_ADMIN_KEY. The new key was therefore refused until the next restart. Bootstrap now runs before the cache loads.
30 lines
799 B
Go
30 lines
799 B
Go
package app
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
"github.com/lukaszraczylo/gohoarder/pkg/auth"
|
|
)
|
|
|
|
// The env-bootstrapped admin key must work on the boot that creates it, not only after a restart.
|
|
func TestBootstrapAdminKeyWorksOnFirstBoot(t *testing.T) {
|
|
const key = "bootstrap-admin-key-for-test"
|
|
t.Setenv(auth.BootstrapAdminEnvVar, key)
|
|
a := newTestApp(t, nil)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/api/admin/prewarming/status", nil)
|
|
req.Header.Set("X-API-Key", key)
|
|
resp, err := a.app.Test(req, fiber.TestConfig{Timeout: 10 * time.Second})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_ = resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("admin route with the bootstrap key = %d, want 200", resp.StatusCode)
|
|
}
|
|
}
|