[3/4] gendummydata.py: Fix to make it less db specific

Message ID 20170301064621.19031-3-mark.weiman@markzz.com
State Accepted, archived
Headers show
Series [1/4] Add sqlite3 schema for testing databases | expand

Commit Message

Mark Weiman March 1, 2017, 6:46 a.m. UTC
Sqlite3 does not support the MD5 function like MySQL does, instead of the
database program hash the passwords, have Python's hashlib module do it
instead.

Signed-off-by: Mark Weiman <mark.weiman@markzz.com>
---
 schema/gendummydata.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Comments

Lukas Fleischer March 1, 2017, 7:23 p.m. UTC | #1
On Wed, 01 Mar 2017 at 07:46:20, Mark Weiman wrote:
> Sqlite3 does not support the MD5 function like MySQL does, instead of the
> database program hash the passwords, have Python's hashlib module do it
> instead.
> 
> Signed-off-by: Mark Weiman <mark.weiman@markzz.com>
> ---
>  schema/gendummydata.py | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> [...]

As of commit 29a4870 (Use bcrypt to hash passwords, 2017-02-24), we are
no longer hashing passwords with MD5. However, given that this is just
"dummy data" and the generated passwords do not seem to be used
anywhere, I am going to merge this to pu for now. We can still migrate
the script to use bcrypt later.

Patch

diff --git a/schema/gendummydata.py b/schema/gendummydata.py
index 9dd2f45..373f82e 100755
--- a/schema/gendummydata.py
+++ b/schema/gendummydata.py
@@ -9,6 +9,7 @@  usage: gendummydata.py outputfilename.sql
 # package names.  It generates the SQL statements to
 # insert these users/packages into the AUR database.
 #
+import hashlib
 import random
 import time
 import os
@@ -170,9 +171,11 @@  for u in user_keys:
 			#
 			pass
 
+	h = hashlib.new('md5')
+	h.update(u.encode());
 	s = ("INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd)"
-		 " VALUES (%d, %d, '%s', '%s@example.com', MD5('%s'));\n")
-	s = s % (seen_users[u], account_type, u, u, u)
+		 " VALUES (%d, %d, '%s', '%s@example.com', '%s');\n")
+	s = s % (seen_users[u], account_type, u, u, h.hexdigest())
 	out.write(s)
 
 log.debug("Number of developers: %d" % len(developers))
@@ -202,9 +205,9 @@  for p in list(seen_pkgs.keys()):
 
 	uuid = genUID() # the submitter/user
 
-	s = ("INSERT INTO PackageBases (ID, Name, SubmittedTS, "
-         "SubmitterUID, MaintainerUID, PackagerUID) VALUES (%d, '%s', %d, %d, %s, %s);\n")
-	s = s % (seen_pkgs[p], p, NOW, uuid, muid, puid)
+	s = ("INSERT INTO PackageBases (ID, Name, SubmittedTS, ModifiedTS, "
+         "SubmitterUID, MaintainerUID, PackagerUID) VALUES (%d, '%s', %d, %d, %d, %s, %s);\n")
+	s = s % (seen_pkgs[p], p, NOW, NOW, uuid, muid, puid)
 	out.write(s)
 
 	s = ("INSERT INTO Packages (ID, PackageBaseID, Name, Version) VALUES "
@@ -303,7 +306,7 @@  for t in range(0, OPEN_PROPOSALS+CLOSE_PROPOSALS):
 		user = user_keys[random.randrange(0,len(user_keys))]
 	suid = trustedusers[random.randrange(0,len(trustedusers))]
 	s = ("INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End,"
-	" SubmitterID) VALUES ('%s', '%s', %d, %d, %d);\n")
+	" Quorum, SubmitterID) VALUES ('%s', '%s', %d, %d, 0.0, %d);\n")
 	s = s % (genFortune(), user, start, end, suid)
 	out.write(s)
 	count += 1