72 lines
2.4 KiB
MySQL
72 lines
2.4 KiB
MySQL
|
-- Test logout
|
||
|
set client_min_messages to warning;
|
||
|
create extension if not exists pgtap;
|
||
|
reset client_min_messages;
|
||
|
|
||
|
begin;
|
||
|
|
||
|
select plan(15);
|
||
|
|
||
|
set search_path to auth, numerus, public;
|
||
|
|
||
|
select has_function('logout');
|
||
|
select function_lang_is('logout', array []::text[], 'sql');
|
||
|
select function_returns('logout', array []::text[], 'void');
|
||
|
select is_definer('logout', array []::text[]);
|
||
|
select volatility_is('logout', array []::text[], 'volatile');
|
||
|
select function_privs_are('logout', array []::text[], 'guest', array []::text[]);
|
||
|
select function_privs_are('logout', array []::text[], 'invoicer', array ['EXECUTE']);
|
||
|
select function_privs_are('logout', array []::text[], 'admin', array ['EXECUTE']);
|
||
|
select function_privs_are('logout', array []::text[], 'authenticator', array []::text[]);
|
||
|
|
||
|
set client_min_messages to warning;
|
||
|
truncate auth."user" cascade;
|
||
|
reset client_min_messages;
|
||
|
|
||
|
insert into auth."user" (email, name, password, role, cookie, cookie_expires_at)
|
||
|
values ('info@tandem.blog', 'Tandem', 'test', 'invoicer', '8c23d4a8d777775f8fc507676a0d99d3dfa54b03b1b257c838', current_timestamp + interval '1 day')
|
||
|
, ('admin@tandem.blog', 'Admin', 'test', 'admin', '0169e5f668eec1e6749fd25388b057997358efa8dfd697961a', current_timestamp + interval '2 day')
|
||
|
;
|
||
|
|
||
|
prepare user_cookies as
|
||
|
select cookie, cookie_expires_at from "user" order by user_id
|
||
|
;
|
||
|
|
||
|
select set_config('request.user', 'nothing', false);
|
||
|
select lives_ok( $$ select * from logout() $$, 'Can logout “nobody”' );
|
||
|
|
||
|
select results_eq(
|
||
|
'user_cookies',
|
||
|
$$ values ('8c23d4a8d777775f8fc507676a0d99d3dfa54b03b1b257c838', current_timestamp + interval '1 day')
|
||
|
, ('0169e5f668eec1e6749fd25388b057997358efa8dfd697961a', current_timestamp + interval '2 day')
|
||
|
$$,
|
||
|
'Nothing changed'
|
||
|
);
|
||
|
|
||
|
select set_config('request.user', 'info@tandem.blog', false);
|
||
|
select lives_ok( $$ select * from logout() $$, 'Can logout the first user' );
|
||
|
|
||
|
select results_eq(
|
||
|
'user_cookies',
|
||
|
$$ values ('', '-infinity'::timestamptz)
|
||
|
, ('0169e5f668eec1e6749fd25388b057997358efa8dfd697961a'::text, current_timestamp + interval '2 day')
|
||
|
$$,
|
||
|
'The first user logged out'
|
||
|
);
|
||
|
|
||
|
select set_config('request.user', 'admin@tandem.blog', false);
|
||
|
select lives_ok( $$ select * from logout() $$, 'Can logout the second user' );
|
||
|
|
||
|
select results_eq(
|
||
|
'user_cookies',
|
||
|
$$ values ('', '-infinity'::timestamptz)
|
||
|
, ('', '-infinity'::timestamptz)
|
||
|
$$,
|
||
|
'The second user logged out'
|
||
|
);
|
||
|
|
||
|
select *
|
||
|
from finish();
|
||
|
|
||
|
rollback;
|