Ejemplo n.º 1
0
    def setUp(self):
        """Set up the app for testing."""
        # Create a webtest Test App for use
        self.app = flask_webtest.TestApp(dnstwister.app)

        # Clear the webapp cache
        dnstwister.cache.clear()
Ejemplo n.º 2
0
 def test_bug_presence(self):
     """ This test will BREAK when the bug is no longer present upstream, at which point this
     fix can be considered for removal.  """
     app = BugApp.testing_prep(FIX_FLASK_WTF_BUG=False)
     client = flask_webtest.TestApp(app)
     client.get('/form')
     assert 'csrf_token' in flask.g
Ejemplo n.º 3
0
    def test_good_signature(self, m_process):
        ts = str(int(arrow.utcnow().float_timestamp)).encode()
        token = b'b' * 32
        key = b'a' * 36

        body = {
            'signature': {
                'timestamp':
                ts.decode(),
                'token':
                token.decode(),
                'signature':
                hmac.new(key=key, msg=ts + token,
                         digestmod=hashlib.sha256).hexdigest()
            },
            'event-data': {
                'foo': 'bar'
            }
        }

        client = flask_webtest.TestApp(flask.current_app)
        resp = client.post_json('/noop-webhook', body)

        assert resp.status_code == 200
        assert resp.text == 'OK'

        m_process.assert_called_once_with({'foo': 'bar'})
Ejemplo n.º 4
0
    def test_calls_update_status_method(self, m_extensions):
        ts = str(int(arrow.utcnow().float_timestamp)).encode()
        token = b'b' * 32
        key = b'a' * 36

        body = {
            'signature': {
                'timestamp':
                ts.decode(),
                'token':
                token.decode(),
                'signature':
                hmac.new(key=key, msg=ts + token,
                         digestmod=hashlib.sha256).hexdigest()
            },
            'event-data': {
                'foo': 'bar'
            }
        }

        client = flask_webtest.TestApp(flask.current_app)
        resp = client.post_json('/log-status-webhook', body)

        assert resp.status_code == 200
        assert resp.text == 'OK'

        m_update = m_extensions.__getitem__.return_value.mailgun_update_message_status
        m_update.assert_called_once_with({'foo': 'bar'})
def test_no_subscribe_links_without_emails_enabled(monkeypatch):
    monkeypatch.setenv('feature.async_search', 'true')
    app = flask_webtest.TestApp(dnstwister.app)

    domain = 'a.com'
    hexdomain = dnstwister.tools.encode_domain(domain)

    search_page = app.get('/search?ed={}'.format(hexdomain))

    assert '/email/subscribe/' not in search_page.body
Ejemplo n.º 6
0
def webapp():
    """Create a webapp fixture for accessing the site.

    Just include 'webapp' as an argument to the test method to use.
    """
    # Create a webtest Test App for use
    testapp = flask_webtest.TestApp(dnstwister.app)
    testapp.app.debug = True

    return testapp
def test_isubscriptions_link_unicode(monkeypatch):
    monkeypatch.setenv('feature.emails', 'true')
    monkeypatch.setenv('feature.async_search', 'true')

    app = flask_webtest.TestApp(dnstwister.app)
    emailer = dnstwister.views.www.email.emailer
    repository = dnstwister.repository

    assert emailer.sent_emails == []

    domain = u'\u0454a.com'  # ea.com, but with a funny 'e'
    hexdomain = dnstwister.tools.encode_domain(domain)
    subscribe_path = '/email/subscribe/{}'.format(hexdomain)

    search_page = app.get('/search?ed={}'.format(hexdomain))

    assert subscribe_path in search_page.body

    subscribe_page = app.get(subscribe_path)

    assert '\xd1\x94a.com (xn--a-9ub.com)' in subscribe_page.body

    subscribe_page.form['email_address'] = '*****@*****.**'
    pending_page = subscribe_page.form.submit()

    assert pending_page.request.url.endswith('pending_verify/786e2d2d612d3975622e636f6d')
    assert '\xd1\x94a.com (xn--a-9ub.com)' in pending_page.body

    assert list(repository.isubscriptions()) == []

    verify_code = repository.db.data.items()[0][0].split(
        'email_sub_pending:'
    )[1]
    verify_path = '/email/verify/{}'.format(
        verify_code
    )
    verify_url = 'http://localhost{}'.format(verify_path)

    assert len(emailer.sent_emails) == 1

    sent_email = emailer.sent_emails[0][:2]

    assert sent_email == (
        '*****@*****.**', 'Please verify your subscription'
    )

    assert verify_url in emailer.sent_emails[0][2]

    subscribed_page = app.get(verify_path)

    assert 'You are now subscribed' in subscribed_page.body
    assert '\xd1\x94a.com (xn--a-9ub.com)' in subscribed_page.body

    assert len(list(repository.isubscriptions())) == 1
Ejemplo n.º 8
0
    def test_post(self):
        ta = flask_webtest.TestApp(app)
        resp = ta.get('/')

        resp.form['csv_file'] = webtest.Upload(
            'foo.csv',
            b'foo, 2000-01-01\nbar, 1980-01-01',
            content_type='text/csv')
        resp = resp.form.submit()

        assert resp.text == 'Age sum: 56'
Ejemplo n.º 9
0
    def test_female_age_limit_39(self):
        ta = flask_webtest.TestApp(app)
        resp = ta.get('/')

        resp.form['csv_file'] = webtest.Upload(
            'foo.csv',
            b'foo, 2000-01-01\nbar, 1980-01-01\n,2010-01-01\nsuzy,1978-01-01,f',
            content_type='text/csv'
        )
        resp = resp.form.submit()

        assert resp.text == 'Age sum: 95'
Ejemplo n.º 10
0
def webapp():
    """Create a webapp fixture for accessing the site.

    Just include 'webapp' as an argument to the test method to use.
    """
    # Create a webtest Test App for use
    testapp = flask_webtest.TestApp(mapbuilder.serve.app)
    testapp.app.debug = True

    # Make sure there's no map.
    testapp.delete('/map')

    return testapp
def test_isubscriptions_link(monkeypatch):
    monkeypatch.setenv('feature.emails', 'true')
    monkeypatch.setenv('feature.async_search', 'true')

    app = flask_webtest.TestApp(dnstwister.app)
    emailer = dnstwister.views.www.email.emailer
    repository = dnstwister.repository

    assert emailer.sent_emails == []

    domain = 'a.com'
    hexdomain = dnstwister.tools.encode_domain(domain)
    subscribe_path = '/email/subscribe/{}'.format(hexdomain)

    search_page = app.get('/search?ed={}'.format(hexdomain))

    assert subscribe_path in search_page.body

    subscribe_page = app.get(subscribe_path)

    subscribe_page.form['email_address'] = '*****@*****.**'
    subscribe_page.form.submit()

    assert list(repository.isubscriptions()) == []

    verify_code = repository.db.data.items()[0][0].split(
        'email_sub_pending:'
    )[1]
    verify_path = '/email/verify/{}'.format(
        verify_code
    )
    verify_url = 'http://localhost{}'.format(verify_path)

    assert len(emailer.sent_emails) == 1

    sent_email = emailer.sent_emails[0][:2]

    assert sent_email == (
        '*****@*****.**', 'Please verify your subscription'
    )

    assert verify_url in emailer.sent_emails[0][2]

    subscribed_page = app.get(verify_path)

    assert 'You are now subscribed' in subscribed_page.body

    assert len(list(repository.isubscriptions())) == 1
Ejemplo n.º 12
0
def test_unsubscribe_unicode():
    """Test can unsubscribe."""
    app = flask_webtest.TestApp(dnstwister.app)
    repository = dnstwister.repository

    domain = u'www.\u0454xample.com'
    email = '*****@*****.**'
    sub_id = '1234'

    assert len(list(repository.isubscriptions())) == 0

    repository.subscribe_email(sub_id, email, domain, False)

    assert len(list(repository.isubscriptions())) == 1

    app.get('/email/unsubscribe/{}'.format(sub_id))

    assert len(list(repository.isubscriptions())) == 0
Ejemplo n.º 13
0
def test_email_address_validation_remembers_hide_noisy_flag():
    app = flask_webtest.TestApp(dnstwister.app)

    domain = 'a.com'
    hexdomain = binascii.hexlify(domain)
    subscribe_path = '/email/subscribe/{}'.format(hexdomain)

    subscribe_page = app.get(subscribe_path)

    subscribe_page.form['email_address'] = ' '
    subscribe_page.form['hide_noisy'] = 'true'
    response = subscribe_page.form.submit()

    assert response.status_code == 302
    assert response.headers[
        'location'] == 'http://localhost/email/subscribe/{}/0?hide_noisy=True'.format(
            hexdomain)

    assert 'Email address is required' in response.follow().body
def test_email_address_required(monkeypatch):
    monkeypatch.setenv('feature.emails', 'true')

    app = flask_webtest.TestApp(dnstwister.app)

    domain = 'a.com'
    hexdomain = binascii.hexlify(domain)
    subscribe_path = '/email/subscribe/{}'.format(hexdomain)

    subscribe_page = app.get(subscribe_path)

    assert 'Email address is required' not in subscribe_page.body

    subscribe_page.form['email_address'] = ' '
    response = subscribe_page.form.submit()

    assert response.status_code == 302
    assert response.headers['location'] == 'http://localhost/email/subscribe/{}/0?hide_noisy=False'.format(hexdomain)

    assert 'Email address is required' in response.follow().body
Ejemplo n.º 15
0
    def test_bad_signature(self, m_process):
        ts = str(int(arrow.utcnow().float_timestamp)).encode()
        token = b'b' * 32
        key = b'a' * 35 + b'b'

        body = {
            'signature': {
                'timestamp':
                ts.decode(),
                'token':
                token.decode(),
                'signature':
                hmac.new(key=key, msg=ts + token,
                         digestmod=hashlib.sha256).hexdigest()
            },
            'event-data': {}
        }

        client = flask_webtest.TestApp(flask.current_app)
        resp = client.post_json('/noop-webhook', body, status=403)

        assert resp.status_code == 403
        assert not m_process.called
Ejemplo n.º 16
0
 def test_bug_fix(self):
     app = BugFixApp.testing_prep()
     client = flask_webtest.TestApp(app)
     client.get('/form')
     assert 'csrf_token' not in flask.g
Ejemplo n.º 17
0
 def setup_class(cls):
     cls.client = flask_webtest.TestApp(app)
Ejemplo n.º 18
0
 def setup_class(cls):
     app.testing = True
     cls.client = flask_webtest.TestApp(app)
Ejemplo n.º 19
0
 def setUp(self):
     """ Set up the mock memcache.
     """
     # Create a webtest Test App for use
     self.app = flask_webtest.TestApp(dnstwister.app)
Ejemplo n.º 20
0
 def test_get(self):
     ta = flask_webtest.TestApp(app)
     resp = ta.get('/')
     assert 'Upload CSV file' in resp.text
Ejemplo n.º 21
0
 def setUp(self):
     # Create a webtest Test App for use
     self.app = flask_webtest.TestApp(dnstwister.app)