Skip to content

Commit 9fa9e27

Browse files
sarg3ntclaude
andcommitted
fix(rotation): adapt phase-1 to main after rebase
Two changes required by main moving forward (PRs #127, #134, #137): 1. internal/api/server_test.go was added in PR #127 (remote console) after Phase 1 branched. It uses the old ServerConfig.APIKey field that Phase 1 replaced with KeyRing. Updated the test to construct a one-entry KeyRing and send the legacy 64-hex bearer token. 2. PR #127 also added migration 000002_add_box_console_enabled, colliding with Phase 1's 000002_add_box_agent_keys. Renumbered Phase 1's migration to 000003. Migrations are content-addressed by the embedded iofs, so the rename is mechanical — no schema change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b654c53 commit 9fa9e27

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

gearbox-agent/internal/api/server_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package api
22

33
import (
4+
"encoding/hex"
45
"io"
56
"log/slog"
67
"net/http"
78
"net/http/httptest"
9+
"strings"
810
"testing"
911

12+
"github.com/sarg3nt/gearbox-agent/internal/framework/crypto"
1013
"github.com/sarg3nt/gearbox-agent/internal/framework/events"
1114
)
1215

@@ -29,9 +32,21 @@ func TestNewServer_ConsoleRoutesAlwaysMounted(t *testing.T) {
2932
bus := events.NewBus()
3033
defer bus.Close()
3134

35+
// Build a one-entry keyring whose legacy bare-hex token the test
36+
// then sends in the Authorization header. The keyring replaced the
37+
// single-string APIKey field on ServerConfig (issue #72).
38+
testSecret := strings.Repeat("ab", 32) // 64 hex chars / 32 bytes
39+
secretBytes, _ := hex.DecodeString(testSecret)
40+
kr := &crypto.KeyRing{
41+
Version: 1,
42+
Entries: []crypto.KeyRingEntry{{
43+
KID: "legacy", Secret: secretBytes, SecretHex: testSecret, Role: "primary",
44+
}},
45+
}
46+
3247
srv := NewServer(ServerConfig{
3348
ListenAddr: "127.0.0.1:0",
34-
APIKey: "test-key",
49+
KeyRing: crypto.NewKeyRingPointer(kr),
3550
Logger: newSilentLogger(),
3651
EventBus: bus,
3752
})
@@ -42,7 +57,7 @@ func TestNewServer_ConsoleRoutesAlwaysMounted(t *testing.T) {
4257
// Capabilities — auth-gated, no token required, deterministic
4358
// response.
4459
req, _ := http.NewRequest(http.MethodGet, ts.URL+"/api/v1/console/capabilities", nil)
45-
req.Header.Set("Authorization", "Bearer test-key")
60+
req.Header.Set("Authorization", "Bearer "+testSecret)
4661
resp, err := http.DefaultClient.Do(req)
4762
if err != nil {
4863
t.Fatalf("capabilities request: %v", err)

gearbox/internal/framework/database/migrations/files/000002_add_box_agent_keys.down.sql renamed to gearbox/internal/framework/database/migrations/files/000003_add_box_agent_keys.down.sql

File renamed without changes.

gearbox/internal/framework/database/migrations/files/000002_add_box_agent_keys.up.sql renamed to gearbox/internal/framework/database/migrations/files/000003_add_box_agent_keys.up.sql

File renamed without changes.

0 commit comments

Comments
 (0)