Beispiel #1
0
 def test_calls_all_dependencies(self):
     mac.generate_authorization_header_value(
         'METHOD', 'http://HOST:8008/PATH', 'KEY_ID', 'SECRET', 'CONTENT_TYPE', 'BODY')
     eq_(self.mock_time.call_args_list, [call()])
     eq_(self.mock_generate_nonce.call_args_list, [call()])
     eq_(self.mock_generate_ext.call_args_list, [
         call('CONTENT_TYPE', 'BODY')])
     eq_(self.mock_generate_signature.call_args_list, [
         call('SECRET', self.mock_build_normalized_request_string.return_value)])
Beispiel #2
0
 def test_calls_all_dependencies(self):
     mac.generate_authorization_header_value(
         'METHOD', 'http://HOST:8008/PATH', 'KEY_ID', 'SECRET', 'CONTENT_TYPE', 'BODY')
     eq_(self.mock_time.call_args_list, [call()])
     eq_(self.mock_generate_nonce.call_args_list, [call()])
     eq_(self.mock_generate_ext.call_args_list, [
         call('CONTENT_TYPE', 'BODY')])
     eq_(self.mock_generate_signature.call_args_list, [
         call('SECRET', self.mock_build_normalized_request_string.return_value)])
Beispiel #3
0
 def test_defaults_to_https_port_for_https_scheme(self):
     mac.generate_authorization_header_value('METHOD', 'https://HOST/PATH',
                                             'KEY_ID', 'SECRET',
                                             'CONTENT_TYPE', 'BODY')
     eq_([
         call(str(self.mock_time.return_value),
              self.mock_generate_nonce.return_value, 'METHOD', 'host',
              '443', '/PATH', self.mock_generate_ext.return_value)
     ], self.mock_build_normalized_request_string.call_args_list)
Beispiel #4
0
 def test_defaults_to_https_port_for_https_scheme(self):
     mac.generate_authorization_header_value(
         'METHOD', 'https://HOST/PATH', 'KEY_ID', 'SECRET', 'CONTENT_TYPE', 'BODY')
     eq_(
         [call(
             str(self.mock_time.return_value),
             self.mock_generate_nonce.return_value,
             'METHOD',
             'host',
             '443',
             '/PATH',
             self.mock_generate_ext.return_value
         )],
         self.mock_build_normalized_request_string.call_args_list
     )
Beispiel #5
0
 def test_returns_authorization_header_as_per_rfc(self):
     # http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-02#section-3.1
     retval = mac.generate_authorization_header_value(
         'METHOD', 'http://HOST:8008/PATH', 'KEY_ID', 'SECRET', 'CONTENT_TYPE',
         'BODY')
     eq_(
         retval, 'MAC id="KEY_ID", ts="42", nonce="NONCE", ext="EXT", mac="SIGNATURE"')
Beispiel #6
0
 def test_returns_authorization_header_as_per_rfc(self):
     # http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-02#section-3.1
     retval = mac.generate_authorization_header_value(
         'METHOD', 'http://HOST:8008/PATH', 'KEY_ID', 'SECRET', 'CONTENT_TYPE',
         'BODY')
     eq_(
         retval, 'MAC id="KEY_ID", ts="42", nonce="NONCE", ext="EXT", mac="SIGNATURE"')
    def __init__(self,
                 url,
                 method,
                 body,
                 mac_algorithm,
                 mac_key_identifier,
                 mac_key):

        headers = {
            "Accept": "application/json",
            "Accept-Encoding": "charset=utf8",
        }

        if body is not None:
            headers["Content-Type"] = "application/json"
            body = json.dumps(body)

        # :TRICKY: don't like the use of encode() below.
        # would have expected generate_authorization_header_value()
        # to deal with that more effectively
        headers["Authorization"] = generate_authorization_header_value(
            method,
            url,
            mac_key_identifier.encode('ascii', 'ignore'),
            mac_key.encode('ascii', 'ignore'),
            headers.get("Content-Type", None) if body else None,
            body)

        tornado.httpclient.HTTPRequest.__init__(
            self,
            url,
            method=method,
            headers=tornado.httputil.HTTPHeaders(headers),
            body=body)
Beispiel #8
0
 def __call__(self, request):
     request.headers['Authorization'] = generate_authorization_header_value(
         request.method,
         request.url,
         self.key_id,
         self.shared_secret,
         request.headers['Content-Type'],
         request.body
     )
     return request
Beispiel #9
0
 def __call__(self, request):
     request.headers['Authorization'] = generate_authorization_header_value(
         request.method, request.url, self.key_id, self.shared_secret,
         request.headers['Content-Type'], request.body)
     return request