summaryrefslogtreecommitdiff
path: root/sql/modules/test/Session.sql
blob: 97520bd17bf0a816778bf1c2396d5344ce93d1f1 (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. values ('session1 retrieved',
  25. (select t.token = md5('test1')
  26. FROM session_check(
  27. currval('session_session_id_seq')::int,
  28. md5('test1')
  29. ) t )
  30. );
  31. INSERT INTO test_result (test_name, success)
  32. VALUES ('session 2 removed',
  33. (select count(*) from session where token = md5('test2') AND users_id = currval('users_id_seq')) = 0);
  34. DELETE FROM session WHERE users_id = currval('users_id_seq');
  35. DELETE FROM entity WHERE control_code = '_TESTING.....';
  36. SELECT * FROM test_result;
  37. SELECT (select count(*) from test_result where success is true)
  38. || ' tests passed and '
  39. || (select count(*) from test_result where success is not true)
  40. || ' failed' as message;
  41. DROP TABLE test_result;
  42. ROLLBACK;