-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests and notes for challenge 13 in progress
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
75dfa8b6e29a435c714b574431aa3024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import unittest | ||
import src.utils.bytecodec as bytecodec | ||
|
||
from secrets import token_bytes | ||
from src.UserProfile import urlencode_to_dict, profile_for, UserProfile | ||
|
||
class UserProfileTest(unittest.TestCase): | ||
|
||
def test_urlencode_to_dict(self): | ||
expected = { | ||
'foo': 'bar', | ||
'baz': 'qux', | ||
'zap': 'zazzle' | ||
} | ||
actual = urlencode_to_dict('foo=bar&baz=qux&zap=zazzle') | ||
self.assertEqual(expected, actual) | ||
|
||
def test_profile_for(self): | ||
expected = 'email=foo@bar.com&uid=10&role=user' | ||
actual = profile_for('foo@bar.com') | ||
self.assertEqual(expected, actual) | ||
expected = 'email=foo@bar.comroleadmin&uid=10&role=user' | ||
actual = profile_for('foo@bar.com&role=admin') | ||
self.assertEqual(expected, actual) | ||
|
||
def test_attack_profile(self): | ||
key = self.get_static_key() | ||
profile = UserProfile(key) | ||
encrypted = profile.encrypted_profile_for('foo@bar.com') | ||
decrypted = profile.decrypt_profile(encrypted) | ||
expected = { | ||
'email': 'foo@bar.com', | ||
'uid': '10', | ||
'role': 'user' | ||
} | ||
self.assertEqual(expected, decrypted) | ||
''' | ||
email=fooooooooo | ||
@bar.commmmmmmmm | ||
&uid=10&role=use | ||
r | ||
''' | ||
|
||
def get_static_key(self): | ||
with open('./tests/fixtures/set_2_challenge13.key', 'r') as fh: | ||
hex_key = fh.read() | ||
key = bytecodec.hex_to_bytes(hex_key) | ||
return key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters