Example #1
0
def notification(request):
    """
    An end point for Bango to communicate with using the Event Notification
    API. This does the Basic Auth and then passes the whole thing on to do
    solitude.
    """
    log.info('Bango notification received')

    try:
        username, password = basic(request)
    except ValueError:
        log.warning('Basic auth failed')
        return HttpResponseForbidden(request)

    try:
        # Just take the whole request and stuff into JSON for passing down
        # the pipe.
        client.slumber.bango.event.post({
            'notification': request.raw_post_data,
            'password': password,
            'username': username
        })
    except HttpClientError, err:
        log.error('Error calling solitude: {0}'.format(err), exc_info=True)
        # Sending something other than a 200, will cause Bango to re-send it.
        return HttpResponse(content='Not OK', status=502)
Example #2
0
def notification(request):
    """
    An end point for Bango to communicate with using the Event Notification
    API. This does the Basic Auth and then passes the whole thing on to do
    solitude.
    """
    log.info("Bango notification received")

    try:
        username, password = basic(request)
    except NoHeader:
        log.info("Header not present")
        return HttpResponseNotAuthenticated(request)
    except WrongHeader:
        log.info("Header given but invalid")
        return HttpResponseForbidden(request)

    # This should help figure out why.
    log.info(
        "Bango notification encoding={0.encoding} "
        "content_type={0.META[CONTENT_TYPE]} POST keys={1}".format(request, request.POST.keys())
    )

    # We want to send XML as bytes to Solitude.
    notice = request.POST["XML"].encode("utf8")
    log.debug("Bango notice: {0}".format(repr(notice)))

    try:
        # Just take the whole request and stuff into JSON for passing down
        # the pipe.
        client.slumber.bango.event.post({"notification": notice, "password": password, "username": username})
    except HttpClientError, err:
        log.error("Error calling solitude: {0}".format(err), exc_info=True)
        # Sending something other than a 200, will cause Bango to re-send it.
        return HttpResponse(content="Not OK", status=502)
Example #3
0
def notification(request):
    """
    An end point for Bango to communicate with using the Event Notification
    API. This does the Basic Auth and then passes the whole thing on to do
    solitude.
    """
    log.info('Bango notification received')

    try:
        username, password = basic(request)
    except NoHeader:
        log.info('Header not present')
        return HttpResponseNotAuthenticated(request)
    except WrongHeader:
        log.info('Header given but invalid')
        return HttpResponseForbidden(request)

    content_type = request.META['CONTENT_TYPE']
    # This should help figure out why.
    log.info('Bango notification encoding={0.encoding} '
             'content_type={1} POST keys={1}'
             .format(request, content_type, request.POST.keys()))

    # As per bug 903567, the requests might come in with different
    # content types.
    if content_type == 'application/x-www-form-urlencoded':
        notice = request.POST['XML'].encode('utf8')
    elif content_type == 'text/xml':
        notice = request.body
    else:
        return HttpResponse(request, status=415)

    log.debug('Bango notice: {0}'.format(repr(notice)))

    try:
        # Just take the whole request and stuff into JSON for passing down
        # the pipe.
        client.slumber.bango.event.post({
            'notification': notice,
            'password': password,
            'username': username
        })
    except HttpClientError, err:
        log.error('Error calling solitude: {0}'.format(err), exc_info=True)
        # Sending something other than a 200, will cause Bango to re-send it.
        return HttpResponse(content='Not OK', status=502)
Example #4
0
def notification(request):
    """
    An end point for Bango to communicate with using the Event Notification
    API. This does the Basic Auth and then passes the whole thing on to do
    solitude.
    """
    log.info('Bango notification received')

    try:
        username, password = basic(request)
    except NoHeader:
        log.info('Header not present')
        return HttpResponseNotAuthenticated(request)
    except WrongHeader:
        log.info('Header given but invalid')
        return HttpResponseForbidden(request)

    content_type = request.META['CONTENT_TYPE']
    # This should help figure out why.
    log.info('Bango notification encoding={0.encoding} '
             'content_type={1} POST keys={1}'
             .format(request, content_type, request.POST.keys()))

    # As per bug 903567, the requests might come in with different
    # content types.
    if content_type == 'application/x-www-form-urlencoded':
        notice = request.POST['XML'].encode('utf8')
    elif content_type == 'text/xml':
        notice = request.body
    else:
        return HttpResponse(request, status=415)

    log.debug('Bango notice: {0}'.format(repr(notice)))

    try:
        # Just take the whole request and stuff into JSON for passing down
        # the pipe.
        client.slumber.bango.event.post({
            'notification': notice,
            'password': password,
            'username': username
        })
    except HttpClientError, err:
        log.error('Error calling solitude: {0}'.format(err), exc_info=True)
        # Sending something other than a 200, will cause Bango to re-send it.
        return HttpResponse(content='Not OK', status=502)
Example #5
0
 def test_no_split(self):
     encoded = base64.encodestring('user')
     basic(RequestFactory().get('/', **{self.key: encoded}))
Example #6
0
 def test_not_base64(self):
     basic(RequestFactory().get('/', **{self.key: 'basic something'}))
Example #7
0
 def test_malformed(self):
     basic(RequestFactory().get('/', **{self.key: ' '}))
Example #8
0
 def test_no_header(self):
     basic(RequestFactory().get('/'))