Skip to content

Commit

Permalink
refactor: move test SSLs to a package
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jan 3, 2025
1 parent f4607f5 commit 596e0c3
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 4 deletions.
22 changes: 22 additions & 0 deletions packages/test-ssls/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM postgres:16

RUN mkdir -p /etc/postgresql/certs && chown postgres:postgres /etc/postgresql/certs

# Copy the SSL certificates into the container
COPY root.crt /etc/postgresql/certs/root.crt
COPY slonik.key /etc/postgresql/certs/server.key
COPY slonik.crt /etc/postgresql/certs/server.crt


RUN chmod 600 /etc/postgresql/certs/server.key && \
chmod 644 /etc/postgresql/certs/server.crt /etc/postgresql/certs/root.crt && \
chown postgres:postgres /etc/postgresql/certs/*

RUN echo "ssl = on" >> /usr/share/postgresql/postgresql.conf.sample && \
echo "ssl_cert_file = '/etc/postgresql/certs/server.crt'" >> /usr/share/postgresql/postgresql.conf.sample && \
echo "ssl_key_file = '/etc/postgresql/certs/server.key'" >> /usr/share/postgresql/postgresql.conf.sample && \
echo "ssl_ca_file = '/etc/postgresql/certs/root.crt'" >> /usr/share/postgresql/postgresql.conf.sample

EXPOSE 5432

USER postgres
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Test SSLs

SSLs used for testing Slonik.

## Generating SSL certificates

```bash
# Generate a Root Certificate (CA)
openssl genrsa -out root.key 2048
Expand All @@ -14,4 +20,11 @@ openssl x509 -req -in slonik.csr -CA root.crt -CAkey root.key -CAcreateserial -o

# Verify the Certificates
openssl verify -CAfile root.crt slonik.crt
```

## Running PostgreSQL with SSL

```bash
docker build -t slonik-ssl-test .
docker run --name slonik-ssl-test --rm -it -e POSTGRES_PASSWORD=postgres -p 5433:5432 slonik-ssl-test
```
21 changes: 21 additions & 0 deletions packages/test-ssls/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"author": {
"email": "[email protected]",
"name": "Gajus Kuizinas",
"url": "http://gajus.com"
},
"description": "SSLs used for testing Slonik.",
"engines": {
"node": ">=18"
},
"license": "BSD-3-Clause",
"name": "@slonik/test-ssls",
"peerDependencies": {
"zod": "^3"
},
"repository": {
"type": "git",
"url": "https://github.com/gajus/slonik"
},
"version": "46.2.0"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions packages/utilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"description": "A Node.js PostgreSQL client with strict types, detailed logging and assertions.",
"devDependencies": {
"@slonik/eslint-config": "workspace:^",
"@slonik/test-ssls": "workspace:^",
"@types/node": "^22.9.0",
"ava": "^6.1.3",
"cspell": "^8.16.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/utilities/src/utilities/parseDsn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ test('postgresql:///database-name?host=/var/lib/postgresql', testParse, {
host: '/var/lib/postgresql',
});

const sslCaCertPath = resolve(__dirname, './fixtures/ssl/root.crt');
const sslCertPath = resolve(__dirname, './fixtures/ssl/slonik.crt');
const sslKeyPath = resolve(__dirname, './fixtures/ssl/slonik.key');
const sslCaCertPath = require.resolve('@slonik/test-ssls/root.crt');
const sslCertPath = require.resolve('@slonik/test-ssls/slonik.crt');
const sslKeyPath = require.resolve('@slonik/test-ssls/slonik.key');

test(`postgresql://?sslcert=${sslCertPath}&sslkey=${sslKeyPath}`, testParse, {
ssl: {
Expand Down
11 changes: 10 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 596e0c3

Please sign in to comment.