Permalink
Browse files

add ssl specs

  • Loading branch information...
1 parent 469578d commit dba0fde9fdc3b4e239e425a0a285cdcbadf40dde @leafo committed Jun 29, 2016
Showing with 98 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +43 −0 spec/pgmoon_ssl_spec.moon
  3. +53 −0 spec/postgres.sh
View
@@ -1,3 +1,4 @@
.tup
logs/
-nginx.conf.compiled
+nginx.conf.compiled
+pgdata
@@ -0,0 +1,43 @@
+import Postgres from require "pgmoon"
+
+HOST = "127.0.0.1"
+PORT = "9999"
+USER = "postgres"
+DB = "pgmoon_test"
+
+describe "pgmoon with server", ->
+ local pg
+
+ setup ->
+ os.execute "spec/postgres.sh start"
+
+ teardown ->
+ os.execute "spec/postgres.sh stop"
+
+ it "connects without ssl on ssl server", ->
+ pg = Postgres {
+ database: DB
+ port: PORT
+ user: USER
+ host: HOST
+ }
+ assert pg\connect!
+ assert pg\query "select * from information_schema.tables"
+ pg\disconnect!
+
+ it "connects with ssl on ssl server", ->
+ pg = Postgres {
+ database: DB
+ port: PORT
+ user: USER
+ host: HOST
+ ssl: true
+ ssl_required: true
+ }
+
+ assert pg\connect!
+ pg\query "select * from information_schema.tables"
@thibaultcha
thibaultcha Jun 29, 2016 Contributor

Are we missing an assert here?

+ pg\disconnect!
+
+
+
View
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+pgroot=$(pwd)/pgdata
+port=9999
+
+function makecerts {
+ # https://www.postgresql.org/docs/9.5/static/ssl-tcp.html
+ (
+ cd $pgroot
+
+ openssl req -new -passout pass:itchzone -text -out server.req -subj "/C=US/ST=Leafo/L=Leafo/O=Leafo/CN=itch.zone"
+ openssl rsa -passin pass:itchzone -in privkey.pem -out server.key
+ rm privkey.pem
+ openssl req -x509 -in server.req -text -key server.key -out server.crt
+ chmod og-rwx server.key
+ )
+}
+
+function start {
+ [ -d "${pgroot}" ] && rm -rf $pgroot
+ initdb --locale 'en_US.UTF-8' -E 'UTF8' -A 'trust' -D $pgroot
+
+ # install ssl
+ makecerts
+
+ echo "
+ssl = on
+ssl_cert_file = '${pgroot}/server.crt'
+ssl_key_file = '${pgroot}/server.key'
+# ssl_ca_file = ''
+# ssl_crl_file = ''
+ " >> $pgroot/postgresql.conf
+
+ postgresql-check-db-dir $pgroot
+ PGPORT=$port pg_ctl -s -o '-k /tmp' -D $pgroot start -w
+ createuser -h localhost -p $port postgres
+ createdb -h localhost -p $port pgmoon_test
+}
+
+function stop {
+ pg_ctl -s -D $pgroot stop -m fast
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ *)
+ echo "usage: spec/postgres.sh {start|stop}"
+esac

0 comments on commit dba0fde

Please sign in to comment.