LP#1468422 SQL upgrade extractions..
authorBill Erickson <berickxx@gmail.com>
Fri, 24 Jul 2015 15:27:01 +0000 (11:27 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 23 Nov 2015 16:25:29 +0000 (11:25 -0500)
Move test code to Pg/live_t (it assumes concerto).

Added pgcrypto to create_extensions file

Upgrade completes w/ a commit now

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/sql/Pg/create_database_extensions.sql
Open-ILS/src/sql/Pg/live_t/lp1468422_passwd_storage.pg [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.password-storage.sql

index b73a871..b61aa5b 100644 (file)
@@ -20,3 +20,4 @@ CREATE EXTENSION tablefunc;
 CREATE EXTENSION xml2;
 CREATE EXTENSION hstore;
 CREATE EXTENSION intarray;
+CREATE EXTENSION pgcrypto;
diff --git a/Open-ILS/src/sql/Pg/live_t/lp1468422_passwd_storage.pg b/Open-ILS/src/sql/Pg/live_t/lp1468422_passwd_storage.pg
new file mode 100644 (file)
index 0000000..30c8ad1
--- /dev/null
@@ -0,0 +1,71 @@
+\set ECHO none
+\set QUIET 1
+-- Turn off echo and keep things quiet.
+
+-- Format the output for nice TAP.
+\pset format unaligned
+\pset tuples_only true
+\pset pager
+
+-- Revert all changes on failure.
+\set ON_ERROR_ROLLBACK 1
+\set ON_ERROR_STOP true
+\set QUIET 1
+
+BEGIN;
+
+-- Plan the tests.
+SELECT plan(6);
+
+SELECT ok(
+    (SELECT TRUE AS verify_old_pw FROM actor.usr 
+        WHERE id = 187 AND passwd = MD5('montyc1234')),
+    'Legacy password should match'
+);
+
+SELECT isnt_empty(
+    'SELECT actor.get_salt(187, ''main'')',
+    'get_salt() returns a new salt'
+);
+
+SELECT isnt_empty(
+    'SELECT * FROM actor.passwd WHERE usr = 187 AND passwd_type = ''main''',
+    'get_salt() should migrate the password'
+);
+
+SELECT ok(
+    (SELECT actor.verify_passwd(187, 'main', 
+        MD5(actor.get_salt(187, 'main') || MD5('montyc1234')))),
+    'verify_passwd should verify migrated password'
+);
+
+SELECT ok(
+    (SELECT NOT (
+        SELECT actor.verify_passwd(187, 'main', 
+            MD5(actor.get_salt(187, 'main') || MD5('BADPASSWORD'))))
+    ),
+    'verify_passwd should fail with wrong password'
+);
+
+-- This code chunk mimics the application changing a user's password
+DO $$
+    DECLARE new_salt TEXT;
+BEGIN
+    -- we have to capture the salt, because subsequent 
+    -- calls will create a new one.
+    SELECT INTO new_salt actor.create_salt('main');
+    PERFORM actor.set_passwd(
+        187, 'main', MD5(new_salt || MD5('bobblehead')), new_salt);
+END $$;
+
+SELECT ok(
+    (SELECT actor.verify_passwd(187, 'main', 
+        MD5(actor.get_salt(187, 'main') || MD5('bobblehead')))),
+    'verify_passwd should verify new password'
+);
+
+-- Finish the tests and clean up.
+SELECT * FROM finish();
+
+ROLLBACK;
+
index 81155af..d604065 100644 (file)
@@ -1,6 +1,7 @@
-
 BEGIN;
 
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
 CREATE EXTENSION IF NOT EXISTS pgcrypto;
 
 CREATE TABLE actor.passwd_type (
@@ -215,78 +216,4 @@ INSERT INTO actor.passwd_type
     (code, name, login, crypt_algo, iter_count) 
     VALUES ('main', 'Main Login Password', TRUE, 'bf', 14);
 
---COMMIT;
---BEGIN;
-
--- INLINE TESTS ---------------
--- TODO: move to new t/ file.
-
-\set ECHO none
-\set QUIET 1
--- Turn off echo and keep things quiet.
-
--- Format the output for nice TAP.
-\pset format unaligned
-\pset tuples_only true
-\pset pager
-
--- Revert all changes on failure.
-\set ON_ERROR_ROLLBACK 1
-\set ON_ERROR_STOP true
-\set QUIET 1
-
--- Plan the tests.
-SELECT plan(6);
-
-SELECT ok(
-    (SELECT TRUE AS verify_old_pw FROM actor.usr 
-        WHERE id = 187 AND passwd = MD5('montyc1234')),
-    'Legacy password should match'
-);
-
-SELECT isnt_empty(
-    'SELECT actor.get_salt(187, ''main'')',
-    'get_salt() returns a new salt'
-);
-
-SELECT isnt_empty(
-    'SELECT * FROM actor.passwd WHERE usr = 187 AND passwd_type = ''main''',
-    'get_salt() should migrate the password'
-);
-
-SELECT ok(
-    (SELECT actor.verify_passwd(187, 'main', 
-        MD5(actor.get_salt(187, 'main') || MD5('montyc1234')))),
-    'verify_passwd should verify migrated password'
-);
-
-SELECT ok(
-    (SELECT NOT (
-        SELECT actor.verify_passwd(187, 'main', 
-            MD5(actor.get_salt(187, 'main') || MD5('BADPASSWORD'))))
-    ),
-    'verify_passwd should fail with wrong password'
-);
-
--- This code chunk mimics the application changing a user's password
-DO $$
-    DECLARE new_salt TEXT;
-BEGIN
-    -- we have to capture the salt, because subsequent 
-    -- calls will create a new one.
-    SELECT INTO new_salt actor.create_salt('main');
-    PERFORM actor.set_passwd(
-        187, 'main', MD5(new_salt || MD5('bobblehead')), new_salt);
-END $$;
-
-SELECT ok(
-    (SELECT actor.verify_passwd(187, 'main', 
-        MD5(actor.get_salt(187, 'main') || MD5('bobblehead')))),
-    'verify_passwd should verify new password'
-);
-
--- Finish the tests and clean up.
-SELECT * FROM finish();
-
-ROLLBACK;
---COMMIT;
+COMMIT;