Exemple #1
0
def test_user_dict_identity():
    for n in NICK_VALS:
        for pk in [Pubkey(v.to_bytes(32, byteorder='big')) for v in PK_VALS]:
            for rowid in {None, 44}:
                first = User(n, pk, rowid=rowid)
                second = User.from_dict(first.to_dict())
                assert first == second
Exemple #2
0
def test_user_from_dict():
    for n in NICK_VALS:
        for pk in [Pubkey(v.to_bytes(32, byteorder='big')) for v in PK_VALS]:
            u_expect = User(n, pk)
            pk_b64_bytes = b64encode(bytes(pk)).decode('utf-8')
            u_actual = User.from_dict({'nick': n, 'pk': pk_b64_bytes})
            assert u_expect == u_actual
Exemple #3
0
def test_user_init():
    for n in NICK_VALS:
        for pk in [Pubkey(v.to_bytes(32, byteorder='big')) for v in PK_VALS]:
            u = User(n, pk)
            assert u.nick == n
            assert u.pk == pk
            assert u.rowid is None
from rela.lib.messages.location import LocationUpdate, LocationUpdateResp,\
    LocationUpdateRespErr
from rela.lib.messages.account import AccountCred
from rela.lib.messages import EncryptedMessage, Stub
from rela.lib.location import Location, Coords
from rela.lib.user import User
from rela.lib.crypto import Pubkey, Enckey
import time

U = User('Foo', Pubkey((1).to_bytes(32, byteorder='big')), rowid=420)
C = Coords(4, 20)
LOC = Location(U, C, time.time())


def fake_cred():
    cred = AccountCred(U, time.time())
    return EncryptedMessage.enc(cred, Enckey.gen())


def test_locationupdate_init():
    cred = fake_cred()
    lu = LocationUpdate(LOC, cred)
    assert lu.loc == LOC
    assert lu.cred == cred


def test_locationupdate_str():
    cred = fake_cred()
    lu = LocationUpdate(LOC, cred)
    s = 'LocationUpdate<%s %s>' % (LOC, cred)
    assert str(lu) == s
Exemple #5
0
from rela.lib.location import Coords, Location
from rela.lib.user import User
from rela.lib.crypto import Pubkey
import pytest
import time

U = User('Sam', Pubkey((1).to_bytes(32, byteorder='big')))

TEST_COORDS_GOOD = [
    (44, 0), (-44, 0),
    (0, 44), (0, -44),
    (-90, -180), (-90, 180),
    (90, 180), (90, -180),
    (0, 0),
    (0.00001, 0), (0.00001, 0.00001), (0, 0.00001),
]

TEST_COORDS_BAD = [
    (-90.00001, 0), (90.00001, 0),
    (0, 180.000001), (0, -180.000001),
]


def test_coords_init_happy():
    for lat, long in TEST_COORDS_GOOD:
        loc = Coords(lat, long)
        assert loc.lat == lat
        assert loc.long == long


def test_coords_init_bad():
Exemple #6
0
def test_authchallenge_str():
    u = User(U.nick, U.pk, rowid=1)
    now = time.time()
    s = 'AuthChallenge<%s %f>' % (u, now)
    assert str(account.AuthChallenge(u, now)) == s
Exemple #7
0
def test_authchallenge_dict_bad_user():
    u = User(U.nick, U.pk, rowid=1)
    d = account.AuthChallenge(u, time.time()).to_dict()
    del d['user']['nick']
    assert account.AuthChallenge.from_dict(d) is None
Exemple #8
0
def test_authchallenge_dict_identity():
    u = User(U.nick, U.pk, rowid=1)
    first = account.AuthChallenge(u, time.time())
    second = account.AuthChallenge.from_dict(first.to_dict())
    assert first == second
Exemple #9
0
def test_accountcred_to_dict():
    ac = account.AccountCred(U, 1)
    d = ac.to_dict()
    assert User.from_dict(d['user']) == U
    assert d['expire'] == 1
Exemple #10
0
def test_user_dict_no_pk():
    d = User('', Pubkey((0).to_bytes(32, byteorder='big'))).to_dict()
    del d['pk']
    assert User.from_dict(d) is None
Exemple #11
0
def test_user_str():
    for n in NICK_VALS:
        for pk in [Pubkey(v.to_bytes(32, byteorder='big')) for v in PK_VALS]:
            s = 'User<%s %s %s>' % (None, n, pk)
            u = User(n, pk)
            assert str(u) == s