Exemplo n.º 1
0
    def test_render_POST_ping(self):
        r = self.res.render_POST(self.m_request)

        self.assertEqual(NOT_DONE_YET, r)
        self.assert_calls_equal(
            self.m_request,
            [call.getHeader('X-Hub-Signature'),
             call.content.getvalue(),
             call.getHeader('X-Github-Event'),
             call.getHeader('X-Github-Delivery'),
             call.setResponseCode(200, 'OK'),
             call.finish()])

        self.assert_calls_equal(
            self.m_handle_event,
            [call('a fake unique id', 'ping', self.pingmessage)])

        self.assert_calls_equal(
            self.m_loghandler,
            [])
Exemplo n.º 2
0
    def test_render_POST_unhandled_event_type(self):
        m_request = self._setup_mock_request('unknown event type', [])

        r = self.res.render_POST(m_request)

        self.assertEqual(NOT_DONE_YET, r)
        self.assert_calls_equal(
            m_request,
            [call.getHeader('X-Hub-Signature'),
             call.content.getvalue(),
             call.getHeader('X-Github-Event'),
             call.getHeader('X-Github-Delivery'),
             call.setResponseCode(400, 'Event Not Supported'),
             call.finish()])

        self.assert_calls_equal(
            self.m_loghandler,
            [call.handle(
                ArgIsLogRecord(
                    levelname='INFO',
                    msg='Unhandled github %r event %r.'))])
Exemplo n.º 3
0
    def test_render_POST_ping(self):
        m_request = self._setup_mock_request('ping', self.pingmessage)

        r = self.res.render_POST(m_request)

        self.assertEqual(NOT_DONE_YET, r)
        self.assert_calls_equal(
            m_request,
            [call.getHeader('X-Hub-Signature'),
             call.content.getvalue(),
             call.getHeader('X-Github-Event'),
             call.getHeader('X-Github-Delivery'),
             call.setResponseCode(200, 'OK'),
             call.finish()])

        # Pings do not reach the push handler:
        self.assert_calls_equal(
            self.m_handle_push_tag,
            [])

        self.assert_calls_equal(
            self.m_loghandler,
            [])
Exemplo n.º 4
0
    def test_render_POST_ping_tampered(self):
        tweakedmessage = self.pingmessage.copy()
        tweakedmessage['hook_id'] += 1

        self.m_request.content.getvalue.return_value = json.dumps(tweakedmessage)

        r = self.res.render_POST(self.m_request)

        self.assertEqual(NOT_DONE_YET, r)
        self.assert_calls_equal(
            self.m_request,
            [call.getHeader('X-Hub-Signature'),
             call.content.getvalue(),
             call.setResponseCode(403, 'FORBIDDEN'),
             call.finish()])

        self.assert_calls_equal(
            self.m_loghandler,
            [call.handle(ArgIsLogRecord(levelname='WARNING'))])
Exemplo n.º 5
0
    def test_render_POST_ping_tampered(self):
        m_request = self._setup_mock_request('ping', self.pingmessage)

        tweakedmessage = self.pingmessage.copy()
        tweakedmessage['hook_id'] += 1

        m_request.content.getvalue.return_value = \
            json.dumps(tweakedmessage)

        r = self.res.render_POST(m_request)

        self.assertEqual(NOT_DONE_YET, r)
        self.assert_calls_equal(
            m_request,
            [call.getHeader('X-Hub-Signature'),
             call.content.getvalue(),
             call.setResponseCode(403, 'FORBIDDEN'),
             call.finish()])

        self.assert_calls_equal(
            self.m_loghandler,
            [call.handle(ArgIsLogRecord(levelname='WARNING'))])