Example #1
0
 def test_normalized_http_path(self):
     request = auth.aws.Request.from_wsgi(self.environ, StartResponse())
     self.assertEquals(request.get_normalized_http_path(), '/')
     request.url = http.clone_url(request.url, path='')
     self.assertEquals(request.get_normalized_http_path(), '/')
     request.url = http.clone_url(request.url, path='/foo/bar/')
     self.assertEquals(request.get_normalized_http_path(), '/foo/bar/')
     request.url = http.clone_url(request.url, path='/foo/bar')
     self.assertEquals(request.get_normalized_http_path(), '/foo/bar')
Example #2
0
    def signed_request(self, request=None, signature_method=None, key=None, secret=None, timestamp=None):
        signature_method = signature_method if signature_method is not None else auth.aws.SignatureMethod_HMAC_SHA256()
        request = request if request is not None else auth.aws.Request.from_wsgi(self.environ, StartResponse())
        parameters = request.url.parameters.copy()
        parameters['AWSAccessKeyId'] = key if key else self.entity_key
        parameters['SignatureVersion'] = signature_method.version
        parameters['SignatureMethod'] = signature_method.name
        parameters['Timestamp'] = timestamp if timestamp is not None else auth.aws.generate_timestamp()
        prepared = request._clone(url=http.clone_url(request.url, parameters=parameters))

        parameters['Signature'] = signature_method.build_signature(prepared, secret if secret is not None else self.entity_secret)
        return request._clone(url=http.clone_url(prepared.url, parameters=parameters))
Example #3
0
 def test_authorized(self):
     request = self.signed_request()
     entity = self.authenticator.authenticate(request)
     authorized = self.authorizer.authorize(entity, request)
     request.url = http.clone_url(request.url, host=settings.remote_host)
     request.headers = [header if header[0] != 'host' else ('host', settings.remote_host) for header in request.headers]
     self.assertEquals(
         authorized.url.parameters['Signature'],
         self.signed_request(request, key=self.aws_key, secret=self.aws_secret, timestamp=authorized.url.parameters['Timestamp']).url.parameters['Signature']
     )