Esempio n. 1
0
def test_extract_token_invite_key_with_no_invite(client):
    with pytest.raises(InviteError) as error:
        extract_token_invite_key(
            encrypted_jwt_token(
                username="",
                sensitive_content="bogus",
                expires_in=datetime.timedelta(hours=24),
                additional_claims={"inv": "*****@*****.**"},
            )
        )
    assert "Invite could not be found!" in str(error.value)
Esempio n. 2
0
def test_extract_token_invite_key_with_wrong_format_for_key(client):
    with pytest.raises(ValueError) as error:
        extract_token_invite_key(
            encrypted_jwt_token(
                username="",
                sensitive_content="bogus",
                expires_in=datetime.timedelta(hours=24),
                additional_claims={"inv": "*****@*****.**"},
            )
        )
    assert "Temporary key is expected be in hexadecimal digits for a byte string." in str(
        error.value
    )
Esempio n. 3
0
def verify_and_transfer_invite_to_user(token, user, password):
    invite, temporary_key = extract_token_invite_key(token)
    private_key_bytes = __verify_invite_temporary_key(invite, temporary_key)
    if private_key_bytes:
        __transfer_invite_private_key_to_user(invite, private_key_bytes, user,
                                              password)
        del private_key_bytes
        gc.collect()
        return True
    return False
Esempio n. 4
0
def test_extract_token_invite_key_successful(client):
    invite, temporary_key = extract_token_invite_key(
        encrypted_jwt_token(
            username="",
            sensitive_content=b"bogus".hex(),
            expires_in=datetime.timedelta(hours=24),
            additional_claims={"inv": "*****@*****.**"},
        )
    )
    assert invite
    assert invite.email == "*****@*****.**"
    assert temporary_key == b"bogus"
Esempio n. 5
0
def test_extract_token_invite_key_with_wrong_token(client):
    with pytest.raises(AuthenticationError) as error:
        extract_token_invite_key(encrypted_jwt_token(username="******", sensitive_content=None))
    assert "Invalid token" in str(error.value)