Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(tests): verify the privilege update and restore shared project state

Vlad Ligai95ffaffefe26
diff --git a/backend-go/tests/infra/stack.go b/backend-go/tests/infra/stack.go
index 0c32f1c390..48741205b8 100644
--- a/backend-go/tests/infra/stack.go
+++ b/backend-go/tests/infra/stack.go
@@ -4,6 +4,7 @@ package infra
import (
"context"
+ "fmt"
"log"
"os"
"testing"
@@ -34,13 +35,41 @@ func (s *Stack) DB() pg.DB { return s.db }
// EnableLegacyAdditionalPrivileges flips the project flag that additional
// privileges are gated on. New projects default to false and no route exposes
-// the column, so tests covering the legacy path have to set it directly.
+// the column, so tests covering the legacy path set it directly. The previous
+// value is restored on cleanup, since some packages share one project fixture.
func (s *Stack) EnableLegacyAdditionalPrivileges(t *testing.T, projectID string) {
t.Helper()
- if _, err := s.db.Primary().Exec(context.Background(),
- `UPDATE projects SET "isLegacyAdditionalPrivilegesEnabled" = true WHERE id = $1`, projectID); err != nil {
+ ctx := context.Background()
+
+ var previous bool
+ if err := s.db.Primary().QueryRow(ctx,
+ `SELECT "isLegacyAdditionalPrivilegesEnabled" FROM projects WHERE id = $1`, projectID,
+ ).Scan(&previous); err != nil {
+ t.Fatalf("infra.EnableLegacyAdditionalPrivileges: reading project %s: %v", projectID, err)
+ }
+
+ if err := s.setLegacyAdditionalPrivileges(ctx, projectID, true); err != nil {
t.Fatalf("infra.EnableLegacyAdditionalPrivileges: %v", err)
}
+
+ t.Cleanup(func() {
+ if err := s.setLegacyAdditionalPrivileges(ctx, projectID, previous); err != nil {
+ t.Errorf("infra.EnableLegacyAdditionalPrivileges cleanup: %v", err)
+ }
+ })
+}
+
+func (s *Stack) setLegacyAdditionalPrivileges(ctx context.Context, projectID string, enabled bool) error {
+ tag, err := s.db.Primary().Exec(ctx,
+ `UPDATE projects SET "isLegacyAdditionalPrivilegesEnabled" = $2 WHERE id = $1`, projectID, enabled)
+ if err != nil {
+ return err
+ }
+ // A stale or wrong ID updates nothing and would surface later as a confusing 400.
+ if n := tag.RowsAffected(); n != 1 {
+ return fmt.Errorf("expected 1 row updated for project %s, got %d", projectID, n)
+ }
+ return nil
}
// Stop tears down all containers, the network, and closes the DB pool.