예제 #1
0
파일: test_base.py 프로젝트: oubiwann/txaws
    def test_submit(self):
        """
        C{submit} uses the given L{IAgent} to issue a request as described
        by the query's credentials and request details.
        """
        url_context = base.url_context(
            scheme=u"https",
            host=u"example.invalid",
            port=443,
            path=[],
        )
        content_sha256 = sha256(b"").hexdigest().decode("ascii")
        details = RequestDetails(
            region=REGION_US_EAST_1,
            service=b"iam",
            method=b"GET",
            url_context=url_context,
            content_sha256=content_sha256,
        )
        query = base.query(
            credentials=self.credentials,
            details=details,
        )

        self.assertNoResult(query.submit(self.agent, utcnow=self.utcnow))
        [(method, url, headers, _, _)] = self.agent._requests

        date = b"20090213T233130Z"
        host = b"example.invalid"

        authorization = query._sign(
            self.now,
            self.credentials,
            details.service,
            details.region,
            query._canonical_request(
                Headers({
                    b"host": [host],
                    b"x-amz-date": [date],
                }),
            )
        )

        self.assertEqual(details.method, method)
        self.assertEqual(b"https://example.invalid:443/", url)
        self.assertEqual(
            Headers({
                b"host": [host],
                b"x-amz-date": [date],
                b"x-amz-content-sha256": [content_sha256],
                b"authorization": [authorization],
            }), headers,
        )
예제 #2
0
파일: test_base.py 프로젝트: xzy3/txaws
    def test_submit(self):
        """
        C{submit} uses the given L{IAgent} to issue a request as described
        by the query's credentials and request details.
        """
        url_context = base.url_context(
            scheme=u"https",
            host=u"example.invalid",
            port=443,
            path=[],
        )
        content_sha256 = sha256(b"").hexdigest().decode("ascii")
        details = RequestDetails(
            region=REGION_US_EAST_1,
            service=b"iam",
            method=b"GET",
            url_context=url_context,
            content_sha256=content_sha256,
        )
        query = base.query(
            credentials=self.credentials,
            details=details,
        )

        self.assertNoResult(query.submit(self.agent, utcnow=self.utcnow))
        [(method, url, headers, _, _)] = self.agent._requests

        date = b"20090213T233130Z"
        host = b"example.invalid"

        authorization = query._sign(
            self.now, self.credentials, details.service, details.region,
            query._canonical_request(
                Headers({
                    b"host": [host],
                    b"x-amz-date": [date],
                }), ))

        self.assertEqual(details.method, method)
        self.assertEqual(b"https://example.invalid:443/", url)
        self.assertEqual(
            Headers({
                b"host": [host],
                b"x-amz-date": [date],
                b"x-amz-content-sha256": [content_sha256],
                b"authorization": [authorization],
            }),
            headers,
        )
예제 #3
0
파일: test_base.py 프로젝트: xzy3/txaws
 def test_construction(self):
     """
     L{url_context} constructs a L{_URLContext} with its parameters.
     """
     params = dict(
         scheme=u"https",
         host=u"example.invalid",
         port=80,
         path=[u"foo"],
         query=[(u"bar", u"baz")],
     )
     self.assertEqual(
         _URLContext(**params),
         url_context(**params),
     )
예제 #4
0
파일: test_base.py 프로젝트: oubiwann/txaws
 def test_construction(self):
     """
     L{url_context} constructs a L{_URLContext} with its parameters.
     """
     params = dict(
         scheme=u"https",
         host=u"example.invalid",
         port=80,
         path=[u"foo"],
         query=[(u"bar", u"baz")],
     )
     self.assertEqual(
         _URLContext(**params),
         url_context(**params),
     )
예제 #5
0
파일: test_base.py 프로젝트: xzy3/txaws
    def test_canonical_request(self):
        """
        L{_Query._canonical_request} is the canonical request which should
        be signed according to the AWS SigV4 rules.
        """
        url_context = base.url_context(
            scheme=u"https",
            host=u"example.invalid",
            port=443,
            path=[u"foo", u"bar"],
            query=[(u"baz", ), (u"quux", u"thud")],
        )
        content_sha256 = sha256(b"random whatever").hexdigest().decode("ascii")
        details = RequestDetails(
            region=REGION_US_EAST_1,
            service=b"iam",
            method=b"GET",
            url_context=url_context,
            content_sha256=content_sha256,
        )

        query = base.query(
            credentials=self.credentials,
            details=details,
        )
        self.assertEqual(
            attr.asdict(
                _CanonicalRequest(
                    method=b"GET",
                    canonical_uri=b"/foo/bar",
                    # Amazon docs don't make it clear that no-argument
                    # query parameters (like "baz" in this case) should be
                    # transformed into empty-value query parameters for
                    # the canonical request.  They should.
                    canonical_query_string=b"baz=&quux=thud",
                    canonical_headers=
                    b"host:example.invalid\nx-amz-date:20090213T233130Z\n",
                    signed_headers=b"host;x-amz-date",
                    payload_hash=content_sha256,
                )),
            attr.asdict(
                query._canonical_request(
                    Headers({
                        b"host": [b"example.invalid"],
                        u"x-amz-date": [b"20090213T233130Z"],
                    }))),
        )
예제 #6
0
파일: test_base.py 프로젝트: oubiwann/txaws
    def test_canonical_request(self):
        """
        L{_Query._canonical_request} is the canonical request which should
        be signed according to the AWS SigV4 rules.
        """
        url_context = base.url_context(
            scheme=u"https",
            host=u"example.invalid",
            port=443,
            path=[u"foo", u"bar"],
            query=[(u"baz",), (u"quux", u"thud")],
        )
        content_sha256 = sha256(b"random whatever").hexdigest().decode("ascii")
        details = RequestDetails(
            region=REGION_US_EAST_1,
            service=b"iam",
            method=b"GET",
            url_context=url_context,
            content_sha256=content_sha256,
        )

        query = base.query(
            credentials=self.credentials,
            details=details,
        )
        self.assertEqual(
            attr.asdict(_CanonicalRequest(
                method=b"GET",
                canonical_uri=b"/foo/bar",
                # Amazon docs don't make it clear that no-argument
                # query parameters (like "baz" in this case) should be
                # transformed into empty-value query parameters for
                # the canonical request.  They should.
                canonical_query_string=b"baz=&quux=thud",
                canonical_headers=b"host:example.invalid\nx-amz-date:20090213T233130Z\n",
                signed_headers=b"host;x-amz-date",
                payload_hash=content_sha256,
            )),
            attr.asdict(query._canonical_request(Headers({
                b"host": [b"example.invalid"],
                u"x-amz-date": [b"20090213T233130Z"],
            }))),
        )
예제 #7
0
파일: client.py 프로젝트: simpoir/txaws
 def _details(self, op):
     content_sha256 = sha256(op.body).hexdigest().decode("ascii")
     body_producer = FileBodyProducer(
         BytesIO(op.body), cooperator=self.cooperator,
     )
     return RequestDetails(
         region=self.region,
         service=op.service,
         method=op.method,
         url_context=url_context(
             scheme=self.endpoint.scheme.decode("ascii"),
             host=self.endpoint.host.decode("ascii"),
             port=self.endpoint.port,
             path=op.path,
             query=op.query,
         ),
         body_producer=body_producer,
         content_sha256=content_sha256,
     )