Skip to content

Commit

Permalink
chore: add additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon committed Sep 27, 2024
1 parent a536813 commit d20f1ca
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function validateCertificate(
dnsName: string
) {
return (hostname: string, cert: tls.PeerCertificate): Error | undefined => {
if (serverCaMode == 'GOOGLE_MANAGED_CAS_CA') {
if (serverCaMode === 'GOOGLE_MANAGED_CAS_CA') {
return tls.checkServerIdentity(dnsName, cert);
}
if (!cert || !cert.subject) {
Expand Down
28 changes: 28 additions & 0 deletions system-test/pg-connect.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,31 @@ t.test('open IAM connection and retrieves standard pg tables', async t => {
await client.end();
connector.close();
});

t.test(
'open connection to CAS-based CA instance and retrieves standard pg tables',
async t => {
const connector = new Connector();
const clientOpts = await connector.getOptions({
instanceConnectionName: process.env.POSTGRES_CAS_CONNECTION_NAME,
ipType: 'PUBLIC',
authType: 'PASSWORD',
});
const client = new Client({
...clientOpts,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_CAS_PASS,
database: process.env.POSTGRES_DB,
});
client.connect();

const {
rows: [result],
} = await client.query('SELECT NOW();');
const returnedDate = result['now'];
t.ok(returnedDate.getTime(), 'should have valid returned date object');

await client.end();
connector.close();
}
);
28 changes: 28 additions & 0 deletions system-test/pg-connect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,31 @@ t.test('open IAM connection and retrieves standard pg tables', async t => {
await client.end();
connector.close();
});

t.test(
'open connection to CAS-based CA instance and retrieves standard pg tables',
async t => {
const connector = new Connector();
const clientOpts = await connector.getOptions({
instanceConnectionName: process.env.POSTGRES_CAS_CONNECTION_NAME,
ipType: 'PUBLIC',
authType: 'PASSWORD',
});
const client = new Client({
...clientOpts,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_CAS_PASS,
database: process.env.POSTGRES_DB,
});
client.connect();

const {
rows: [result],
} = await client.query('SELECT NOW();');
const returnedDate = result['now'];
t.ok(returnedDate.getTime(), 'should have valid returned date object');

await client.end();
connector.close();
}
);

0 comments on commit d20f1ca

Please sign in to comment.