Exemple #1
0
    def testSecurityCheckUnicode(self):
        user = "******"
        # TODO(hanuszczak): Test password with unicode characters as well. Currently
        # this will not work because `CryptedPassword` is broken and does not work
        # with unicode objects.
        password = "******"

        self._SetupUser(user, password)

        authorization = "{user}:{password}".format(user=user,
                                                   password=password)
        token = base64.b64encode(authorization.encode("utf-8")).decode("ascii")
        environ = werkzeug_test.EnvironBuilder(path="/foo",
                                               headers={
                                                   "Authorization":
                                                   "Basic %s" % token,
                                               }).get_environ()
        request = wsgiapp.HttpRequest(environ)

        def Handler(request, *args, **kwargs):
            del args, kwargs  # Unused.

            self.assertEqual(request.user, user)
            return http_response.HttpResponse(b"foobar", status=200)

        manager = webauth.BasicWebAuthManager()
        response = manager.SecurityCheck(Handler, request)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get_data(), b"foobar")
Exemple #2
0
    def testSecurityCheckUnicode(self):
        user = "******"
        # TODO(hanuszczak): Test password with unicode characters as well. Currently
        # this will not work because `CryptedPassword` is broken and does not work
        # with unicode objects.
        password = "******"

        with aff4.FACTORY.Open("aff4:/users/%s" % user,
                               aff4_type=aff4_users.GRRUser,
                               mode="w",
                               token=self.token) as fd:
            crypted_password = aff4_users.CryptedPassword()
            crypted_password.SetPassword(password.encode("utf-8"))
            fd.Set(fd.Schema.PASSWORD, crypted_password)

        token = base64.b64encode(("%s:%s" % (user, password)).encode("utf-8"))
        environ = werkzeug_test.EnvironBuilder(path="/foo",
                                               headers={
                                                   "Authorization":
                                                   "Basic %s" % token,
                                               }).get_environ()
        request = wsgiapp.HttpRequest(environ)

        def Handler(request, *args, **kwargs):
            del args, kwargs  # Unused.

            self.assertEqual(request.user, user)
            return werkzeug_wrappers.Response("foobar", status=200)

        manager = webauth.BasicWebAuthManager()
        response = manager.SecurityCheck(Handler, request)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get_data(), "foobar")