mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-05-18 14:30:25 -04:00
Big refactoring sweep through tests
This commit is contained in:
parent
b545c5c2be
commit
553ea7a3e0
5 changed files with 134 additions and 105 deletions
|
@ -1,42 +1,53 @@
|
|||
# Crypto veilid tests
|
||||
|
||||
import veilid
|
||||
import pytest
|
||||
from . import *
|
||||
import veilid
|
||||
from veilid.api import CryptoSystem
|
||||
|
||||
from . import api_connection
|
||||
|
||||
##################################################################
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_best_crypto_system():
|
||||
async def func(api: veilid.VeilidAPI):
|
||||
bcs = await api.best_crypto_system()
|
||||
await simple_connect_and_run(func)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_crypto_system():
|
||||
async def func(api: veilid.VeilidAPI):
|
||||
cs = await api.get_crypto_system(veilid.CryptoKind.CRYPTO_KIND_VLD0)
|
||||
# clean up handle early
|
||||
del cs
|
||||
await simple_connect_and_run(func)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_crypto_system_invalid():
|
||||
async def func(api: veilid.VeilidAPI):
|
||||
with pytest.raises(veilid.VeilidAPIError):
|
||||
cs = await api.get_crypto_system(veilid.CryptoKind.CRYPTO_KIND_NONE)
|
||||
await simple_connect_and_run(func)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hash_and_verify_password():
|
||||
async def func(api: veilid.VeilidAPI):
|
||||
bcs = await api.best_crypto_system()
|
||||
nonce = await bcs.random_nonce()
|
||||
salt = nonce.to_bytes()
|
||||
# Password match
|
||||
phash = await bcs.hash_password(b"abc123", salt)
|
||||
assert await bcs.verify_password(b"abc123", phash)
|
||||
# Password mismatch
|
||||
phash2 = await bcs.hash_password(b"abc1234", salt)
|
||||
assert not await bcs.verify_password(b"abc12345", phash)
|
||||
await simple_connect_and_run(func)
|
||||
async def test_best_crypto_system(api_connection):
|
||||
bcs: CryptoSystem = await api_connection.best_crypto_system()
|
||||
|
||||
assert await bcs.default_salt_length() == 16
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_crypto_system(api_connection):
|
||||
cs: CryptoSystem = await api_connection.get_crypto_system(
|
||||
veilid.CryptoKind.CRYPTO_KIND_VLD0
|
||||
)
|
||||
|
||||
assert await cs.default_salt_length() == 16
|
||||
|
||||
# clean up handle early
|
||||
del cs
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_crypto_system_invalid(api_connection):
|
||||
with pytest.raises(veilid.VeilidAPIErrorInvalidArgument) as exc:
|
||||
await api_connection.get_crypto_system(veilid.CryptoKind.CRYPTO_KIND_NONE)
|
||||
|
||||
assert exc.value.context == "unsupported cryptosystem"
|
||||
assert exc.value.argument == "kind"
|
||||
assert exc.value.value == "NONE"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hash_and_verify_password(api_connection):
|
||||
bcs = await api_connection.best_crypto_system()
|
||||
nonce = await bcs.random_nonce()
|
||||
salt = nonce.to_bytes()
|
||||
|
||||
# Password match
|
||||
phash = await bcs.hash_password(b"abc123", salt)
|
||||
assert await bcs.verify_password(b"abc123", phash)
|
||||
|
||||
# Password mismatch
|
||||
phash2 = await bcs.hash_password(b"abc1234", salt)
|
||||
assert not await bcs.verify_password(b"abc12345", phash)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue