Exemplo n.º 1
0
    def test_initialize_from_url(self):
        self.assertRaises(TypeError, lambda: Pusher.from_url(4))
        self.assertRaises(Exception, lambda: Pusher.from_url(u'httpsahsutaeh'))

        conf = Pusher.from_url(u'http://*****:*****@host/apps/4')
        self.assertEqual(conf.ssl, False)
        self.assertEqual(conf.key, u'foo')
        self.assertEqual(conf.secret, u'bar')
        self.assertEqual(conf.host, u'host')
        self.assertEqual(conf.app_id, u'4')

        conf = Pusher.from_url(u'https://*****:*****@host/apps/4')
        self.assertEqual(conf.ssl, True)
        self.assertEqual(conf.key, u'foo')
        self.assertEqual(conf.secret, u'bar')
        self.assertEqual(conf.host, u'host')
        self.assertEqual(conf.app_id, u'4')
Exemplo n.º 2
0
 def test_x_pusher_library_header(self):
     conf = Pusher.from_url(u'http://*****:*****@somehost/apps/4')
     req = Request(conf._pusher_client, u'GET', u'/some/obscure/api',
                   {u'foo': u'bar'})
     self.assertTrue('X-Pusher-Library' in req.headers)
     pusherLib = req.headers['X-Pusher-Library']
     self.assertRegexpMatches(pusherLib,
                              r'^pusher-http-python \d+(\.\d+)+(rc\d+)?$')
Exemplo n.º 3
0
    def test_authenticate_for_private_channels(self):
        pusher = Pusher.from_url(u'http://*****:*****@host/apps/4')

        expected = {
            u'auth': u"foo:89955e77e1b40e33df6d515a5ecbba86a01dc816a5b720da18a06fd26f7d92ff"
        }

        self.assertEqual(pusher.authenticate(u'private-channel', u'345.23'), expected)
Exemplo n.º 4
0
    def test_validate_webhook_bad_time(self):
        pusher = Pusher.from_url(u'http://*****:*****@host/apps/4')

        body = u'{"time_ms": 1000000}'
        signature = six.text_type(hmac.new(pusher.secret.encode('utf8'), body.encode('utf8'), hashlib.sha256).hexdigest())

        with mock.patch('time.time', return_value=1301):
            self.assertEqual(pusher.validate_webhook(pusher.key, signature, body), None)
Exemplo n.º 5
0
    def test_initialize_from_url(self):
        self.assertRaises(TypeError, lambda: Pusher.from_url(4))
        self.assertRaises(Exception, lambda: Pusher.from_url(u"httpsahsutaeh"))

        conf = Pusher.from_url(u"http://*****:*****@host/apps/4")
        self.assertEqual(conf.ssl, False)
        self.assertEqual(conf.key, u"foo")
        self.assertEqual(conf.secret, u"bar")
        self.assertEqual(conf.host, u"host")
        self.assertEqual(conf.app_id, u"4")

        conf = Pusher.from_url(u"https://*****:*****@host/apps/4")
        self.assertEqual(conf.ssl, True)
        self.assertEqual(conf.key, u"foo")
        self.assertEqual(conf.secret, u"bar")
        self.assertEqual(conf.host, u"host")
        self.assertEqual(conf.app_id, u"4")
  def setUp(self):

    # temporary ignoring warnings until these are sorted:
    # https://github.com/gabrielfalcao/HTTPretty/issues/368
    if sys.version_info[0] >= 3:
        import warnings
        warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed file <_io.BufferedRandom name*")

    self.pusher = Pusher.from_url(u'http://*****:*****@api.pusherapp.com/apps/4')
Exemplo n.º 7
0
 def test_x_pusher_library_header(self):
     conf = Pusher.from_url(u'http://*****:*****@somehost/apps/4')
     req = Request(conf._pusher_client, u'GET', u'/some/obscure/api', {u'foo': u'bar'})
     self.assertTrue('X-Pusher-Library' in req.headers)
     pusherLib = req.headers['X-Pusher-Library']
     regex = r'^pusher-http-python \d+(\.\d+)+(rc\d+)?$'
     if sys.version_info < (3,):
         self.assertRegexpMatches(pusherLib, regex)
     else:
         self.assertRegex(pusherLib, regex)
Exemplo n.º 8
0
    def test_validate_webhook_bad_signature(self):
        pusher = Pusher.from_url(u'http://*****:*****@host/apps/4')

        body = u'some body'
        signature = u'some signature'

        with mock.patch('time.time') as time_mock:
            self.assertEqual(pusher.validate_webhook(pusher.key, signature, body), None)

        time_mock.assert_not_called()
Exemplo n.º 9
0
    def test_validate_webhook_bad_key(self):
        pusher = Pusher.from_url(u'http://*****:*****@host/apps/4')

        body = u'some body'
        signature = six.text_type(hmac.new(pusher.secret.encode(u'utf8'), body.encode(u'utf8'), hashlib.sha256).hexdigest())

        with mock.patch('time.time') as time_mock:
            self.assertEqual(pusher.validate_webhook(u'badkey', signature, body), None)

        time_mock.assert_not_called()
Exemplo n.º 10
0
    def test_validate_webhook_bad_types(self):
        pusher = Pusher.from_url(u'http://*****:*****@host/apps/4')

        pusher.validate_webhook(u'key', u'signature', u'body')

        # These things are meant to be human readable, so enforcing being text is
        # sensible.

        with mock.patch('time.time') as time_mock:
            self.assertRaises(TypeError, lambda: pusher.validate_webhook(4, u'signature', u'body'))
            self.assertRaises(TypeError, lambda: pusher.validate_webhook(u'key', 4, u'body'))
            self.assertRaises(TypeError, lambda: pusher.validate_webhook(u'key', u'signature', 4))

        time_mock.assert_not_called()
    def test_get_signature_generation(self):
        conf = Pusher.from_url(u'http://*****:*****@somehost/apps/4')

        expected = {
            u'auth_key': u'key',
            u'auth_signature': u'5c49f04a95eedc9028b1e0e8de7c2c7ad63504a0e3b5c145d2accaef6c14dbac',
            u'auth_timestamp': u'1000',
            u'auth_version': u'1.0',
            u'body_md5': u'd41d8cd98f00b204e9800998ecf8427e',
            u'foo': u'bar'
        }

        with mock.patch('time.time', return_value=1000):
            req = Request(conf._pusher_client, u'GET', u'/some/obscure/api', {u'foo': u'bar'})
            self.assertEqual(req.query_params, expected)
Exemplo n.º 12
0
    def test_get_signature_generation(self):
        conf = Pusher.from_url(u'http://*****:*****@somehost/apps/4')

        expected = {
            u'auth_key': u'key',
            u'auth_signature': u'5c49f04a95eedc9028b1e0e8de7c2c7ad63504a0e3b5c145d2accaef6c14dbac',
            u'auth_timestamp': u'1000',
            u'auth_version': u'1.0',
            u'body_md5': u'd41d8cd98f00b204e9800998ecf8427e',
            u'foo': u'bar'
        }

        with mock.patch('time.time', return_value=1000):
            req = Request(conf, u'GET', u'/some/obscure/api', {u'foo': u'bar'})
            self.assertEqual(req.query_params, expected)
Exemplo n.º 13
0
    def setUp(self):
        class JSONEncoder(json.JSONEncoder):
            def default(self, o):
                if isinstance(o, Decimal):
                    return str(o)
                return super(JSONEncoder, self).default(o)

        constants = {"NaN": 99999}

        class JSONDecoder(json.JSONDecoder):
            def __init__(self, **kwargs):
                super(JSONDecoder, self).__init__(parse_constant=constants.__getitem__)

        self.pusher = Pusher.from_url(u'http://*****:*****@somehost/apps/4',
                                      json_encoder=JSONEncoder,
                                      json_decoder=JSONDecoder)
    def test_post_signature_generation(self):
        conf = Pusher.from_url(u'http://*****:*****@somehost/apps/4')

        expected = {
            u'auth_key': u'key',
            u'auth_signature': u'e05fa4cafee86311746ee3981d5581a5e4e87c27bbab0aeb1059e2df5c90258b',
            u'auth_timestamp': u'1000',
            u'auth_version': u'1.0',
            u'body_md5': u'94232c5b8fc9272f6f73a1e36eb68fcf'
        }

        with mock.patch('time.time', return_value=1000):
            # patching this, because json can be unambiguously parsed, but not
            # unambiguously generated (think whitespace).
            with mock.patch('json.dumps', return_value='{"foo": "bar"}') as json_dumps_mock:
                req = Request(conf._pusher_client, u'POST', u'/some/obscure/api', {u'foo': u'bar'})
                self.assertEqual(req.query_params, expected)

            json_dumps_mock.assert_called_once_with({u"foo": u"bar"})
Exemplo n.º 15
0
    def test_post_signature_generation(self):
        conf = Pusher.from_url(u'http://*****:*****@somehost/apps/4')

        expected = {
            u'auth_key': u'key',
            u'auth_signature': u'e05fa4cafee86311746ee3981d5581a5e4e87c27bbab0aeb1059e2df5c90258b',
            u'auth_timestamp': u'1000',
            u'auth_version': u'1.0',
            u'body_md5': u'94232c5b8fc9272f6f73a1e36eb68fcf'
        }

        with mock.patch('time.time', return_value=1000):
            # patching this, because json can be unambiguously parsed, but not 
            # unambiguously generated (think whitespace).
            with mock.patch('json.dumps', return_value='{"foo": "bar"}') as json_dumps_mock:
                req = Request(conf, u'POST', u'/some/obscure/api', {u'foo': u'bar'})
                self.assertEqual(req.query_params, expected)

            json_dumps_mock.assert_called_once({u"foo": u"bar"})
Exemplo n.º 16
0
    def test_authenticate_for_presence_channels(self):
        pusher = Pusher.from_url(u'http://*****:*****@host/apps/4')

        custom_data = {
            u'user_id': u'fred',
            u'user_info': {
                u'key': u'value'
            }
        }

        expected = {
            u'auth': u"foo:e80ba6439492c2113022c39297a87a948de14061cc67b5788e045645a68b8ccd",
            u'channel_data': u"{\"user_id\":\"fred\",\"user_info\":{\"key\":\"value\"}}"
        }

        with mock.patch('json.dumps', return_value=expected[u'channel_data']) as dumps_mock:
            actual = pusher.authenticate(u'presence-channel', u'345.43245', custom_data)

        self.assertEqual(actual, expected)
        dumps_mock.assert_called_once_with(custom_data, cls=None)
Exemplo n.º 17
0
    def test_authenticate_types(self):
        pusher = Pusher.from_url(u'http://*****:*****@host/apps/4')

        self.assertRaises(TypeError, lambda: pusher.authenticate(2423, u'34554'))
        self.assertRaises(TypeError, lambda: pusher.authenticate(u'plah', 234234))
        self.assertRaises(ValueError, lambda: pusher.authenticate(u'::', u'345345'))
Exemplo n.º 18
0
 def setUp(self):
     self.pusher = Pusher.from_url(u'http://*****:*****@somehost/apps/4')
 def setUp(self):
   self.pusher = Pusher.from_url(u'http://*****:*****@api.pusherapp.com/apps/4')
 def setUp(self):
     self.pusher = Pusher.from_url(
         u'http://*****:*****@api.pusherapp.com/apps/4')
Exemplo n.º 21
0
from little_pger import LittlePGer
from redis import StrictRedis
from pusher import Pusher
from flask import g
from flask_github import GitHub

import settings


redis = StrictRedis.from_url(settings.REDIS_URL)
pusher = Pusher.from_url(settings.PUSHER_URL)
pg = LittlePGer(settings.POSTGRESQL_URL, commit=True)


github = GitHub()


@github.access_token_getter
def get_token():
    return g.github_token