Exemplo n.º 1
0
 def __init__(self, headers, env, account, container):
     self.headers = headers
     self.status_int = FakeResponse_status_int
     self.environ = env
     cache_key, env_key = _get_cache_key(account, container)
     if container:
         info = headers_to_container_info(headers, FakeResponse_status_int)
     else:
         info = headers_to_account_info(headers, FakeResponse_status_int)
     env[env_key] = info
Exemplo n.º 2
0
 def __init__(self, headers, env, account, container):
     self.headers = headers
     self.status_int = FakeResponse_status_int
     self.environ = env
     cache_key, env_key = _get_cache_key(account, container)
     if container:
         info = headers_to_container_info(headers, FakeResponse_status_int)
     else:
         info = headers_to_account_info(headers, FakeResponse_status_int)
     env[env_key] = info
Exemplo n.º 3
0
 def test_valid_sig2(self):
     sig = self.sync.realms_conf.get_sig('GET', '/v1/a/c', '0', 'nonce',
                                         self.sync.realms_conf.key2('US'),
                                         'abc')
     req = swob.Request.blank(
         '/v1/a/c', headers={'x-container-sync-auth': 'US nonce ' + sig})
     req.environ[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'}
     resp = req.get_response(self.sync)
     self.assertEqual(resp.status, '200 OK')
     self.assertEqual(resp.body, 'Response to Authorized Request')
     self.assertTrue('cs:valid' in req.environ.get('swift.log_info'),
                     req.environ.get('swift.log_info'))
Exemplo n.º 4
0
 def test_invalid_sig(self):
     req = swob.Request.blank(
         '/v1/a/c', headers={'x-container-sync-auth': 'US nonce sig'})
     req.environ[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'}
     resp = req.get_response(self.sync)
     self.assertEqual(resp.status, '401 Unauthorized')
     self.assertEqual(
         resp.body,
         'X-Container-Sync-Auth header not valid; contact cluster operator '
         'for support.')
     self.assertTrue('cs:invalid-sig' in req.environ.get('swift.log_info'),
                     req.environ.get('swift.log_info'))
Exemplo n.º 5
0
 def test_valid_sig2(self):
     sig = self.sync.realms_conf.get_sig(
         'GET', '/v1/a/c', '0', 'nonce',
         self.sync.realms_conf.key2('US'), 'abc')
     req = swob.Request.blank(
         '/v1/a/c', headers={'x-container-sync-auth': 'US nonce ' + sig})
     req.environ[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'}
     resp = req.get_response(self.sync)
     self.assertEqual(resp.status, '200 OK')
     self.assertEqual(resp.body, 'Response to Authorized Request')
     self.assertTrue(
         'cs:valid' in req.environ.get('swift.log_info'),
         req.environ.get('swift.log_info'))
Exemplo n.º 6
0
 def test_invalid_sig(self):
     req = swob.Request.blank(
         '/v1/a/c', headers={'x-container-sync-auth': 'US nonce sig'})
     req.environ[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'}
     resp = req.get_response(self.sync)
     self.assertEqual(resp.status, '401 Unauthorized')
     self.assertEqual(
         resp.body,
         'X-Container-Sync-Auth header not valid; contact cluster operator '
         'for support.')
     self.assertTrue(
         'cs:invalid-sig' in req.environ.get('swift.log_info'),
         req.environ.get('swift.log_info'))
Exemplo n.º 7
0
 def __call__(self, env, start_response):
     if env['REQUEST_METHOD'] == "HEAD" and \
             env['PATH_INFO'] == '/v1/a/c2/o2':
         env_key = get_object_env_key('a', 'c2', 'o2')
         env[env_key] = headers_to_object_info(self.headers, 200)
         start_response('200 OK', self.headers)
     elif env['REQUEST_METHOD'] == "HEAD" and \
             env['PATH_INFO'] == '/v1/a/c2/o3':
         start_response('404 Not Found', [])
     else:
         # Cache the account_info (same as a real application)
         cache_key, env_key = _get_cache_key('a', None)
         env[env_key] = headers_to_account_info(self.headers, 200)
         start_response('200 OK', self.headers)
     return []
Exemplo n.º 8
0
 def test_valid_sig(self):
     ts = '1455221706.726999_0123456789abcdef'
     sig = self.sync.realms_conf.get_sig(
         'GET', '/v1/a/c', ts, 'nonce',
         self.sync.realms_conf.key('US'), 'abc')
     req = swob.Request.blank('/v1/a/c', headers={
         'x-container-sync-auth': 'US nonce ' + sig,
         'x-backend-inbound-x-timestamp': ts})
     req.environ[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'}
     resp = req.get_response(self.sync)
     self.assertEqual(resp.status, '200 OK')
     self.assertEqual(resp.body, 'Response to Authorized Request')
     self.assertIn('cs:valid', req.environ.get('swift.log_info'))
     self.assertIn('X-Timestamp', resp.headers)
     self.assertEqual(ts, resp.headers['X-Timestamp'])
Exemplo n.º 9
0
    def __init__(self, headers, env, account, container, obj):
        self.headers = headers
        self.status_int = FakeResponse_status_int
        self.environ = env
        if obj:
            env_key = get_object_env_key(account, container, obj)
        else:
            cache_key, env_key = _get_cache_key(account, container)

        if account and container and obj:
            info = headers_to_object_info(headers, FakeResponse_status_int)
        elif account and container:
            info = headers_to_container_info(headers, FakeResponse_status_int)
        else:
            info = headers_to_account_info(headers, FakeResponse_status_int)
        env[env_key] = info
Exemplo n.º 10
0
    def __init__(self, headers, env, account, container, obj):
        self.headers = headers
        self.status_int = FakeResponse_status_int
        self.environ = env
        if obj:
            env_key = get_object_env_key(account, container, obj)
        else:
            cache_key, env_key = _get_cache_key(account, container)

        if account and container and obj:
            info = headers_to_object_info(headers, FakeResponse_status_int)
        elif account and container:
            info = headers_to_container_info(headers, FakeResponse_status_int)
        else:
            info = headers_to_account_info(headers, FakeResponse_status_int)
        env[env_key] = info
Exemplo n.º 11
0
 def test_valid_sig(self):
     ts = '1455221706.726999_0123456789abcdef'
     sig = self.sync.realms_conf.get_sig('GET', '/v1/a/c', ts, 'nonce',
                                         self.sync.realms_conf.key('US'),
                                         'abc')
     req = swob.Request.blank('/v1/a/c',
                              headers={
                                  'x-container-sync-auth':
                                  'US nonce ' + sig,
                                  'x-backend-inbound-x-timestamp': ts
                              })
     req.environ[_get_cache_key('a', 'c')[1]] = {'sync_key': 'abc'}
     resp = req.get_response(self.sync)
     self.assertEqual(resp.status, '200 OK')
     self.assertEqual(resp.body, 'Response to Authorized Request')
     self.assertIn('cs:valid', req.environ.get('swift.log_info'))
     self.assertIn('X-Timestamp', resp.headers)
     self.assertEqual(ts, resp.headers['X-Timestamp'])
Exemplo n.º 12
0
 def __call__(self, env, start_response):
     if 'swift.authorize' in env:
         aresp = env['swift.authorize'](Request(env))
         if aresp:
             return aresp(env, start_response)
     if env['REQUEST_METHOD'] == "HEAD" and \
             env['PATH_INFO'] == '/v1/a/c2/o2':
         env_key = get_object_env_key('a', 'c2', 'o2')
         env.setdefault('swift.infocache', {})[env_key] = \
             headers_to_object_info(self.headers, 200)
         start_response('200 OK', self.headers)
     elif env['REQUEST_METHOD'] == "HEAD" and \
             env['PATH_INFO'] == '/v1/a/c2/o3':
         start_response('404 Not Found', [])
     else:
         # Cache the account_info (same as a real application)
         cache_key, env_key = _get_cache_key('a', None)
         env.setdefault('swift.infocache', {})[env_key] = \
             headers_to_account_info(self.headers, 200)
         start_response('200 OK', self.headers)
     return []
Exemplo n.º 13
0
 def __call__(self, env, start_response):
     # Cache the account_info (same as a real application)
     cache_key, env_key = _get_cache_key('a', None)
     env[env_key] = headers_to_account_info(self.headers, 200)
     start_response('200 OK', self.headers)
     return []
Exemplo n.º 14
0
 def __call__(self, env, start_response):
     # Cache the account_info (same as a real application)
     cache_key, env_key = _get_cache_key('a', None)
     env[env_key] = headers_to_account_info(self.headers, 200)
     start_response('200 OK', self.headers)
     return []