Skip to content

Commit ece2377

Browse files
update
Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
1 parent b8155f4 commit ece2377

4 files changed

Lines changed: 11 additions & 29 deletions

File tree

e2e-tests/container-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@ if [[ "$DEPLOYMENT_EXIT_CODE" -ne 0 ]]; then
184184
exit $DEPLOYMENT_EXIT_CODE
185185
fi
186186

187-
# Container will exit and local-run.sh will show next steps
187+
# Container will exit and local-run.sh will show next steps

e2e-tests/playwright/e2e/plugin-division-mode-schema/schema-mode-db.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
import { expect } from "@playwright/test";
77
import { Client } from "pg";
8-
import { quoteIdent } from "../../utils/postgres-config";
98

10-
export { quoteIdent } from "../../utils/postgres-config";
9+
/** Quote a PostgreSQL identifier (safe against injection in dynamic SQL). */
10+
function quoteIdent(name: string): string {
11+
return '"' + String(name).replace(/"/g, '""') + '"';
12+
}
1113

1214
/** Escape a string for use inside PostgreSQL single-quoted literal (doubles single quotes). */
1315
function escapePasswordLiteral(value: string): string {

e2e-tests/playwright/utils/kube-client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,7 @@ export class KubeClient {
511511

512512
/**
513513
* Create or update a Kubernetes secret (upsert pattern).
514-
* Replaces the secret's data entirely so that keys not in secret.data are removed
515-
* (avoids stale keys when switching e.g. from SSL to non-SSL).
514+
* Tries to update the secret first; if it doesn't exist, creates it.
516515
*/
517516
async createOrUpdateSecret(
518517
secret: k8s.V1Secret,

e2e-tests/playwright/utils/postgres-config.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ function unescapeNewlines(value: string): string {
2222
return value.replace(/\\n/g, "\n");
2323
}
2424

25-
/**
26-
* Quote a PostgreSQL identifier (safe against injection).
27-
* Use for database, schema, and role names in dynamic SQL.
28-
*/
29-
export function quoteIdent(name: string): string {
30-
return '"' + String(name).replace(/"/g, '""') + '"';
31-
}
32-
3325
/**
3426
* Read certificate content from a file path.
3527
* @param filePath - Path to the certificate file
@@ -82,24 +74,15 @@ export async function configurePostgresCredentials(
8274
sslMode?: string;
8375
},
8476
): Promise<void> {
85-
const sslMode = credentials.sslMode || "require";
8677
const data: Record<string, string> = {
8778
POSTGRES_HOST: Buffer.from(credentials.host).toString("base64"),
8879
POSTGRES_PORT: Buffer.from(credentials.port || "5432").toString("base64"),
89-
PGSSLMODE: Buffer.from(sslMode).toString("base64"),
80+
PGSSLMODE: Buffer.from(credentials.sslMode || "require").toString("base64"),
81+
NODE_EXTRA_CA_CERTS: Buffer.from(
82+
"/opt/app-root/src/postgres-crt.pem",
83+
).toString("base64"),
9084
};
9185

92-
// In-cluster path where RHDH reads the mounted postgres TLS bundle (override via POSTGRES_NODE_EXTRA_CA_CERTS).
93-
const nodeExtraCaCerts =
94-
process.env.POSTGRES_NODE_EXTRA_CA_CERTS ||
95-
"/opt/app-root/src/postgres-crt.pem";
96-
// Only set certificate path when SSL is enabled. When disable, we omit
97-
// NODE_EXTRA_CA_CERTS; createOrUpdateSecret replaces secret data entirely
98-
// so a previously set value is removed.
99-
if (sslMode !== "disable") {
100-
data.NODE_EXTRA_CA_CERTS = Buffer.from(nodeExtraCaCerts).toString("base64");
101-
}
102-
10386
if (credentials.user) {
10487
data.POSTGRES_USER = Buffer.from(credentials.user).toString("base64");
10588
}
@@ -203,9 +186,7 @@ export async function clearDatabase(credentials: {
203186
for (let attempt = 1; attempt <= maxRetries; attempt++) {
204187
try {
205188
// WITH (FORCE) atomically terminates connections and drops the database
206-
await client.query(
207-
`DROP DATABASE IF EXISTS ${quoteIdent(db)} WITH (FORCE)`,
208-
);
189+
await client.query(`DROP DATABASE IF EXISTS "${db}" WITH (FORCE)`);
209190
success = true;
210191
break;
211192
} catch (error) {

0 commit comments

Comments
 (0)