Onionr/tests/default-plugin-tests/wot/test_identity_init.py

44 lines
1.2 KiB
Python
Raw Permalink Normal View History

2022-08-31 05:30:28 +00:00
import os, uuid
from random import randint
import secrets
from nacl import signing
TEST_DIR = 'testdata/%s-%s' % (str(uuid.uuid4())[:6], os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import unittest
import sys
sys.path.append(".")
2023-01-17 23:53:51 +00:00
sys.path.append('static-data/official-plugins/wot/')
2022-08-31 05:30:28 +00:00
sys.path.append("src/")
2023-01-17 23:53:51 +00:00
import wot
from wot.identity import Identity
2022-08-31 05:30:28 +00:00
class IdentityInitTest(unittest.TestCase):
def test_inden_init_privkey(self):
private_key = signing.SigningKey.generate()
iden = Identity(private_key, "test")
self.assertEqual(iden.name, "test")
self.assertEqual(iden.key, private_key.verify_key)
self.assertEqual(iden.private_key, private_key)
def test_iden_init_pubkey(self):
public = signing.SigningKey.generate().verify_key
iden = Identity(public, "test")
self.assertEqual(iden.name, "test")
self.assertEqual(iden.key, public)
self.assertEqual(iden.private_key, None)
def test_iden_init_pubkey_invalid_name(self):
public = signing.SigningKey.generate().verify_key
self.assertRaises(ValueError, Identity, public, secrets.token_hex(32))
unittest.main()