forked from UTSAVS26/PyVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_auth.py
More file actions
25 lines (21 loc) · 733 Bytes
/
Copy pathtest_auth.py
File metadata and controls
25 lines (21 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import unittest
import os
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from server import auth
class TestAuth(unittest.TestCase):
def setUp(self):
self.token = 'SECRET123'
self.password = 'mypass'
self.salt = os.urandom(16)
def test_verify_token(self):
self.assertTrue(auth.verify_token('SECRET123', self.token))
self.assertFalse(auth.verify_token('WRONG', self.token))
def test_derive_key(self):
key1 = auth.derive_key(self.password, self.salt)
key2 = auth.derive_key(self.password, self.salt)
self.assertEqual(key1, key2)
self.assertEqual(len(key1), 32)
if __name__ == '__main__':
unittest.main()