hhorak / tests / postgresql

Forked from tests/postgresql 3 years ago
Clone
Blob Blame History Raw
#!/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 <hhorak@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   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 database/postgresql"
        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