Compare commits

..
3 Commits
Author SHA1 Message Date
warkanum dab4940ace fix(security): DatabaseAuthenticator.RefreshToken surfaces rotated refresh token and expiry
Tests / Unit Tests (push) Failing after 13s
Tests / Integration Tests (push) Failing after 27s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 33s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 35s
Build , Vet Test, and Lint / Build (push) Successful in 35s
Build , Vet Test, and Lint / Lint Code (push) Successful in 39s
RefreshToken() hardcoded LoginResponse{Token: userCtx.SessionID, ExpiresIn: 24h}
and silently discarded anything else resolvespec_refresh_token returned. An
implementation that issues its own independent, rotating refresh token (not
just reusing the session/access token as its own refresh token) has nowhere
else to put the new refresh token and real access-token expiry than
UserContext.Claims, since UserContext has no dedicated fields for either.

Now reads claims.refresh_token/claims.expires_in when present and surfaces
them into LoginResponse.RefreshToken/ExpiresIn. Implementations that don't
set these claims keep today's behavior unchanged (empty RefreshToken, 24h
ExpiresIn default) — purely additive, no breaking change.
2026-08-27 21:51:16 +02:00
Hein c7178e0a2b fix(parameters): increase default limit for requests
Tests / Integration Tests (push) Failing after 3m24s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 4m13s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 3m17s
Build , Vet Test, and Lint / Lint Code (push) Failing after 4m51s
Tests / Unit Tests (push) Failing after 5m23s
Build , Vet Test, and Lint / Build (push) Successful in 4m14s
2026-08-25 15:50:09 +02:00
warkanum 0261f121e8 fix(security): change types for template and hasBlock
Tests / Unit Tests (push) Failing after 19s
Tests / Integration Tests (push) Failing after 30s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Failing after 39s
Build , Vet Test, and Lint / Build (push) Successful in 3m47s
Build , Vet Test, and Lint / Lint Code (push) Successful in 3m45s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 3m47s
2026-08-10 20:46:40 +02:00
3 changed files with 66 additions and 7 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ func (h *Handler) ParseParameters(r *http.Request) *RequestParameters {
FieldFilters: make(map[string]string),
SearchFilters: make(map[string]string),
SearchOps: make(map[string]FilterOperator),
Limit: 20, // Default limit
Limit: 100000, // Default limit
Offset: 0, // Default offset
ResponseFormat: "simple", // Default format
ComplexAPI: false, // Default to simple API
+22 -6
View File
@@ -551,11 +551,27 @@ func (a *DatabaseAuthenticator) RefreshToken(ctx context.Context, refreshToken s
return nil, fmt.Errorf("failed to parse user context: %w", err)
}
return &LoginResponse{
// A resolvespec_refresh_token implementation that issues its own rotating
// refresh token (independent of the access/session token) returns it
// under claims.refresh_token, since UserContext has no dedicated field
// for it. Surface that into LoginResponse.RefreshToken so callers don't
// need to reach into User.Claims themselves. claims.expires_in
// (seconds) similarly overrides the default access-token ExpiresIn when
// the procedure provides a real value. Implementations that don't set
// these claims keep today's behavior unchanged (empty RefreshToken,
// 24h ExpiresIn default).
resp := &LoginResponse{
Token: userCtx.SessionID, // New session token from stored procedure
User: &userCtx,
ExpiresIn: int64(24 * time.Hour.Seconds()),
}, nil
}
if refreshToken, ok := userCtx.Claims["refresh_token"].(string); ok && refreshToken != "" {
resp.RefreshToken = refreshToken
}
if expiresIn, ok := userCtx.Claims["expires_in"].(float64); ok && expiresIn > 0 {
resp.ExpiresIn = int64(expiresIn)
}
return resp, nil
}
// JWTAuthenticator provides JWT token-based authentication
@@ -924,8 +940,8 @@ func (p *DatabaseRowSecurityProvider) GetRowSecurity(ctx context.Context, userRe
userRef = v.UserID
}
var template string
var hasBlock bool
var template sql.NullString
var hasBlock sql.NullBool
runQuery := func() error {
query := fmt.Sprintf(`SELECT p_template, p_block FROM %s($1, $2, $3)`, p.sqlNames.RowSecurity)
@@ -945,8 +961,8 @@ func (p *DatabaseRowSecurityProvider) GetRowSecurity(ctx context.Context, userRe
Schema: schema,
Tablename: table,
UserID: userRef,
Template: template,
HasBlock: hasBlock,
Template: template.String,
HasBlock: hasBlock.Bool,
}, nil
}
+43
View File
@@ -793,6 +793,49 @@ func TestDatabaseAuthenticatorRefreshToken(t *testing.T) {
t.Errorf("unfulfilled expectations: %v", err)
}
})
// A resolvespec_refresh_token implementation that rotates its own
// independent refresh token (not just reusing the session/access token)
// has nowhere else to put the new refresh token and real access-token
// expiry than under UserContext.Claims, since UserContext has no
// dedicated fields for either. RefreshToken must surface those claims
// keys into LoginResponse.RefreshToken/ExpiresIn rather than silently
// dropping them (see the "successful token refresh" case above, which
// covers an implementation that has no independent refresh token at all
// and gets the 24h default instead).
t.Run("surfaces rotated refresh token and expiry from claims", func(t *testing.T) {
refreshToken := "refresh-token-abc"
sessionRows := sqlmock.NewRows([]string{"p_success", "p_error", "p_user"}).
AddRow(true, nil, `{"user_id":1,"user_name":"testuser"}`)
mock.ExpectQuery(`SELECT p_success, p_error, p_user::text FROM resolvespec_session`).
WithArgs(refreshToken, "refresh").
WillReturnRows(sessionRows)
refreshRows := sqlmock.NewRows([]string{"p_success", "p_error", "p_user"}).
AddRow(true, nil, `{"user_id":1,"user_name":"testuser","session_id":"new-access-789","claims":{"refresh_token":"new-refresh-def","expires_in":900}}`)
mock.ExpectQuery(`SELECT p_success, p_error, p_user::text FROM resolvespec_refresh_token`).
WithArgs(refreshToken, sqlmock.AnyArg()).
WillReturnRows(refreshRows)
resp, err := auth.RefreshToken(ctx, refreshToken)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
if resp.Token != "new-access-789" {
t.Errorf("expected token new-access-789, got %s", resp.Token)
}
if resp.RefreshToken != "new-refresh-def" {
t.Errorf("expected rotated refresh token new-refresh-def, got %q", resp.RefreshToken)
}
if resp.ExpiresIn != 900 {
t.Errorf("expected ExpiresIn 900 from claims, got %d", resp.ExpiresIn)
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("unfulfilled expectations: %v", err)
}
})
}
func TestDatabaseAuthenticatorReconnectsClosedDBPaths(t *testing.T) {