summaryrefslogtreecommitdiff
path: root/sql/modules/test/Session.sql
blob: bfcd37eb77cbd51c39ab5d9ce18448f76c377600 (plain)
  1. BEGIN;
  2. \i Base.sql
  3. INSERT INTO test_result (test_name, success)
  4. values ('timeout set',
  5. (select count(*) from defaults where setting_key = 'timeout') = 1);
  6. INSERT INTO entity (name, entity_class, control_code)
  7. VALUES ('Testing.....', 3, '_TESTING.....');
  8. INSERT INTO users (entity_id, username)
  9. SELECT currval('entity_id_seq'), CURRENT_USER;
  10. INSERT INTO session (users_id, last_used, token, transaction_id)
  11. SELECT currval('users_id_seq'),
  12. now() - coalesce((select value from defaults where setting_key = 'timeout')::interval,
  13. '90 minutes'::interval),
  14. md5('test2'), 2;
  15. INSERT INTO session (users_id, last_used, token, transaction_id)
  16. SELECT currval('users_id_seq'),
  17. now() - coalesce((select value from defaults where setting_key = 'timeout')::interval,
  18. '2 days'::interval),
  19. md5('test3'), 3;
  20. select * from session_check(currval('session_session_id_seq')::int, md5('test1'));
  21. INSERT INTO session (users_id, last_used, token, transaction_id)
  22. SELECT currval('users_id_seq'), now(), md5('test1'), 1;
  23. INSERT INTO test_result (test_name, success)
  24. SELECT 'records exist in transactions table', count(*) > 0 FROM transactions;
  25. INSERT INTO test_result (test_name, success)
  26. SELECT 'unlock record fails when record is not locked', unlock(max(id)) IS FALSE
  27. FROM transactions;
  28. INSERT INTO test_result (test_name, success)
  29. SELECT 'lock record', lock_record(max(id), currval('session_session_id_seq')::int)
  30. FROM transactions WHERE locked_by IS NULL;
  31. INSERT INTO test_result (test_name, success)
  32. SELECT 'unlock record', unlock(max(id))
  33. FROM transactions WHERE locked_by = currval('session_session_id_seq')::int;
  34. INSERT INTO test_result (test_name, success)
  35. SELECT 'lock all record', bool_and(lock_record(id, currval('session_session_id_seq')::int))
  36. FROM transactions WHERE locked_by IS NULL;
  37. INSERT INTO test_result (test_name, success)
  38. SELECT 'unlock all records', unlock_all();
  39. INSERT INTO test_result (test_name, success)
  40. values ('session1 retrieved',
  41. (select t.token = md5('test1')
  42. FROM session_check(
  43. currval('session_session_id_seq')::int,
  44. md5('test1')
  45. ) t )
  46. );
  47. INSERT INTO test_result (test_name, success)
  48. VALUES ('session 2 removed',
  49. (select count(*) from session where token = md5('test2') AND users_id = currval('users_id_seq')) = 0);
  50. SELECT * FROM test_result;
  51. SELECT (select count(*) from test_result where success is true)
  52. || ' tests passed and '
  53. || (select count(*) from test_result where success is not true)
  54. || ' failed' as message;
  55. ROLLBACK;