SQL logging fixes

* Added user mapping on the "remote" logging database for the
administrative user. This allows calls to sys.write_sql_log() to succeed
when they are executed by code with administrative privileges.

* Added test suites for both the link to the database and the function
itself.

* Replaced RAISE NOTICE with actual logging in the universe generator
This commit is contained in:
Emmanuel BENOîT 2012-01-07 11:14:17 +01:00
parent e50775ec76
commit 3e109b13bc
9 changed files with 177 additions and 64 deletions
legacyworlds-server-data/db-structure/tests/user
020-extensions
030-data/150-logs
040-functions/005-logs
priv/sys

View file

@ -0,0 +1,23 @@
/*
* Test the configuration of the dblink extension from the user's perspective
*/
BEGIN;
SELECT plan( 3 );
SELECT diag_test_name( 'dblink - Connection' );
SELECT lives_ok(
$$ SELECT dblink_connect( 'cn_logging' , 'srv_logging' ) $$
);
SELECT diag_test_name( 'dblink - Remote user = local user' );
SELECT is( username , current_user::TEXT )
FROM dblink( 'cn_logging' , 'SELECT current_user' )
AS ( username TEXT );
SELECT diag_test_name( 'dblink - Disconnection' );
SELECT lives_ok(
$$ SELECT dblink_disconnect( 'cn_logging' ) $$
);
SELECT * FROM finish( );
ROLLBACK;

View file

@ -0,0 +1,29 @@
/*
* Test privileges on sys.logs
*/
BEGIN;
SELECT plan( 4 );
SELECT diag_test_name( 'sys.logs - INSERT privileges' );
SELECT throws_ok(
$$ INSERT INTO sys.logs( component , level , message )
VALUES ( 'test' , 'WARNING'::log_level , 'test' );
$$ , 42501 );
SELECT diag_test_name( 'sys.logs - UPDATE privileges' );
SELECT throws_ok(
$$ UPDATE sys.logs SET component = 'retest'; $$ ,
42501 );
SELECT diag_test_name( 'sys.logs - SELECT privileges' );
SELECT lives_ok(
$$ SELECT * FROM sys.logs; $$
);
SELECT diag_test_name( 'sys.logs - DELETE privileges' );
SELECT throws_ok(
$$ DELETE FROM sys.logs; $$ ,
42501 );
SELECT * FROM finish( );
ROLLBACK;

View file

@ -0,0 +1,13 @@
/*
* Test the sys.write_sql_log( ) function
*/
BEGIN;
SELECT plan( 1 );
SELECT diag_test_name( 'sys.write_sql_log( ) - Privileges' );
SELECT lives_ok(
$$ SELECT sys.write_sql_log( 'test' , 'WARNING'::log_level , 'test' ) $$
);
SELECT * FROM finish( );
ROLLBACK;

View file

@ -1,39 +0,0 @@
BEGIN;
SELECT plan( 3 );
--
-- Insertion through sys.write_log()
--
CREATE OR REPLACE FUNCTION _test_this( )
RETURNS BIGINT
AS $$
SELECT sys.write_log( 'test' , 'WARNING'::log_level , 'test' );
$$ LANGUAGE SQL;
SELECT lives_ok( 'SELECT _test_this()' );
DROP FUNCTION _test_this( );
--
-- Direct insertion must fail
--
CREATE FUNCTION _test_this( )
RETURNS VOID
AS $$
INSERT INTO sys.logs( component , level , message )
VALUES ( 'test' , 'WARNING'::log_level , 'test' );
$$ LANGUAGE SQL;
SELECT throws_ok( 'SELECT _test_this()' , 42501 );
DROP FUNCTION _test_this( );
--
-- Updates must fail
--
CREATE OR REPLACE FUNCTION _test_this( )
RETURNS VOID
AS $$
UPDATE sys.logs SET component = 'random' WHERE component = 'test';
$$ LANGUAGE SQL;
SELECT throws_ok( 'SELECT _test_this()' , 42501 );
DROP FUNCTION _test_this( );
SELECT * FROM finish( );
ROLLBACK;