Exemplo n.º 1
0
    def test_get_filter(self):
        fltr = sbf(['sha512', 'md5', 'sha1'],
                   bit_mapping=4,
                   hash_salt_path="../hash_salt/hash_salt")
        sbf_fltr = fltr.get_filter()

        self.assertEqual(np.count_nonzero(sbf_fltr), 0)
Exemplo n.º 2
0
    def test_insert(self):
        fltr = sbf(['sha512', 'md5', 'sha1'],
                   bit_mapping=4,
                   hash_salt_path="../hash_salt/hash_salt")
        fltr.insert("51.8989#-8.4825", 1)

        self.assertNotEqual(np.count_nonzero(fltr.get_filter()), 0)
Exemplo n.º 3
0
    def test_get_stats(self):
        fltr = sbf(['sha512', 'md5', 'sha1'],
                   bit_mapping=4,
                   hash_salt_path="../hash_salt/hash_salt")
        fltr_stats = fltr.get_stats()

        self.assertEqual(int(fltr_stats['Number of Cells']), pow(2, 4))
        self.assertEqual(ast.literal_eval(fltr_stats['Hash Family']),
                         ['sha512', 'md5', 'sha1'])
Exemplo n.º 4
0
def update_hash_family():
    if request.method == 'POST':
        hash_family, hf_options = _hash_functions(request.form.getlist('hf'))

        app.my_sbf.clear_filter()
        app.my_sbf = sbf(request.form.getlist('hf'))
        _set_session()

        return render_template('edit-details.html',
                               hash_family=Markup(hash_family),
                               hf_options=Markup(hf_options))
Exemplo n.º 5
0
def reset_hash_family():
    if request.method == 'POST':
        default_hash_family = ['md5', 'sha256', 'sha1']
        hash_family, hf_options = _hash_functions(default_hash_family)

        app.my_sbf.clear_filter()
        app.my_sbf = sbf(default_hash_family)
        _set_session()

        return render_template('edit-details.html',
                               hash_family=Markup(hash_family),
                               hf_options=Markup(hf_options))
Exemplo n.º 6
0
def index():
    app.my_sbf = sbf(HASH_FAMILY)

    _set_session()

    return render_template(
        'index.html',
        sbf_table=Markup(session.get('sbf_table')),
        sbf_stats=Markup(session.get('sbf_stats')),
        import_message=Markup(session.get('import_message')),
        area_link=Markup(session.get('area_link')),
        check_result_table=Markup(session.get('check_result_table')),
        check_result_conclusion=Markup(session.get('check_result_conclusion')))
Exemplo n.º 7
0
    def test_check(self):
        fltr = sbf(['sha512', 'md5', 'sha1'],
                   bit_mapping=4,
                   hash_salt_path="../hash_salt/hash_salt")
        fltr.insert("51.8989#-8.4825", 1)
        fltr_check_positive = fltr.check("51.8989#-8.4825")
        fltr_check_negative = fltr.check("51.8980#-8.4845")

        areas_1, areas_2 = [], []
        for i in ['sha512', 'md5', 'sha1']:
            areas_1.append(fltr_check_positive[i][1])
            areas_2.append(fltr_check_negative[i][1])

        self.assertEqual(min(int(m) for m in areas_1), 1)
        self.assertEqual(min(int(m) for m in areas_2), 0)
Exemplo n.º 8
0
 def test_invalid_hash_family(self):
     with self.assertRaisesRegex(AttributeError, "Invalid hash family."):
         sbf(['sha512', 'md5', 'sha'])
Exemplo n.º 9
0
 def test_hash_salt_path(self):
     with self.assertRaisesRegex(IOError, "Error opening hash salts"):
         sbf(['sha512', 'md5', 'sha1'])
Exemplo n.º 10
0
 def test_invalid_bit_mapping(self):
     with self.assertRaisesRegex(AttributeError, "Invalid bit mapping."):
         sbf(['sha512', 'md5', 'sha1'], bit_mapping=65)
Exemplo n.º 11
0
from flask import Flask, render_template, Markup, session, request
from scripts.layout import Layout
from scripts.sbf import sbf

app = Flask(__name__)

app.secret_key = 'spacial bloom filter'

HASH_FAMILY = ['md5', 'sha1', 'sha256']

format_layout = Layout(10)
app.my_sbf = sbf(HASH_FAMILY)


@app.route('/index')
@app.route('/')
def index():
    app.my_sbf = sbf(HASH_FAMILY)

    _set_session()

    return render_template(
        'index.html',
        sbf_table=Markup(session.get('sbf_table')),
        sbf_stats=Markup(session.get('sbf_stats')),
        import_message=Markup(session.get('import_message')),
        area_link=Markup(session.get('area_link')),
        check_result_table=Markup(session.get('check_result_table')),
        check_result_conclusion=Markup(session.get('check_result_conclusion')))