]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/live_t/lp1468422_passwd_storage.pg
LP#1673059: Update passwd storage test
[working/Evergreen.git] / Open-ILS / src / sql / Pg / live_t / lp1468422_passwd_storage.pg
1 \set ECHO none
2 \set QUIET 1
3 -- Turn off echo and keep things quiet.
4
5 -- Format the output for nice TAP.
6 \pset format unaligned
7 \pset tuples_only true
8 \pset pager
9
10 -- Revert all changes on failure.
11 \set ON_ERROR_ROLLBACK 1
12 \set ON_ERROR_STOP true
13 \set QUIET 1
14
15 BEGIN;
16
17 -- Plan the tests.
18 SELECT plan(6);
19
20 SELECT ok(
21     (SELECT TRUE AS verify_old_pw FROM actor.usr 
22         WHERE id = 189 AND passwd = MD5('montyc1234')),
23     'Legacy password should match'
24 );
25
26 SELECT isnt_empty(
27     'SELECT actor.get_salt(189, ''main'')',
28     'get_salt() returns a new salt'
29 );
30
31 SELECT isnt_empty(
32     'SELECT * FROM actor.passwd WHERE usr = 189 AND passwd_type = ''main''',
33     'get_salt() should migrate the password'
34 );
35
36 SELECT ok(
37     (SELECT actor.verify_passwd(189, 'main', 
38         MD5(actor.get_salt(189, 'main') || MD5('montyc1234')))),
39     'verify_passwd should verify migrated password'
40 );
41
42 SELECT ok(
43     (SELECT NOT (
44         SELECT actor.verify_passwd(189, 'main', 
45             MD5(actor.get_salt(189, 'main') || MD5('BADPASSWORD'))))
46     ),
47     'verify_passwd should fail with wrong password'
48 );
49
50 -- This code chunk mimics the application changing a user's password
51 DO $$
52     DECLARE new_salt TEXT;
53 BEGIN
54     -- we have to capture the salt, because subsequent 
55     -- calls will create a new one.
56     SELECT INTO new_salt actor.create_salt('main');
57     PERFORM actor.set_passwd(
58         189, 'main', MD5(new_salt || MD5('bobblehead')), new_salt);
59 END $$;
60
61 SELECT ok(
62     (SELECT actor.verify_passwd(189, 'main', 
63         MD5(actor.get_salt(189, 'main') || MD5('bobblehead')))),
64     'verify_passwd should verify new password'
65 );
66
67 -- Finish the tests and clean up.
68 SELECT * FROM finish();
69
70 ROLLBACK;
71