Beispiel #1
0
def test_passcheck():
    '''
    This tests if we can check the password for a logged-in user.

    '''

    try:
        os.remove('test-passcheck.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-passcheck.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-passcheck.authdb.sqlite-wal')
    except Exception as e:
        pass

    get_test_authdb()

    # create the user
    user_payload = {'email':'*****@*****.**',
                    'password':'******'}
    user_created = actions.create_new_user(
        user_payload,
        override_authdb_path='sqlite:///test-passcheck.authdb.sqlite'
    )
    assert user_created['success'] is True
    assert user_created['user_email'] == '*****@*****.**'
    assert ('User account created. Please verify your email address to log in.'
            in user_created['messages'])

    # create a new session token
    session_payload = {
        'user_id':2,
        'client_header':'Mozzarella Killerwhale',
        'expires':datetime.utcnow()+timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json':{'pref_datasets_always_private':True}
    }

    # check creation of session
    session_token1 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-passcheck.authdb.sqlite'
    )
    assert session_token1['success'] is True
    assert session_token1['session_token'] is not None

    # verify our email
    emailverify = (
        actions.verify_user_email_address(
            {'email':user_payload['email'],
             'user_id': user_created['user_id']},
            override_authdb_path='sqlite:///test-passcheck.authdb.sqlite'
        )
    )

    assert emailverify['success'] is True
    assert emailverify['user_id'] == user_created['user_id']
    assert emailverify['is_active'] is True
    assert emailverify['user_role'] == 'authenticated'

    # now make a new session token to simulate a logged-in user
    session_payload = {
        'user_id':emailverify['user_id'],
        'client_header':'Mozzarella Killerwhale',
        'expires':datetime.utcnow()+timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json':{'pref_datasets_always_private':True}
    }

    # check creation of session
    session_token2 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-passcheck.authdb.sqlite'
    )
    assert session_token2['success'] is True
    assert session_token2['session_token'] is not None

    #
    # now run a password check
    #

    # correct password
    pass_check = actions.auth_password_check(
        {'session_token':session_token2['session_token'],
         'password':user_payload['password']},
        override_authdb_path='sqlite:///test-passcheck.authdb.sqlite',
        raiseonfail=True
    )
    assert pass_check['success'] is True
    assert pass_check['user_id'] == emailverify['user_id']

    # incorrect password
    pass_check = actions.auth_password_check(
        {'session_token':session_token2['session_token'],
         'password':'******'},
        override_authdb_path='sqlite:///test-passcheck.authdb.sqlite',
        raiseonfail=True
    )
    assert pass_check['success'] is False
    assert pass_check['user_id'] is None

    currproc = mp.current_process()
    if getattr(currproc, 'table_meta', None):
        del currproc.table_meta

    if getattr(currproc, 'connection', None):
        currproc.connection.close()
        del currproc.connection

    if getattr(currproc, 'engine', None):
        currproc.engine.dispose()
        del currproc.engine


    try:
        os.remove('test-passcheck.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-passcheck.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-passcheck.authdb.sqlite-wal')
    except Exception as e:
        pass
def test_login_timing():
    '''This tests obfuscating the presence/absence of users based on password
    checks.

    This may fail randomly if the testing service is under load.

    '''

    try:
        os.remove('test-timing.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-timing.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-timing.authdb.sqlite-wal')
    except Exception as e:
        pass

    get_test_authdb()

    # create the user
    user_payload = {
        'email': '*****@*****.**',
        'password': '******'
    }
    user_created = actions.create_new_user(
        user_payload,
        override_authdb_path='sqlite:///test-timing.authdb.sqlite')
    assert user_created['success'] is True
    assert user_created['user_email'] == '*****@*****.**'
    assert ('User account created. Please verify your email address to log in.'
            in user_created['messages'])

    # create a new session token
    session_payload = {
        'user_id': 2,
        'client_header': 'Mozzarella Killerwhale',
        'expires': datetime.utcnow() + timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json': {
            'pref_datasets_always_private': True
        }
    }

    # check creation of session
    session_token1 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-timing.authdb.sqlite')
    assert session_token1['success'] is True
    assert session_token1['session_token'] is not None

    # try logging in now with correct password
    login = actions.auth_user_login(
        {
            'session_token': session_token1['session_token'],
            'email': user_payload['email'],
            'password': user_payload['password']
        },
        override_authdb_path='sqlite:///test-timing.authdb.sqlite')

    # this should fail because we haven't verified our email yet
    assert login['success'] is False

    # verify our email
    emailverify = (actions.verify_user_email_address(
        {
            'email': user_payload['email'],
            'user_id': user_created['user_id']
        },
        override_authdb_path='sqlite:///test-timing.authdb.sqlite'))

    assert emailverify['success'] is True
    assert emailverify['user_id'] == user_created['user_id']
    assert emailverify['is_active'] is True
    assert emailverify['user_role'] == 'authenticated'

    # now make a new session token
    session_payload = {
        'user_id': 2,
        'client_header': 'Mozzarella Killerwhale',
        'expires': datetime.utcnow() + timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json': {
            'pref_datasets_always_private': True
        }
    }

    # check creation of session
    session_token2 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-timing.authdb.sqlite')
    assert session_token2['success'] is True
    assert session_token2['session_token'] is not None

    # and now try to log in again
    login = actions.auth_user_login(
        {
            'session_token': session_token2['session_token'],
            'email': user_payload['email'],
            'password': user_payload['password']
        },
        override_authdb_path='sqlite:///test-timing.authdb.sqlite')

    assert login['success'] is True

    # basic tests for timing attacks

    # incorrect passwords
    incorrect_timings = []
    for _ in range(1000):

        # now make a new session token
        session_payload = {
            'user_id': 2,
            'client_header': 'Mozzarella Killerwhale',
            'expires': datetime.utcnow() + timedelta(hours=1),
            'ip_address': '1.1.1.1',
            'extra_info_json': {
                'pref_datasets_always_private': True
            }
        }

        # check creation of session
        session_token2 = actions.auth_session_new(
            session_payload,
            override_authdb_path='sqlite:///test-timing.authdb.sqlite')

        start = time.time()
        actions.auth_user_login(
            {
                'session_token': session_token2['session_token'],
                'email': user_payload['email'],
                'password': secrets.token_urlsafe(16)
            },
            override_authdb_path='sqlite:///test-timing.authdb.sqlite')
        end = time.time()
        incorrect_timings.append(end - start)

    # correct passwords
    correct_timings = []
    for _ in range(1000):

        # now make a new session token
        session_payload = {
            'user_id': 2,
            'client_header': 'Mozzarella Killerwhale',
            'expires': datetime.utcnow() + timedelta(hours=1),
            'ip_address': '1.1.1.1',
            'extra_info_json': {
                'pref_datasets_always_private': True
            }
        }

        # check creation of session
        session_token2 = actions.auth_session_new(
            session_payload,
            override_authdb_path='sqlite:///test-timing.authdb.sqlite')

        start = time.time()
        actions.auth_user_login(
            {
                'session_token': session_token2['session_token'],
                'email': user_payload['email'],
                'password': user_payload['password']
            },
            override_authdb_path='sqlite:///test-timing.authdb.sqlite')
        end = time.time()
        correct_timings.append(end - start)

    # wronguser passwords
    wronguser_timings = []
    for _ in range(1000):

        # now make a new session token
        session_payload = {
            'user_id': 2,
            'client_header': 'Mozzarella Killerwhale',
            'expires': datetime.utcnow() + timedelta(hours=1),
            'ip_address': '1.1.1.1',
            'extra_info_json': {
                'pref_datasets_always_private': True
            }
        }

        # check creation of session
        session_token2 = actions.auth_session_new(
            session_payload,
            override_authdb_path='sqlite:///test-timing.authdb.sqlite')

        start = time.time()
        actions.auth_user_login(
            {
                'session_token': session_token2['session_token'],
                'email': secrets.token_urlsafe(16),
                'password': secrets.token_urlsafe(16)
            },
            override_authdb_path='sqlite:///test-timing.authdb.sqlite')
        end = time.time()
        wronguser_timings.append(end - start)

    # broken requests
    broken_timings = []
    for _ in range(1000):

        # now make a new session token
        session_payload = {
            'user_id': 2,
            'client_header': 'Mozzarella Killerwhale',
            'expires': datetime.utcnow() + timedelta(hours=1),
            'ip_address': '1.1.1.1',
            'extra_info_json': {
                'pref_datasets_always_private': True
            }
        }

        # check creation of session
        session_token2 = actions.auth_session_new(
            session_payload,
            override_authdb_path='sqlite:///test-timing.authdb.sqlite')

        start = time.time()
        actions.auth_user_login(
            {
                'session_token': 'correcthorsebatterystaple',
                'email': user_payload['email'],
                'password': user_payload['password']
            },
            override_authdb_path='sqlite:///test-timing.authdb.sqlite')
        end = time.time()
        broken_timings.append(end - start)

    correct_timings = np.array(correct_timings)
    incorrect_timings = np.array(incorrect_timings)
    broken_timings = np.array(broken_timings)
    wronguser_timings = np.array(wronguser_timings)

    correct_median = np.median(correct_timings)
    incorrect_median = np.median(incorrect_timings)
    broken_median = np.median(broken_timings)
    wronguser_median = np.median(wronguser_timings)

    # all timings should match within 7 milliseconds or so
    assert_allclose(correct_median, incorrect_median, atol=7.0e-3)
    assert_allclose(correct_median, broken_median, atol=7.0e-3)
    assert_allclose(correct_median, wronguser_median, atol=7.0e-3)

    currproc = mp.current_process()
    if getattr(currproc, 'table_meta', None):
        del currproc.table_meta

    if getattr(currproc, 'connection', None):
        currproc.connection.close()
        del currproc.connection

    if getattr(currproc, 'engine', None):
        currproc.engine.dispose()
        del currproc.engine

    try:
        os.remove('test-timing.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-timing.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-timing.authdb.sqlite-wal')
    except Exception as e:
        pass
Beispiel #3
0
def test_create_user():
    '''
    This runs through various iterations of creating a user.

    '''
    try:
        os.remove('test-creation.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-creation.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-creation.authdb.sqlite-wal')
    except Exception as e:
        pass

    get_test_authdb()

    # 1. dumb password
    payload = {'email': '*****@*****.**', 'password': '******'}
    user_created = actions.create_new_user(
        payload, override_authdb_path='sqlite:///test-creation.authdb.sqlite')
    assert user_created['success'] is False
    assert user_created['user_email'] == '*****@*****.**'
    assert user_created['user_id'] is None
    assert user_created['send_verification'] is False
    assert ('Your password is too short. It must have at least 12 characters.'
            in user_created['messages'])
    assert ('Your password is not complex enough. '
            'One or more characters appear appear too frequently.'
            in user_created['messages'])

    # 2. all numeric password
    payload = {
        'email': '*****@*****.**',
        'password': '******'
    }
    user_created = actions.create_new_user(
        payload, override_authdb_path='sqlite:///test-creation.authdb.sqlite')
    assert user_created['success'] is False
    assert user_created['user_email'] == '*****@*****.**'
    assert user_created['user_id'] is None
    assert user_created['send_verification'] is False
    assert ('Your password cannot be all numbers.' in user_created['messages'])

    # 3. password == user name
    payload = {'email': '*****@*****.**', 'password': '******'}
    user_created = actions.create_new_user(
        payload, override_authdb_path='sqlite:///test-creation.authdb.sqlite')
    assert user_created['success'] is False
    assert user_created['user_email'] == '*****@*****.**'
    assert user_created['user_id'] is None
    assert user_created['send_verification'] is False
    assert ('Your password is not complex enough. '
            'One or more characters appear appear too frequently.'
            in user_created['messages'])
    assert ('Your password is too similar to either '
            'the domain name of this LCC-Server or your '
            'own email address.' in user_created['messages'])

    # 4. password is OK
    payload = {
        'email': '*****@*****.**',
        'password': '******'
    }
    user_created = actions.create_new_user(
        payload, override_authdb_path='sqlite:///test-creation.authdb.sqlite')
    assert user_created['success'] is True
    assert user_created['user_email'] == '*****@*****.**'
    assert user_created['user_id'] == 4
    assert user_created['send_verification'] is True
    assert ('User account created. Please verify your email address to log in.'
            in user_created['messages'])

    # 5. try to create a new user with an existing email address
    payload = {
        'email': '*****@*****.**',
        'password': '******'
    }
    user_created = actions.create_new_user(
        payload, override_authdb_path='sqlite:///test-creation.authdb.sqlite')
    assert user_created['success'] is False
    assert user_created['user_email'] == '*****@*****.**'
    assert user_created['user_id'] == 4

    # we should not send a verification email because the user already has an
    # account or if the account is not active yet, the last verification email
    # was sent less than 24 hours ago
    assert user_created['send_verification'] is False
    assert ('User account created. Please verify your email address to log in.'
            in user_created['messages'])

    currproc = mp.current_process()
    if getattr(currproc, 'table_meta', None):
        del currproc.table_meta

    if getattr(currproc, 'connection', None):
        currproc.connection.close()
        del currproc.connection

    if getattr(currproc, 'engine', None):
        currproc.engine.dispose()
        del currproc.engine

    try:
        os.remove('test-creation.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-creation.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-creation.authdb.sqlite-wal')
    except Exception as e:
        pass
def test_sessioninfo():
    '''
    This tests if we can add session info to a session dict.

    '''

    try:
        os.remove('test-sessioninfo.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-sessioninfo.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-sessioninfo.authdb.sqlite-wal')
    except Exception as e:
        pass

    get_test_authdb()

    # create the user
    user_payload = {
        'email': '*****@*****.**',
        'password': '******'
    }
    user_created = actions.create_new_user(
        user_payload,
        override_authdb_path='sqlite:///test-sessioninfo.authdb.sqlite')
    assert user_created['success'] is True
    assert user_created['user_email'] == '*****@*****.**'
    assert ('User account created. Please verify your email address to log in.'
            in user_created['messages'])

    # create a new session token
    session_payload = {
        'user_id': 2,
        'client_header': 'Mozzarella Killerwhale',
        'expires': datetime.utcnow() + timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json': {
            'pref_datasets_always_private': True
        }
    }

    # check creation of session
    session_token1 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-sessioninfo.authdb.sqlite')
    assert session_token1['success'] is True
    assert session_token1['session_token'] is not None

    # verify our email
    emailverify = (actions.verify_user_email_address(
        {
            'email': user_payload['email'],
            'user_id': user_created['user_id']
        },
        override_authdb_path='sqlite:///test-sessioninfo.authdb.sqlite'))

    assert emailverify['success'] is True
    assert emailverify['user_id'] == user_created['user_id']
    assert emailverify['is_active'] is True
    assert emailverify['user_role'] == 'authenticated'

    # now make a new session token
    session_payload = {
        'user_id': emailverify['user_id'],
        'client_header': 'Mozzarella Killerwhale',
        'expires': datetime.utcnow() + timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json': {
            'pref_datasets_always_private': True
        }
    }

    # check creation of session
    session_token2 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-sessioninfo.authdb.sqlite')
    assert session_token2['success'] is True
    assert session_token2['session_token'] is not None

    #
    # now try to add info to the session
    #

    session_info_added = actions.auth_session_set_extrainfo(
        {
            'session_token': session_token2['session_token'],
            'extra_info': {
                'this': 'is',
                'a': 'test'
            }
        },
        override_authdb_path='sqlite:///test-sessioninfo.authdb.sqlite',
        raiseonfail=True)

    assert session_info_added['success'] is True
    assert isinstance(session_info_added['session_info']['extra_info_json'],
                      dict)
    assert session_info_added['session_info']['extra_info_json'][
        'this'] == 'is'
    assert session_info_added['session_info']['extra_info_json']['a'] == 'test'

    # get back the new session info
    info_check = actions.auth_session_exists(
        {'session_token': session_token2['session_token']},
        override_authdb_path='sqlite:///test-sessioninfo.authdb.sqlite')

    assert info_check['success'] is True
    assert isinstance(info_check['session_info']['extra_info_json'], dict)
    assert info_check['session_info']['extra_info_json']['this'] == 'is'
    assert info_check['session_info']['extra_info_json']['a'] == 'test'

    currproc = mp.current_process()
    if getattr(currproc, 'table_meta', None):
        del currproc.table_meta

    if getattr(currproc, 'connection', None):
        currproc.connection.close()
        del currproc.connection

    if getattr(currproc, 'engine', None):
        currproc.engine.dispose()
        del currproc.engine

    try:
        os.remove('test-sessioninfo.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-sessioninfo.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-sessioninfo.authdb.sqlite-wal')
    except Exception as e:
        pass
Beispiel #5
0
def test_login():
    '''
    This tests if we can log in successfully or fail correctly.

    '''

    try:
        os.remove('test-login.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-login.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-login.authdb.sqlite-wal')
    except Exception as e:
        pass

    get_test_authdb()

    # create the user
    user_payload = {
        'email': '*****@*****.**',
        'password': '******'
    }
    user_created = actions.create_new_user(
        user_payload,
        override_authdb_path='sqlite:///test-login.authdb.sqlite')
    assert user_created['success'] is True
    assert user_created['user_email'] == '*****@*****.**'
    assert ('User account created. Please verify your email address to log in.'
            in user_created['messages'])

    # create a new session token
    session_payload = {
        'user_id': 2,
        'client_header': 'Mozzarella Killerwhale',
        'expires': datetime.utcnow() + timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json': {
            'pref_datasets_always_private': True
        }
    }

    # check creation of session
    session_token1 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-login.authdb.sqlite')
    assert session_token1['success'] is True
    assert session_token1['session_token'] is not None

    # try logging in now with correct password
    login = actions.auth_user_login(
        {
            'session_token': session_token1['session_token'],
            'email': user_payload['email'],
            'password': user_payload['password']
        },
        override_authdb_path='sqlite:///test-login.authdb.sqlite')

    # this should fail because we haven't verified our email yet
    assert login['success'] is False

    # verify our email
    emailverify = (actions.verify_user_email_address(
        {
            'email': user_payload['email'],
            'user_id': user_created['user_id']
        },
        override_authdb_path='sqlite:///test-login.authdb.sqlite'))

    assert emailverify['success'] is True
    assert emailverify['user_id'] == user_created['user_id']
    assert emailverify['is_active'] is True
    assert emailverify['user_role'] == 'authenticated'

    # now make a new session token
    session_payload = {
        'user_id': emailverify['user_id'],
        'client_header': 'Mozzarella Killerwhale',
        'expires': datetime.utcnow() + timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json': {
            'pref_datasets_always_private': True
        }
    }

    # check creation of session
    session_token2 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-login.authdb.sqlite')
    assert session_token2['success'] is True
    assert session_token2['session_token'] is not None

    # and now try to log in again
    login = actions.auth_user_login(
        {
            'session_token': session_token2['session_token'],
            'email': user_payload['email'],
            'password': user_payload['password']
        },
        override_authdb_path='sqlite:///test-login.authdb.sqlite')

    assert login['success'] is True

    # try logging in now with the wrong password
    login = actions.auth_user_login(
        {
            'session_token': session_token2['session_token'],
            'email': user_payload['email'],
            'password': '******'
        },
        override_authdb_path='sqlite:///test-login.authdb.sqlite')
    assert login['success'] is False

    # tests for no session token provided
    login = actions.auth_user_login(
        {
            'session_token': 'correcthorsebatterystaple',
            'email': user_payload['email'],
            'password': user_payload['password']
        },
        override_authdb_path='sqlite:///test-login.authdb.sqlite')
    assert login['success'] is False

    currproc = mp.current_process()
    if getattr(currproc, 'table_meta', None):
        del currproc.table_meta

    if getattr(currproc, 'connection', None):
        currproc.connection.close()
        del currproc.connection

    if getattr(currproc, 'engine', None):
        currproc.engine.dispose()
        del currproc.engine

    try:
        os.remove('test-login.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-login.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-login.authdb.sqlite-wal')
    except Exception as e:
        pass
def test_login_logout():
    '''
    See if we can login and log out correctly.

    '''

    try:
        os.remove('test-loginlogout.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-loginlogout.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-loginlogout.authdb.sqlite-wal')
    except Exception as e:
        pass

    get_test_authdb()

    # create the user
    user_payload = {
        'email': '*****@*****.**',
        'password': '******'
    }
    user_created = actions.create_new_user(
        user_payload,
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite')
    assert user_created['success'] is True
    assert user_created['user_email'] == '*****@*****.**'
    assert ('User account created. Please verify your email address to log in.'
            in user_created['messages'])

    # create a new session token
    session_payload = {
        'user_id': 2,
        'client_header': 'Mozzarella Killerwhale',
        'expires': datetime.utcnow() + timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json': {
            'pref_datasets_always_private': True
        }
    }

    # check creation of session
    session_token1 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite',
        raiseonfail=True)
    assert session_token1['success'] is True
    assert session_token1['session_token'] is not None

    # try logging in now with correct password
    login = actions.auth_user_login(
        {
            'session_token': session_token1['session_token'],
            'email': user_payload['email'],
            'password': user_payload['password']
        },
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite',
        raiseonfail=True)

    # this should fail because we haven't verified our email yet
    assert login['success'] is False

    # verify our email
    emailverify = (actions.verify_user_email_address(
        {
            'email': user_payload['email'],
            'user_id': user_created['user_id']
        },
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite',
        raiseonfail=True))

    assert emailverify['success'] is True
    assert emailverify['user_id'] == user_created['user_id']
    assert emailverify['is_active'] is True
    assert emailverify['user_role'] == 'authenticated'

    # now make a new session token
    session_payload = {
        'user_id': 2,
        'client_header': 'Mozzarella Killerwhale',
        'expires': datetime.utcnow() + timedelta(hours=1),
        'ip_address': '1.1.1.1',
        'extra_info_json': {
            'pref_datasets_always_private': True
        }
    }

    # check creation of session
    session_token2 = actions.auth_session_new(
        session_payload,
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite',
        raiseonfail=True)
    assert session_token2['success'] is True
    assert session_token2['session_token'] is not None

    # and now try to log in again
    login = actions.auth_user_login(
        {
            'session_token': session_token2['session_token'],
            'email': user_payload['email'],
            'password': user_payload['password']
        },
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite',
        raiseonfail=True)

    assert login['success'] is True

    # make sure the session token we used to log in is gone
    # check if our session was deleted correctly
    session_still_exists = actions.auth_session_exists(
        {'session_token': session_token2['session_token']},
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite')
    assert session_still_exists['success'] is False

    # start a new session with this user's user ID
    authenticated_session_token = actions.auth_session_new(
        {
            'user_id': login['user_id'],
            'client_header': 'Mozzarella Killerwhale',
            'expires': datetime.utcnow() + timedelta(hours=1),
            'ip_address': '1.1.1.1',
            'extra_info_json': {
                'pref_datasets_always_private': True
            }
        },
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite',
        raiseonfail=True)

    # now see if we can log out
    logged_out = actions.auth_user_logout(
        {
            'session_token': authenticated_session_token['session_token'],
            'user_id': login['user_id']
        },
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite',
        raiseonfail=True)

    assert logged_out['success'] is True

    # check if our session was deleted correctly
    session_still_exists = actions.auth_session_exists(
        {'session_token': authenticated_session_token},
        override_authdb_path='sqlite:///test-loginlogout.authdb.sqlite',
        raiseonfail=True)

    assert session_still_exists['success'] is False

    currproc = mp.current_process()
    if getattr(currproc, 'table_meta', None):
        del currproc.table_meta

    if getattr(currproc, 'connection', None):
        currproc.connection.close()
        del currproc.connection

    if getattr(currproc, 'engine', None):
        currproc.engine.dispose()
        del currproc.engine

    try:
        os.remove('test-loginlogout.authdb.sqlite')
    except Exception as e:
        pass
    try:
        os.remove('test-loginlogout.authdb.sqlite-shm')
    except Exception as e:
        pass
    try:
        os.remove('test-loginlogout.authdb.sqlite-wal')
    except Exception as e:
        pass