Skip to content

Commit

Permalink
Demo of storing a hashed barcode with pgcrypto.
Browse files Browse the repository at this point in the history
  • Loading branch information
aslagle committed Dec 11, 2015
1 parent 17364a1 commit 4552a33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core
Submodule core updated from 2a8756 to 833112
2 changes: 2 additions & 0 deletions millenium_patron.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def update_patron(self, patron, identifier, dump=None):
if not dump:
dump = self.dump(identifier)
patron.authorization_identifier = dump.get(self.BARCODE_FIELD, None)
from sqlalchemy import func
patron.hashed_identifier = func.crypt(patron.authorization_identifier, func.gen_salt('md5'))
patron.username = dump.get(self.USERNAME_FIELD, None)
patron.fines = dump.get(self.FINES_FIELD, None)
patron._external_type = dump.get(self.PATRON_TYPE_FIELD, None)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def test_borrow_fails_with_outstanding_fines(self):

with self.app.test_request_context(
"/", headers=dict(Authorization=auth)):
self.manager.loans.authenticated_patron_from_request()
patron = self.manager.loans.authenticated_patron_from_request()
response = self.manager.loans.borrow(
DataSource.THREEM, pool.identifier.identifier)

Expand All @@ -419,6 +419,11 @@ def test_borrow_fails_with_outstanding_fines(self):
assert "outstanding fines" in response.detail
assert "$1.00" in response.detail

patrons_from_db = self._db.query(Patron).filter_by(original_identifier="5").all()
eq_(1, len(patrons_from_db))
matched_patron = patrons_from_db[0]
eq_("5", matched_patron.authorization_identifier)

with temp_config() as config:
config['policies'][Configuration.MAX_OUTSTANDING_FINES] = "$20.00"

Expand Down

0 comments on commit 4552a33

Please sign in to comment.