Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions hub-server/internal/cache/client_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func TestBlacklistRefreshToken_ThenCheck_Hit(t *testing.T) {
c, _ := testClient(t)
ctx := context.Background()

const tokenHash = "rt-hash-hit-1"
require.NoError(t, c.BlacklistRefreshToken(ctx, tokenHash, 5*time.Minute))
const blacklistKey = "rt-hash-hit-1"
require.NoError(t, c.BlacklistRefreshToken(ctx, blacklistKey, 5*time.Minute))

hit, err := c.IsRefreshTokenBlacklisted(ctx, tokenHash)
hit, err := c.IsRefreshTokenBlacklisted(ctx, blacklistKey)
require.NoError(t, err)
assert.True(t, hit, "blacklisted refresh token must be reported as blacklisted")
}
Expand All @@ -43,13 +43,13 @@ func TestBlacklistRefreshToken_RevokeIsIdempotent(t *testing.T) {
c, _ := testClient(t)
ctx := context.Background()

const tokenHash = "rt-hash-idempotent"
const blacklistKey = "rt-hash-idempotent"
// First revocation.
require.NoError(t, c.BlacklistRefreshToken(ctx, tokenHash, 5*time.Minute))
require.NoError(t, c.BlacklistRefreshToken(ctx, blacklistKey, 5*time.Minute))
// Second revocation of the same hash must succeed (idempotent).
require.NoError(t, c.BlacklistRefreshToken(ctx, tokenHash, 5*time.Minute))
require.NoError(t, c.BlacklistRefreshToken(ctx, blacklistKey, 5*time.Minute))

hit, err := c.IsRefreshTokenBlacklisted(ctx, tokenHash)
hit, err := c.IsRefreshTokenBlacklisted(ctx, blacklistKey)
require.NoError(t, err)
assert.True(t, hit, "key must remain blacklisted after a repeat revoke")
}
Expand All @@ -62,16 +62,16 @@ func TestBlacklistRefreshToken_RevokeExtendsTTL(t *testing.T) {
c, mr := testClient(t)
ctx := context.Background()

const tokenHash = "rt-hash-extend"
const blacklistKey = "rt-hash-extend"
// Initial revoke with a 2s TTL.
require.NoError(t, c.BlacklistRefreshToken(ctx, tokenHash, 2*time.Second))
require.NoError(t, c.BlacklistRefreshToken(ctx, blacklistKey, 2*time.Second))
// Fast-forward 1s, then revoke again — the second call must reset the TTL.
mr.FastForward(1 * time.Second)
require.NoError(t, c.BlacklistRefreshToken(ctx, tokenHash, 5*time.Second))
require.NoError(t, c.BlacklistRefreshToken(ctx, blacklistKey, 5*time.Second))
// Fast-forward 3s: original 2s TTL would have expired at t=2s, but the
// second revoke (at t=1s) reset it to 5s, so at t=4s the key must survive.
mr.FastForward(3 * time.Second)
hit, err := c.IsRefreshTokenBlacklisted(ctx, tokenHash)
hit, err := c.IsRefreshTokenBlacklisted(ctx, blacklistKey)
require.NoError(t, err)
assert.True(t, hit, "repeat revoke must extend the blacklist TTL past the original expiry")
}
Expand All @@ -82,17 +82,17 @@ func TestBlacklistRefreshToken_Expires(t *testing.T) {
c, mr := testClient(t)
ctx := context.Background()

const tokenHash = "rt-hash-expire"
require.NoError(t, c.BlacklistRefreshToken(ctx, tokenHash, 1*time.Second))
const blacklistKey = "rt-hash-expire"
require.NoError(t, c.BlacklistRefreshToken(ctx, blacklistKey, 1*time.Second))

// Present immediately.
hit, err := c.IsRefreshTokenBlacklisted(ctx, tokenHash)
hit, err := c.IsRefreshTokenBlacklisted(ctx, blacklistKey)
require.NoError(t, err)
assert.True(t, hit)

// Fast-forward past the TTL.
mr.FastForward(1100 * time.Millisecond)
hit, err = c.IsRefreshTokenBlacklisted(ctx, tokenHash)
hit, err = c.IsRefreshTokenBlacklisted(ctx, blacklistKey)
require.NoError(t, err)
assert.False(t, hit, "blacklist entry must expire after its TTL")
}
Expand Down
3 changes: 2 additions & 1 deletion hub-server/internal/handler/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/agenthub/hub-server/internal/metrics"
"github.com/agenthub/hub-server/internal/middleware"
"github.com/agenthub/hub-server/internal/safego"
"github.com/agenthub/hub-server/internal/ws"
)

Expand Down Expand Up @@ -103,7 +104,7 @@ func (h *WebSocketHandler) ServeWS(c *gin.Context) {
// seq_id=2 because auth.ok now consumes seq_id=1.
go h.writeLoop(conn)
h.manager.PushToConn(conn.ID, ws.NewFrame(ws.TypeAuthOK, nil))
middleware.SafeGo("ws.readLoop", func() {
safego.SafeGo("ws.readLoop", func() {
h.authenticatedReadLoop(conn)
})
}
Expand Down
2 changes: 1 addition & 1 deletion hub-server/internal/repository/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func FindActivePendingTaskByAgentInstance(db *gorm.DB, agentInstanceID string) (
// row-level FOR UPDATE lock; the SQLite fallback performs a no-op write so
// integration tests exercise a real write lock. Mirrors LockTeamRunForUpdate (#1383).
func LockAgentInstanceForUpdate(db *gorm.DB, agentInstanceID string) error {
if db.Dialector.Name() == "postgres" {
if db.Name() == "postgres" {
var id string
if err := db.Raw("SELECT id FROM agent_instances WHERE id = ? FOR UPDATE", agentInstanceID).Scan(&id).Error; err != nil {
return err
Expand Down
Loading
Loading