def _validate_signature(self, request, principal, args, params): """Validate the signature.""" creds = AWSCredentials(principal.access_key, principal.secret_key) endpoint = AWSServiceEndpoint() endpoint.set_method(request.method) endpoint.set_canonical_host(request.getHeader("Host")) path = request.path if self.path is not None: path = "%s/%s" % (self.path.rstrip("/"), path.lstrip("/")) endpoint.set_path(path) signature = Signature( creds, endpoint, params, signature_method=args["signature_method"], signature_version=args["signature_version"], ) if signature.compute() != args["signature"]: raise APIError( 403, "SignatureDoesNotMatch", "The request signature we calculated does not " "match the signature you provided. Check your " "key and signing method.", )
def test_set_canonical_host_with_empty_port(self): """ The canonical host can also have no port. """ endpoint = AWSServiceEndpoint() endpoint.set_canonical_host("my.service:") self.assertEquals("my.service", endpoint.host) self.assertIdentical(None, endpoint.port)
def test_set_canonical_host_with_port(self): """ The canonical host can optionally have a port. """ endpoint = AWSServiceEndpoint() endpoint.set_canonical_host("my.service:99") self.assertEquals("my.service", endpoint.host) self.assertEquals(99, endpoint.port)
def test_set_canonical_host(self): """ The canonical host is converted to lower case. """ endpoint = AWSServiceEndpoint() endpoint.set_canonical_host("My.Service") self.assertEquals("my.service", endpoint.host) self.assertIdentical(None, endpoint.port)
def _validate_signature(self, request, principal, args, params): """Validate the signature.""" creds = AWSCredentials(principal.access_key, principal.secret_key) endpoint = AWSServiceEndpoint() endpoint.set_method(request.method) endpoint.set_canonical_host(request.getHeader("Host")) path = request.path if self.path is not None: path = "%s/%s" % (self.path.rstrip("/"), path.lstrip("/")) endpoint.set_path(path) params.pop("Signature") signature = Signature(creds, endpoint, params) if signature.compute() != args.Signature: raise APIError(403, "SignatureDoesNotMatch", "The request signature we calculated does not " "match the signature you provided. Check your " "key and signing method.")