Exemple #1
0
    def test_authenticate_postdata_204(self):
        self.setup_mock()
        self.uuid4_m()
        self.mocker.result("focaccia")
        self.mocker.replay()

        url = self.get_url("blur")
        auth = DigestAuthenticator("quesadilla", "king")

        def check(response):
            self.assertTrue(
                response.startswith(
                    'Digest username="******", realm="p", nonce="q", uri="%s"'
                    % url))
            self.assertIn('qop="auth", nc="00000001", cnonce="focaccia"',
                          response)

        self.add_auth("blur",
                      "HURL",
                      "",
                      "Digest realm=p, nonce=q, qop=auth",
                      check,
                      expect_content="bbq",
                      status=204)
        d = get_page_auth(url, auth, method="HURL", postdata="bbq")
        d.addCallback(self.assertEquals, "")
        return d
Exemple #2
0
    def test_authenticate_postdata_201(self):
        self.setup_mock()
        self.uuid4_m()
        self.mocker.result("ciabatta")
        self.mocker.replay()

        url = self.get_url("blam")
        auth = DigestAuthenticator("pizza", "principessa")

        def check(response):
            self.assertTrue(
                response.startswith(
                    'Digest username="******", realm="a", nonce="b", uri="%s"' %
                    url))
            self.assertIn('qop="auth", nc="00000001", cnonce="ciabatta"',
                          response)

        self.add_auth("blam",
                      "FLING",
                      "tomato",
                      "Digest realm=a, nonce=b, qop=auth",
                      check,
                      expect_content="oven",
                      status=201)
        d = get_page_auth(url, auth, method="FLING", postdata="oven")
        d.addCallback(self.assertEquals, "tomato")
        return d
Exemple #3
0
    def put(self, name, file_object):
        """Upload a file to WebDAV.

        :param unicode remote_path: path on which to store the content

        :param file_object: open file object containing the content

        :rtype: :class:`twisted.internet.defer.Deferred`
        """
        url = self.get_url(name)
        postdata = file_object.read()
        d = get_page_auth(url, self._auth, method="PUT", postdata=postdata)
        d.addCallback(lambda _: True)
        d.addErrback(_convert_error, "PUT", url, {401: ProviderError(
            "The supplied storage credentials were not accepted by the "
            "server")})
        return d
    def test_authenticate(self):
        self.setup_mock()
        self.uuid4_m()
        self.mocker.result("baguette")
        self.mocker.replay()

        url = self.get_url("blip")
        auth = DigestAuthenticator("sandwich", "earl")

        def check(response):
            self.assertTrue(response.startswith(
                'Digest username="******", realm="x", nonce="y", uri="%s"'
                % url))
            self.assertIn(
                'qop="auth", nc="00000001", cnonce="baguette"', response)

        self.add_auth(
            "blip", "PROD", "ham", "Digest realm=x, nonce=y, qop=auth", check)
        d = get_page_auth(url, auth, method="PROD")
        d.addCallback(self.assertEquals, "ham")
        return d
Exemple #5
0
    def put(self, name, file_object):
        """Upload a file to WebDAV.

        :param unicode remote_path: path on which to store the content

        :param file_object: open file object containing the content

        :rtype: :class:`twisted.internet.defer.Deferred`
        """
        url = self.get_url(name)
        postdata = file_object.read()
        d = get_page_auth(url, self._auth, method="PUT", postdata=postdata)
        d.addCallback(lambda _: True)
        d.addErrback(
            _convert_error, "PUT", url, {
                401:
                ProviderError(
                    "The supplied storage credentials were not accepted by the "
                    "server")
            })
        return d
    def test_authenticate_postdata_204(self):
        self.setup_mock()
        self.uuid4_m()
        self.mocker.result("focaccia")
        self.mocker.replay()

        url = self.get_url("blur")
        auth = DigestAuthenticator("quesadilla", "king")

        def check(response):
            self.assertTrue(response.startswith(
                'Digest username="******", realm="p", nonce="q", uri="%s"'
                % url))
            self.assertIn(
                'qop="auth", nc="00000001", cnonce="focaccia"', response)

        self.add_auth(
            "blur", "HURL", "", "Digest realm=p, nonce=q, qop=auth", check,
            expect_content="bbq", status=204)
        d = get_page_auth(url, auth, method="HURL", postdata="bbq")
        d.addCallback(self.assertEquals, "")
        return d
    def test_authenticate_postdata_201(self):
        self.setup_mock()
        self.uuid4_m()
        self.mocker.result("ciabatta")
        self.mocker.replay()

        url = self.get_url("blam")
        auth = DigestAuthenticator("pizza", "principessa")

        def check(response):
            self.assertTrue(response.startswith(
                'Digest username="******", realm="a", nonce="b", uri="%s"'
                % url))
            self.assertIn(
                'qop="auth", nc="00000001", cnonce="ciabatta"', response)

        self.add_auth(
            "blam", "FLING", "tomato", "Digest realm=a, nonce=b, qop=auth",
            check, expect_content="oven", status=201)
        d = get_page_auth(url, auth, method="FLING", postdata="oven")
        d.addCallback(self.assertEquals, "tomato")
        return d
Exemple #8
0
    def test_authenticate(self):
        self.setup_mock()
        self.uuid4_m()
        self.mocker.result("baguette")
        self.mocker.replay()

        url = self.get_url("blip")
        auth = DigestAuthenticator("sandwich", "earl")

        def check(response):
            self.assertTrue(
                response.startswith(
                    'Digest username="******", realm="x", nonce="y", uri="%s"'
                    % url))
            self.assertIn('qop="auth", nc="00000001", cnonce="baguette"',
                          response)

        self.add_auth("blip", "PROD", "ham",
                      "Digest realm=x, nonce=y, qop=auth", check)
        d = get_page_auth(url, auth, method="PROD")
        d.addCallback(self.assertEquals, "ham")
        return d
 def test_other_method(self):
     self.add_plain("blob", "TWIDDLE", "pickle")
     d = get_page_auth(self.get_url("blob"), None, method="TWIDDLE")
     d.addCallback(self.assertEquals, "pickle")
     return d
 def test_default_method(self):
     self.add_plain("blah", "GET", "cheese")
     d = get_page_auth(self.get_url("blah"), None)
     d.addCallback(self.assertEquals, "cheese")
     return d
 def test_404(self):
     # verify that usual mechanism is in place
     d = get_page_auth(self.get_url("missing"), None)
     error = yield self.assertFailure(d, Error)
     self.assertEquals(error.status, "404")
Exemple #12
0
 def test_other_method(self):
     self.add_plain("blob", "TWIDDLE", "pickle")
     d = get_page_auth(self.get_url("blob"), None, method="TWIDDLE")
     d.addCallback(self.assertEquals, "pickle")
     return d
Exemple #13
0
 def test_default_method(self):
     self.add_plain("blah", "GET", "cheese")
     d = get_page_auth(self.get_url("blah"), None)
     d.addCallback(self.assertEquals, "cheese")
     return d
Exemple #14
0
 def test_404(self):
     # verify that usual mechanism is in place
     d = get_page_auth(self.get_url("missing"), None)
     error = yield self.assertFailure(d, Error)
     self.assertEquals(error.status, "404")