diff options
author | uditgulati | 2021-01-05 13:13:28 -0600 |
---|---|---|
committer | uditgulati | 2021-01-05 13:13:28 -0600 |
commit | 1e7a4d76fa36d1476fe37ae9b4c0a946fe99bce1 (patch) | |
tree | 0d18520e09fa0edce0080c773d0edd14750b855c /wqflask/tests/unit/utility/test_hmac.py | |
parent | e106f5888cb4d761a6dcb71dc0273e461ef3c71a (diff) | |
parent | e36d40d64c1cf8476002c46b5c9dba308151f75c (diff) | |
download | genenetwork2-1e7a4d76fa36d1476fe37ae9b4c0a946fe99bce1.tar.gz |
Merge branch 'testing' of https://github.com/genenetwork/genenetwork2 into snp_browser_changes
Diffstat (limited to 'wqflask/tests/unit/utility/test_hmac.py')
-rw-r--r-- | wqflask/tests/unit/utility/test_hmac.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/wqflask/tests/unit/utility/test_hmac.py b/wqflask/tests/unit/utility/test_hmac.py new file mode 100644 index 00000000..13d6261d --- /dev/null +++ b/wqflask/tests/unit/utility/test_hmac.py @@ -0,0 +1,51 @@ +"""Test hmac utility functions""" + +import unittest +from unittest import mock + +from utility.hmac import data_hmac +from utility.hmac import url_for_hmac +from utility.hmac import hmac_creation + + +class TestHmacUtil(unittest.TestCase): + """Test Utility method for hmac creation""" + + @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) + def test_hmac_creation(self): + """Test hmac creation with a utf-8 string""" + self.assertEqual(hmac_creation("ファイ"), "7410466338cfe109e946") + + @mock.patch("utility.hmac.app.config", + {'SECRET_HMAC_CODE': ('\x08\xdf\xfa\x93N\x80' + '\xd9\\H@\\\x9f`\x98d^' + '\xb4a;\xc6OM\x946a\xbc' + '\xfc\x80:*\xebc')}) + def test_hmac_creation_with_cookie(self): + """Test hmac creation with a cookie""" + cookie = "3f4c1dbf-5b56-4260-87d6-f35445bda37e:af4fcf5eace9e7c864ce" + uuid_, _, signature = cookie.partition(":") + self.assertEqual( + hmac_creation(uuid_), + "af4fcf5eace9e7c864ce") + + @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) + def test_data_hmac(self): + """Test data_hmac fn with a utf-8 string""" + self.assertEqual(data_hmac("ファイ"), "ファイ:7410466338cfe109e946") + + @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) + @mock.patch("utility.hmac.url_for") + def test_url_for_hmac_with_plain_url(self, mock_url): + """Test url_for_hmac without params""" + mock_url.return_value = "https://mock_url.com/ファイ/" + self.assertEqual(url_for_hmac("ファイ"), + "https://mock_url.com/ファイ/?hm=05bc39e659b1948f41e7") + + @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) + @mock.patch("utility.hmac.url_for") + def test_url_for_hmac_with_param_in_url(self, mock_url): + """Test url_for_hmac with params""" + mock_url.return_value = "https://mock_url.com/?ファイ=1" + self.assertEqual(url_for_hmac("ファイ"), + "https://mock_url.com/?ファイ=1&hm=4709c1708270644aed79") |