Example #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
Example #2
0
    def wrapper(*args, **kwargs):
        user, refreshed_token = validate(args[0])

        if user:
            args[0].user = user

            try:
                resp = controller_function(*args, **kwargs)

            except Exception as e:
                # LOGGER.error(e)
                resp = HttpResponseServerError("<h1>Server Error (500)</h1>")
                raise

            finally:
                if refreshed_token:
                    resp["Authorization"] = refreshed_token
                    resp.set_cookie(TOKEN_KEY_NAME, refreshed_token)

        return resp