-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor check_user to optionally hash key and user inputs #51
Conversation
@thekaveman I'm running into several issues:
monkeypatch.setenv("HASH_INPUTS", "False")
assert os.environ.get("HASH_INPUTS") == "False"
assert settings.HASH_INPUT == False ## this fails
assert hash._hash_inputs == False ## this fails It seems like
So, I tried a different way: @patch("eligibility_server.settings.HASH_INPUTS", False)
@patch("eligibility_server.settings.HASH_TYPE", "sha512") But I wasn't able to get this to pass:
I wasn't able to use
The good news is that, with this way, I was able to get this test, which is testing the case in which a user doesn't want to hash anything, to pass: However, when I tried to write another spec that tests this same condition (HASH_INPUTS is False) from the Any suggestions??? I need to be able to:
I'm not sure if monkeypatching the environment variables are better, or if using the fixture method is better.. (though I'd like to make it easier to turn on/off fixtures or use only certain fixtures with certain tests, so I can more easily change "hash_type" for just a few specs). |
@thekaveman Can you review the way I've added the .env vars, config default values and initialized the Hash class? |
Create a hash instance here https://github.com/cal-itp/eligibility-server/blob/main/eligibility_server/verify.py#L24 |
|
I think you captured most of what we talked about in your notes. A few additional things:
And one additional idea as I was typing this up: I think the class Database:
def __init__(self, hash=False):
self._hash = hash
def lookup(self, input):
if self._hash:
hashed_input = self._hash.hash_input(input)
# lookup using hashed_input
else:
# look up using input directly
class Verify:
def __init__(self):
if settings.HASH_INPUTS:
hash = Hash(settings.HASH_TYPE)
self._db = Database(hash=hash)
else:
self._db = Database() |
@thekaveman @angela-tran Finally ready for review. Thank you both for all the help already! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! A few testing comments, a few comments on the comments 😉, a few more general/python comments.
@thekaveman Ready for a re-review:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker in the least, but perhaps a quick git rebase -i main
could allow for clean up of some of these "trying this" type commits.
#34
What this PR does
Hash
,Database
andVerify
classes.env
,.env.sample
,.env.tests
file with new env variable,HASH_TYPE
and default sample value,sha256
.Database#check_user
that checks to see if theDatabase
has aHash
or not. If theDatabase
was initialized with aHash
object, thecheck_user
function will hash the inputs first. If not, the function will not hash the inputs.server.json
as test dataTo Do
How to run tests
coverage run -m pytest -v