Esempio n. 1
0
def test_api_get_trust_no_modules():
    '''Tests that api.py get_trust fails when not supplied modules'''
    rec = api.Receiver()
    launderer = Launderer(rec)
    launderer.invoke_untouchable()
    assert launderer.status == 501
    assert launderer.score == 'This server does not have any data collection and analysis modules installed'
Esempio n. 2
0
def test_api_get_trust():
    '''Tests api.py get_trust'''
    rec = api.Receiver()
    rec.add_comparer('fake_data_type_expired', fake_comparer, 1)
    rec.add_comparer('fake_data_type_passing_1', fake_comparer, 1)
    rec.add_comparer('fake_data_type_passing_2', fake_comparer, 1)
    rec.add_comparer('fake_data_type_missing', fake_comparer, 1)
    launderer = Launderer(rec)
    launderer.invoke_untouchable()
    assert launderer.status == 200
    assert launderer.score == '0.25'
Esempio n. 3
0
def test_api_copy_data():
    '''Tests the copy_data method of the api class'''
    rec = api.Receiver()
    rec.add_translator('fake_data_type', fake_translator)
    ses = {'fake_data_type': 'fake_data'}
    fake_user_data = FakeDBObject()
    '''{
		'uid':'fake_uid',
		'_id':'fake_id',
		'data':{}
	})'''
    rec.copy_data(ses, fake_user_data)
    assert fake_user_data.added_data == {
        'fake_data_type': 'translated_fake_data'
    }
Esempio n. 4
0
def test_api_add_data():
    '''Tests the add_data method of the api class'''
    headers = {'Host': '127.0.0.1', 'X-Real-IP': '127.0.0.1'}

    rec = api.Receiver()
    rec.add_hasher('fake_data', fake_hasher)

    req = {
        'name': 'fake_data',
        'ck': 'fake_ck',
        'sid': 'fake_sid',
        'data': 'fake_data'
    }

    fake_site_list = FakeCollection({
        'clientKey': 'fake_ck',
        '_id': 'fake_id',
        'salts': {
            'fake_data': 'fake_salt'
        },
        'host': '127.0.0.1',
        'serverKey': 'irrelivant_server_key'
    })
    fake_site_data = FakeCollection({
        'sid': 'fake_sid',
        '_id': 'fake_id',
        'data': {},
        'expireTimes': {}
    })
    db = {
        'siteList': fake_site_list,
        'sessionData_site-fake_id': fake_site_data
    }

    rec.add_data(req, headers, db)
    assert fake_site_list.finder_call == {'clientKey': 'fake_ck'}
    assert fake_site_data.finder_call == {'sid': 'fake_sid'}
    assert fake_site_data.replacer_call['sid'] == 'fake_sid'
    assert fake_site_data.replacer_call['data'] == {
        'fake_data': 'hashed_fake_data'
    }
    curtime = datetime.datetime.utcnow()
    hour = datetime.timedelta(hours=1)
    newtime = hour + curtime
    assert fake_site_data.replacer_call['expireTimes']['fake_data'] < newtime
    assert fake_site_data.replacer_call['expireTimes']['fake_data'] > curtime
Esempio n. 5
0
#Creates and initializes API receiver and client JS storage class

import hijackingprevention.api as api
import hijackingprevention.client as client

rec = api.Receiver()
mods = client.Client()