Esempio n. 1
0
def django_tests():
    from django.http import HttpResponse
    from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect, HttpResponseBadRequest, HttpResponseNotModified, HttpResponseNotFound, HttpResponseForbidden, HttpResponseNotAllowed, HttpResponseGone, HttpResponseServerError

    response = HttpResponse()
    response.set_cookie("C1", "world")  # Noncompliant
    response.set_cookie("C2", "world", secure=None)  # Noncompliant
    response.set_cookie("C3", "world", secure=False)  # Noncompliant
    response.set_cookie("C4", "world", secure=True)

    response2 = HttpResponseRedirect()
    response2.set_cookie("C5", "world")  # Noncompliant
    response2.set_cookie("C5", "world", None, None, "/", None, True)  # OK
    response2.set_signed_cookie("C5", "world")  # Noncompliant
    response2.set_signed_cookie("C5", "world", secure=True)  # OK
    response2.set_signed_cookie("C5", "world", other=False, secure=True)  # OK
    response2.set_signed_cookie("C5", "world", secure=False)  # Noncompliant
    response2.set_signed_cookie("C5", "world", secure=None)  # Noncompliant
    response2.set_signed_cookie("C5", "", "world", None, None, "/", None,
                                True)  # OK
    kwargs = {secure: True}
    response2.set_signed_cookie("C5", "world", **kwargs)  # OK

    kwargs = {secure: False}
    response2.set_signed_cookie("C5", "world", **kwargs)  # FN

    get_cookie().set_cookie("C3", "world", secure=False)

    response3 = HttpResponsePermanentRedirect()
    response3.set_cookie("C6", "world")  # Noncompliant
    response4 = HttpResponseNotModified()
    response4.set_cookie("C7", "world")  # Noncompliant
    response5 = HttpResponseBadRequest()
    response5.set_cookie("C8", "world")  # Noncompliant
    response6 = HttpResponseNotFound()
    response6.set_cookie("C9", "world")  # Noncompliant
    response7 = HttpResponseForbidden()
    response7.set_cookie("C10", "world")  # Noncompliant
    response8 = HttpResponseNotAllowed()
    response8.set_cookie("C11", "world")  # Noncompliant
    response9 = HttpResponseGone()
    response9.set_cookie("C12", "world")  # Noncompliant
    response10 = HttpResponseServerError()
    response10.set_cookie("C13", "world")  # Noncompliant
Esempio n. 2
0
def download_protected_result(request):
    """
    View function that search for the result file and download it to the user

    return: HttpResponse object with the X-Accel-Redirect header containing the path to the file to be downloaded
    """
    result_id = request.GET.get('resultid')
    result = Result.objects.get(id=result_id)
    response = HttpResponseForbidden()
    if result.crawler.user == request.user:
        if result.error:
            response = HttpResponseServerError(result.error_message)
        elif not result.data:
            response = HttpResponse('loading')
        else:
            filename = os.path.basename(result.data.name)
            response = HttpResponse()
            response[
                "Content-Disposition"] = "attachment; filename={0}".format(
                    filename)
            response['X-Accel-Redirect'] = "/crawlers-results/{0}".format(
                filename)
            response.set_cookie('fileDownload', 'true')
    return response