diff --git a/Sanity/pgaudit/main.fmf b/Sanity/pgaudit/main.fmf new file mode 100644 index 0000000..70f13b8 --- /dev/null +++ b/Sanity/pgaudit/main.fmf @@ -0,0 +1,26 @@ +summary: Sanity test for pgaudit extension +description: '' +contact: Vaclav Danek +component: +- postgresql +test: ./runtest.sh +path: /Sanity/pgaudit +framework: beakerlib +require: +- url: https://github.com/beakerlib/database.git + name: /postgresql + ref: master +recommend: +- postgresql-server +- pgaudit +duration: 5m +enabled: true +tag: +- NoRHEL4 +- NoRHEL5 +- NoRHEL6 +- TIPfail +- TIPfail_Apps +- Tier1 +tier: '1' +extra-task: /CoreOS/postgresql/Sanity/pgaudit diff --git a/Sanity/pgaudit/runtest.sh b/Sanity/pgaudit/runtest.sh new file mode 100755 index 0000000..a4cc1e7 --- /dev/null +++ b/Sanity/pgaudit/runtest.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/postgresql/Sanity/pgaudit +# Description: Sanity test for pgaudit extension +# Author: Honza Horak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="postgresql" +PACKAGE_AUDIT="pgaudit" + +rlJournalStart + rlPhaseStart FAIL "Setup" + rlRun "rlImport postgresql/basic" + PGDATA="$(postgresqlGetDataDir)"; + PACKAGES="$PACKAGES ${postgresqlPackagePrefix}${PACKAGE_AUDIT} \ + ${postgresqlPackagePrefix}${PACKAGE} \ + ${postgresqlPackagePrefix}${PACKAGE}-server"; + for PACKAGE in $PACKAGES; do + rlAssertRpm $PACKAGE + done + rlRun "postgresqlStop"; + [[ -d ${postgresqlDataDir} ]] && rlFileBackup "${postgresqlDataDir}" + rlRun "postgresqlCleanup" + rlRun "postgresqlStart" + rlRun "sed -i -e \"s/#shared_preload_libraries = ''/shared_preload_libraries = 'pgaudit'/\" ${PGDATA}/postgresql.conf" 0 "Adding pgaudit to the shared_preload_libraries in the config file ..." + rlRun "postgresqlStop"; + rlRun "postgresqlStart" + rlPhaseEnd + + rlPhaseStartTest + rlRun "postgresqlQuery \"DROP EXTENSION IF EXISTS pgaudit;\""; + rlRun "postgresqlQuery \"CREATE EXTENSION pgaudit;\"" 0; + rlRun "postgresqlQuery \"SET pgaudit.log = 'read, ddl'; + DROP TABLE IF EXISTS account; + CREATE TABLE account (id int, name text, password text, description text); + INSERT INTO account (id, name, password, description) VALUES (1, 'user1', 'HASH1', 'blah, blah');\"" 0; + rlRun "postgresqlQuery \"SELECT * FROM account;\"" 0; + rlAssertGrep 'AUDIT: SESSION,.*,.*,DDL,DROP TABLE,,,DROP TABLE IF EXISTS account' ${postgresqlLogDir}/postgresql*.log -E + rlAssertGrep 'AUDIT: SESSION,.*,.*,DDL,CREATE TABLE,TABLE,public.account,"CREATE TABLE account' ${postgresqlLogDir}/postgresql*.log -E +cat ${postgresqlLogDir}/postgresql*.log + rlRun "postgresqlQuery \"DROP TABLE IF EXISTS account;\"" 0; + rlRun "postgresqlQuery \"DROP EXTENSION IF EXISTS pgaudit;\""; + rlPhaseEnd + + rlPhaseStart WARN "Cleanup"; + rm -f $rlRun_LOG; + rlRun "postgresqlCleanup"; + rlFileRestore; + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/Sanity/postgres-decoderbufs/main.fmf b/Sanity/postgres-decoderbufs/main.fmf new file mode 100644 index 0000000..281e830 --- /dev/null +++ b/Sanity/postgres-decoderbufs/main.fmf @@ -0,0 +1,26 @@ +summary: Sanity test for postgres-decoderbufs plugin +description: '' +contact: Vaclav Danek +component: +- postgresql +test: ./runtest.sh +path: /Sanity/postgres-decoderbufs +framework: beakerlib +require: +- url: https://github.com/beakerlib/database.git + name: /postgresql + ref: master +recommend: +- postgresql-server +- postgres-decoderbufs +duration: 5m +enabled: true +tag: +- NoRHEL4 +- NoRHEL5 +- NoRHEL6 +- TIPfail +- TIPfail_Apps +- Tier1 +tier: '1' +extra-task: /CoreOS/postgresql/Sanity/postgres-decoderbufs diff --git a/Sanity/postgres-decoderbufs/runtest.sh b/Sanity/postgres-decoderbufs/runtest.sh new file mode 100755 index 0000000..225c957 --- /dev/null +++ b/Sanity/postgres-decoderbufs/runtest.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/postgresql/Sanity/postgres-decoderbufs +# Description: Sanity test for postgres-decoderbufs plugin +# Author: Jiri Pechanec +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="postgresql" +PACKAGE_DECODERBUFS="postgres-decoderbufs" + +rlJournalStart + rlPhaseStart FAIL "Setup" + rlRun "rlImport postgresql/basic" + PGDATA="$(postgresqlGetDataDir)"; + PACKAGES="$PACKAGES ${postgresqlPackagePrefix}${PACKAGE_DECODERBUFS} \ + ${postgresqlPackagePrefix}${PACKAGE} \ + ${postgresqlPackagePrefix}${PACKAGE}-server"; + for PACKAGE in $PACKAGES; do + rlAssertRpm $PACKAGE + done + rlRun "postgresqlStop"; + [[ -d ${postgresqlDataDir} ]] && rlFileBackup "${postgresqlDataDir}" + rlRun "postgresqlCleanup" + rlRun "postgresqlStart" + rlRun "sed -i -e \"s/#shared_preload_libraries = ''/shared_preload_libraries = 'decoderbufs'/\" ${PGDATA}/postgresql.conf" 0 "Adding decoderbufs to the shared_preload_libraries in the config file ..." + rlRun "sed -i -e \"s/#wal_level = replica/wal_level = logical/\" ${PGDATA}/postgresql.conf" 0 "Configuring wal_level to logical..." + rlRun "postgresqlStop"; + rlRun "postgresqlStart" + rlPhaseEnd + + rlPhaseStartTest + rlRun "postgresqlQuery \"DROP TABLE IF EXISTS streaming_table;\""; + rlRun "postgresqlQuery \"CREATE TABLE streaming_table (id int, name varchar(32));\"" 0; + rlRun "postgresqlQuery \"SELECT * FROM pg_drop_replication_slot('test');\"" 0,3; + rlRun "postgresqlQuery \"SELECT * FROM pg_create_logical_replication_slot('test', 'decoderbufs');\"" 0; + rlRun "postgresqlQuery \"INSERT INTO streaming_table VALUES (1, 'myname');\"" 0; + rlRun -s "postgresqlQuery \"SELECT data FROM pg_logical_slot_peek_changes('test', NULL, 1, 'debug-mode', 'true');\"" 0; + rlAssertGrep 'column_name\[id\], column_type\[23\], datum\[1\]' $rlRun_LOG -E + rlRun "postgresqlQuery \"DROP TABLE IF EXISTS streaming_table;\"" 0; + rlRun "postgresqlQuery \"SELECT * FROM pg_drop_replication_slot('test');\"" 0; + rlPhaseEnd + + rlPhaseStart WARN "Cleanup"; + rm -f $rlRun_LOG; + rlRun "postgresqlCleanup"; + rlFileRestore; + rlPhaseEnd +rlJournalPrintText +rlJournalEnd