Pep8 unit tests in middleware > 20 violations (7 of 12)
Change-Id: I9dfae1a473a8212ef25dcc01e338d8bdade7ef4e Signed-off-by: Peter Portante <peter.portante@redhat.com>
This commit is contained in:
parent
56593a1323
commit
0ebddd87d1
test/unit/common/middleware
@ -202,7 +202,7 @@ class TestReconSuccess(TestCase):
|
||||
oart = OpenAndReadTester(['{"notneeded": 5, "testkey1": "canhazio"}'])
|
||||
self.app._from_recon_cache = self.real_from_cache
|
||||
rv = self.app._from_recon_cache(['testkey1', 'notpresentkey'],
|
||||
'test.cache', openr=oart.open)
|
||||
'test.cache', openr=oart.open)
|
||||
self.assertEquals(oart.read_calls, [((), {})])
|
||||
self.assertEquals(oart.open_calls, [(('test.cache', 'r'), {})])
|
||||
self.assertEquals(rv, {'notpresentkey': None, 'testkey1': 'canhazio'})
|
||||
@ -212,7 +212,7 @@ class TestReconSuccess(TestCase):
|
||||
oart = self.frecon.raise_IOError
|
||||
self.app._from_recon_cache = self.real_from_cache
|
||||
rv = self.app._from_recon_cache(['testkey1', 'notpresentkey'],
|
||||
'test.cache', openr=oart)
|
||||
'test.cache', openr=oart)
|
||||
self.assertEquals(rv, {'notpresentkey': None, 'testkey1': None})
|
||||
self.app._from_recon_cache = self.fakecache.fake_from_recon_cache
|
||||
|
||||
@ -220,7 +220,7 @@ class TestReconSuccess(TestCase):
|
||||
oart = self.frecon.raise_ValueError
|
||||
self.app._from_recon_cache = self.real_from_cache
|
||||
rv = self.app._from_recon_cache(['testkey1', 'notpresentkey'],
|
||||
'test.cache', openr=oart)
|
||||
'test.cache', openr=oart)
|
||||
self.assertEquals(rv, {'notpresentkey': None, 'testkey1': None})
|
||||
self.app._from_recon_cache = self.fakecache.fake_from_recon_cache
|
||||
|
||||
@ -228,46 +228,53 @@ class TestReconSuccess(TestCase):
|
||||
oart = self.frecon.raise_Exception
|
||||
self.app._from_recon_cache = self.real_from_cache
|
||||
rv = self.app._from_recon_cache(['testkey1', 'notpresentkey'],
|
||||
'test.cache', openr=oart)
|
||||
'test.cache', openr=oart)
|
||||
self.assertEquals(rv, {'notpresentkey': None, 'testkey1': None})
|
||||
self.app._from_recon_cache = self.fakecache.fake_from_recon_cache
|
||||
|
||||
def test_get_mounted(self):
|
||||
mounts_content = ['rootfs / rootfs rw 0 0',
|
||||
'none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0',
|
||||
'none /proc proc rw,nosuid,nodev,noexec,relatime 0 0',
|
||||
'none /dev devtmpfs rw,relatime,size=248404k,nr_inodes=62101,mode=755 0 0',
|
||||
'none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0',
|
||||
'/dev/disk/by-uuid/e5b143bd-9f31-49a7-b018-5e037dc59252 / ext4 rw,relatime,errors=remount-ro,barrier=1,data=ordered 0 0',
|
||||
'none /sys/fs/fuse/connections fusectl rw,relatime 0 0',
|
||||
'none /sys/kernel/debug debugfs rw,relatime 0 0',
|
||||
'none /sys/kernel/security securityfs rw,relatime 0 0',
|
||||
'none /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0',
|
||||
'none /var/run tmpfs rw,nosuid,relatime,mode=755 0 0',
|
||||
'none /var/lock tmpfs rw,nosuid,nodev,noexec,relatime 0 0',
|
||||
'none /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0',
|
||||
'/dev/loop0 /mnt/sdb1 xfs rw,noatime,nodiratime,attr2,nobarrier,logbufs=8,noquota 0 0',
|
||||
'rpc_pipefs /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0',
|
||||
'nfsd /proc/fs/nfsd nfsd rw,relatime 0 0',
|
||||
'none /proc/fs/vmblock/mountPoint vmblock rw,relatime 0 0',
|
||||
'']
|
||||
mounted_resp = [{'device': 'rootfs', 'path': '/'},
|
||||
{'device': 'none', 'path': '/sys'},
|
||||
{'device': 'none', 'path': '/proc'},
|
||||
{'device': 'none', 'path': '/dev'},
|
||||
{'device': 'none', 'path': '/dev/pts'},
|
||||
{'device': '/dev/disk/by-uuid/e5b143bd-9f31-49a7-b018-5e037dc59252', 'path': '/'},
|
||||
{'device': 'none', 'path': '/sys/fs/fuse/connections'},
|
||||
{'device': 'none', 'path': '/sys/kernel/debug'},
|
||||
{'device': 'none', 'path': '/sys/kernel/security'},
|
||||
{'device': 'none', 'path': '/dev/shm'},
|
||||
{'device': 'none', 'path': '/var/run'},
|
||||
{'device': 'none', 'path': '/var/lock'},
|
||||
{'device': 'none', 'path': '/lib/init/rw'},
|
||||
{'device': '/dev/loop0', 'path': '/mnt/sdb1'},
|
||||
{'device': 'rpc_pipefs', 'path': '/var/lib/nfs/rpc_pipefs'},
|
||||
{'device': 'nfsd', 'path': '/proc/fs/nfsd'},
|
||||
{'device': 'none', 'path': '/proc/fs/vmblock/mountPoint'}]
|
||||
mounts_content = [
|
||||
'rootfs / rootfs rw 0 0',
|
||||
'none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0',
|
||||
'none /proc proc rw,nosuid,nodev,noexec,relatime 0 0',
|
||||
'none /dev devtmpfs rw,relatime,size=248404k,nr_inodes=62101,'
|
||||
'mode=755 0 0',
|
||||
'none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,'
|
||||
'ptmxmode=000 0 0',
|
||||
'/dev/disk/by-uuid/e5b143bd-9f31-49a7-b018-5e037dc59252 / ext4'
|
||||
' rw,relatime,errors=remount-ro,barrier=1,data=ordered 0 0',
|
||||
'none /sys/fs/fuse/connections fusectl rw,relatime 0 0',
|
||||
'none /sys/kernel/debug debugfs rw,relatime 0 0',
|
||||
'none /sys/kernel/security securityfs rw,relatime 0 0',
|
||||
'none /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0',
|
||||
'none /var/run tmpfs rw,nosuid,relatime,mode=755 0 0',
|
||||
'none /var/lock tmpfs rw,nosuid,nodev,noexec,relatime 0 0',
|
||||
'none /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0',
|
||||
'/dev/loop0 /mnt/sdb1 xfs rw,noatime,nodiratime,attr2,nobarrier,'
|
||||
'logbufs=8,noquota 0 0',
|
||||
'rpc_pipefs /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0',
|
||||
'nfsd /proc/fs/nfsd nfsd rw,relatime 0 0',
|
||||
'none /proc/fs/vmblock/mountPoint vmblock rw,relatime 0 0',
|
||||
'']
|
||||
mounted_resp = [
|
||||
{'device': 'rootfs', 'path': '/'},
|
||||
{'device': 'none', 'path': '/sys'},
|
||||
{'device': 'none', 'path': '/proc'},
|
||||
{'device': 'none', 'path': '/dev'},
|
||||
{'device': 'none', 'path': '/dev/pts'},
|
||||
{'device': '/dev/disk/by-uuid/'
|
||||
'e5b143bd-9f31-49a7-b018-5e037dc59252', 'path': '/'},
|
||||
{'device': 'none', 'path': '/sys/fs/fuse/connections'},
|
||||
{'device': 'none', 'path': '/sys/kernel/debug'},
|
||||
{'device': 'none', 'path': '/sys/kernel/security'},
|
||||
{'device': 'none', 'path': '/dev/shm'},
|
||||
{'device': 'none', 'path': '/var/run'},
|
||||
{'device': 'none', 'path': '/var/lock'},
|
||||
{'device': 'none', 'path': '/lib/init/rw'},
|
||||
{'device': '/dev/loop0', 'path': '/mnt/sdb1'},
|
||||
{'device': 'rpc_pipefs', 'path': '/var/lib/nfs/rpc_pipefs'},
|
||||
{'device': 'nfsd', 'path': '/proc/fs/nfsd'},
|
||||
{'device': 'none', 'path': '/proc/fs/vmblock/mountPoint'}]
|
||||
oart = OpenAndReadTester(mounts_content)
|
||||
rv = self.app.get_mounted(openr=oart.open)
|
||||
self.assertEquals(oart.open_calls, [(('/proc/mounts', 'r'), {})])
|
||||
@ -378,61 +385,65 @@ class TestReconSuccess(TestCase):
|
||||
self.assertEquals(rv, {'async_pending': 5})
|
||||
|
||||
def test_get_replication_info_account(self):
|
||||
from_cache_response = {"replication_stats": {
|
||||
"attempted": 1, "diff": 0,
|
||||
"diff_capped": 0, "empty": 0,
|
||||
"failure": 0, "hashmatch": 0,
|
||||
"no_change": 2, "remote_merge": 0,
|
||||
"remove": 0, "rsync": 0,
|
||||
"start": 1333044050.855202,
|
||||
"success": 2, "ts_repl": 0},
|
||||
"replication_time": 0.2615511417388916,
|
||||
"replication_last": 1357969645.25}
|
||||
from_cache_response = {
|
||||
"replication_stats": {
|
||||
"attempted": 1, "diff": 0,
|
||||
"diff_capped": 0, "empty": 0,
|
||||
"failure": 0, "hashmatch": 0,
|
||||
"no_change": 2, "remote_merge": 0,
|
||||
"remove": 0, "rsync": 0,
|
||||
"start": 1333044050.855202,
|
||||
"success": 2, "ts_repl": 0},
|
||||
"replication_time": 0.2615511417388916,
|
||||
"replication_last": 1357969645.25}
|
||||
self.fakecache.fakeout = from_cache_response
|
||||
rv = self.app.get_replication_info('account')
|
||||
self.assertEquals(self.fakecache.fakeout_calls,
|
||||
[((['replication_time', 'replication_stats',
|
||||
'replication_last'],
|
||||
'/var/cache/swift/account.recon'), {})])
|
||||
self.assertEquals(rv, {"replication_stats": {
|
||||
"attempted": 1, "diff": 0,
|
||||
"diff_capped": 0, "empty": 0,
|
||||
"failure": 0, "hashmatch": 0,
|
||||
"no_change": 2, "remote_merge": 0,
|
||||
"remove": 0, "rsync": 0,
|
||||
"start": 1333044050.855202,
|
||||
"success": 2, "ts_repl": 0},
|
||||
"replication_time": 0.2615511417388916,
|
||||
"replication_last": 1357969645.25})
|
||||
[((['replication_time', 'replication_stats',
|
||||
'replication_last'],
|
||||
'/var/cache/swift/account.recon'), {})])
|
||||
self.assertEquals(rv, {
|
||||
"replication_stats": {
|
||||
"attempted": 1, "diff": 0,
|
||||
"diff_capped": 0, "empty": 0,
|
||||
"failure": 0, "hashmatch": 0,
|
||||
"no_change": 2, "remote_merge": 0,
|
||||
"remove": 0, "rsync": 0,
|
||||
"start": 1333044050.855202,
|
||||
"success": 2, "ts_repl": 0},
|
||||
"replication_time": 0.2615511417388916,
|
||||
"replication_last": 1357969645.25})
|
||||
|
||||
def test_get_replication_info_container(self):
|
||||
from_cache_response = {"replication_time": 200.0,
|
||||
"replication_stats": {
|
||||
"attempted": 179, "diff": 0,
|
||||
"diff_capped": 0, "empty": 0,
|
||||
"failure": 0, "hashmatch": 0,
|
||||
"no_change": 358, "remote_merge": 0,
|
||||
"remove": 0, "rsync": 0,
|
||||
"start": 5.5, "success": 358,
|
||||
"ts_repl": 0},
|
||||
"replication_last": 1357969645.25}
|
||||
from_cache_response = {
|
||||
"replication_time": 200.0,
|
||||
"replication_stats": {
|
||||
"attempted": 179, "diff": 0,
|
||||
"diff_capped": 0, "empty": 0,
|
||||
"failure": 0, "hashmatch": 0,
|
||||
"no_change": 358, "remote_merge": 0,
|
||||
"remove": 0, "rsync": 0,
|
||||
"start": 5.5, "success": 358,
|
||||
"ts_repl": 0},
|
||||
"replication_last": 1357969645.25}
|
||||
self.fakecache.fakeout_calls = []
|
||||
self.fakecache.fakeout = from_cache_response
|
||||
rv = self.app.get_replication_info('container')
|
||||
self.assertEquals(self.fakecache.fakeout_calls,
|
||||
[((['replication_time', 'replication_stats',
|
||||
'replication_last'],
|
||||
'/var/cache/swift/container.recon'), {})])
|
||||
self.assertEquals(rv, {"replication_time": 200.0,
|
||||
"replication_stats": {
|
||||
"attempted": 179, "diff": 0,
|
||||
"diff_capped": 0, "empty": 0,
|
||||
"failure": 0, "hashmatch": 0,
|
||||
"no_change": 358, "remote_merge": 0,
|
||||
"remove": 0, "rsync": 0,
|
||||
"start": 5.5, "success": 358,
|
||||
"ts_repl": 0},
|
||||
"replication_last": 1357969645.25})
|
||||
[((['replication_time', 'replication_stats',
|
||||
'replication_last'],
|
||||
'/var/cache/swift/container.recon'), {})])
|
||||
self.assertEquals(rv, {
|
||||
"replication_time": 200.0,
|
||||
"replication_stats": {
|
||||
"attempted": 179, "diff": 0,
|
||||
"diff_capped": 0, "empty": 0,
|
||||
"failure": 0, "hashmatch": 0,
|
||||
"no_change": 358, "remote_merge": 0,
|
||||
"remove": 0, "rsync": 0,
|
||||
"start": 5.5, "success": 358,
|
||||
"ts_repl": 0},
|
||||
"replication_last": 1357969645.25})
|
||||
|
||||
def test_get_replication_object(self):
|
||||
from_cache_response = {"object_replication_time": 200.0,
|
||||
@ -441,9 +452,9 @@ class TestReconSuccess(TestCase):
|
||||
self.fakecache.fakeout = from_cache_response
|
||||
rv = self.app.get_replication_info('object')
|
||||
self.assertEquals(self.fakecache.fakeout_calls,
|
||||
[((['object_replication_time',
|
||||
'object_replication_last'],
|
||||
'/var/cache/swift/object.recon'), {})])
|
||||
[((['object_replication_time',
|
||||
'object_replication_last'],
|
||||
'/var/cache/swift/object.recon'), {})])
|
||||
self.assertEquals(rv, {'object_replication_time': 200.0,
|
||||
'object_replication_last': 1357962809.15})
|
||||
|
||||
@ -453,8 +464,8 @@ class TestReconSuccess(TestCase):
|
||||
self.fakecache.fakeout = from_cache_response
|
||||
rv = self.app.get_updater_info('container')
|
||||
self.assertEquals(self.fakecache.fakeout_calls,
|
||||
[((['container_updater_sweep'],
|
||||
'/var/cache/swift/container.recon'), {})])
|
||||
[((['container_updater_sweep'],
|
||||
'/var/cache/swift/container.recon'), {})])
|
||||
self.assertEquals(rv, {"container_updater_sweep": 18.476239919662476})
|
||||
|
||||
def test_get_updater_info_object(self):
|
||||
@ -463,8 +474,8 @@ class TestReconSuccess(TestCase):
|
||||
self.fakecache.fakeout = from_cache_response
|
||||
rv = self.app.get_updater_info('object')
|
||||
self.assertEquals(self.fakecache.fakeout_calls,
|
||||
[((['object_updater_sweep'],
|
||||
'/var/cache/swift/object.recon'), {})])
|
||||
[((['object_updater_sweep'],
|
||||
'/var/cache/swift/object.recon'), {})])
|
||||
self.assertEquals(rv, {"object_updater_sweep": 0.79848217964172363})
|
||||
|
||||
def test_get_auditor_info_account(self):
|
||||
@ -476,11 +487,11 @@ class TestReconSuccess(TestCase):
|
||||
self.fakecache.fakeout = from_cache_response
|
||||
rv = self.app.get_auditor_info('account')
|
||||
self.assertEquals(self.fakecache.fakeout_calls,
|
||||
[((['account_audits_passed',
|
||||
'account_auditor_pass_completed',
|
||||
'account_audits_since',
|
||||
'account_audits_failed'],
|
||||
'/var/cache/swift/account.recon'), {})])
|
||||
[((['account_audits_passed',
|
||||
'account_auditor_pass_completed',
|
||||
'account_audits_since',
|
||||
'account_audits_failed'],
|
||||
'/var/cache/swift/account.recon'), {})])
|
||||
self.assertEquals(rv, {"account_auditor_pass_completed": 0.24,
|
||||
"account_audits_failed": 0,
|
||||
"account_audits_passed": 6,
|
||||
@ -495,52 +506,54 @@ class TestReconSuccess(TestCase):
|
||||
self.fakecache.fakeout = from_cache_response
|
||||
rv = self.app.get_auditor_info('container')
|
||||
self.assertEquals(self.fakecache.fakeout_calls,
|
||||
[((['container_audits_passed',
|
||||
'container_auditor_pass_completed',
|
||||
'container_audits_since',
|
||||
'container_audits_failed'],
|
||||
'/var/cache/swift/container.recon'), {})])
|
||||
[((['container_audits_passed',
|
||||
'container_auditor_pass_completed',
|
||||
'container_audits_since',
|
||||
'container_audits_failed'],
|
||||
'/var/cache/swift/container.recon'), {})])
|
||||
self.assertEquals(rv, {"container_auditor_pass_completed": 0.24,
|
||||
"container_audits_failed": 0,
|
||||
"container_audits_passed": 6,
|
||||
"container_audits_since": "1333145374.1373529"})
|
||||
|
||||
def test_get_auditor_info_object(self):
|
||||
from_cache_response = {"object_auditor_stats_ALL": {
|
||||
"audit_time": 115.14418768882751,
|
||||
"bytes_processed": 234660,
|
||||
"completed": 115.4512460231781,
|
||||
"errors": 0,
|
||||
"files_processed": 2310,
|
||||
"quarantined": 0},
|
||||
"object_auditor_stats_ZBF": {
|
||||
"audit_time": 45.877294063568115,
|
||||
"bytes_processed": 0,
|
||||
"completed": 46.181446075439453,
|
||||
"errors": 0,
|
||||
"files_processed": 2310,
|
||||
"quarantined": 0}}
|
||||
from_cache_response = {
|
||||
"object_auditor_stats_ALL": {
|
||||
"audit_time": 115.14418768882751,
|
||||
"bytes_processed": 234660,
|
||||
"completed": 115.4512460231781,
|
||||
"errors": 0,
|
||||
"files_processed": 2310,
|
||||
"quarantined": 0},
|
||||
"object_auditor_stats_ZBF": {
|
||||
"audit_time": 45.877294063568115,
|
||||
"bytes_processed": 0,
|
||||
"completed": 46.181446075439453,
|
||||
"errors": 0,
|
||||
"files_processed": 2310,
|
||||
"quarantined": 0}}
|
||||
self.fakecache.fakeout_calls = []
|
||||
self.fakecache.fakeout = from_cache_response
|
||||
rv = self.app.get_auditor_info('object')
|
||||
self.assertEquals(self.fakecache.fakeout_calls,
|
||||
[((['object_auditor_stats_ALL',
|
||||
'object_auditor_stats_ZBF'],
|
||||
'/var/cache/swift/object.recon'), {})])
|
||||
self.assertEquals(rv, {"object_auditor_stats_ALL": {
|
||||
"audit_time": 115.14418768882751,
|
||||
"bytes_processed": 234660,
|
||||
"completed": 115.4512460231781,
|
||||
"errors": 0,
|
||||
"files_processed": 2310,
|
||||
"quarantined": 0},
|
||||
"object_auditor_stats_ZBF": {
|
||||
"audit_time": 45.877294063568115,
|
||||
"bytes_processed": 0,
|
||||
"completed": 46.181446075439453,
|
||||
"errors": 0,
|
||||
"files_processed": 2310,
|
||||
"quarantined": 0}})
|
||||
[((['object_auditor_stats_ALL',
|
||||
'object_auditor_stats_ZBF'],
|
||||
'/var/cache/swift/object.recon'), {})])
|
||||
self.assertEquals(rv, {
|
||||
"object_auditor_stats_ALL": {
|
||||
"audit_time": 115.14418768882751,
|
||||
"bytes_processed": 234660,
|
||||
"completed": 115.4512460231781,
|
||||
"errors": 0,
|
||||
"files_processed": 2310,
|
||||
"quarantined": 0},
|
||||
"object_auditor_stats_ZBF": {
|
||||
"audit_time": 45.877294063568115,
|
||||
"bytes_processed": 0,
|
||||
"completed": 46.181446075439453,
|
||||
"errors": 0,
|
||||
"files_processed": 2310,
|
||||
"quarantined": 0}})
|
||||
|
||||
def test_get_unmounted(self):
|
||||
|
||||
@ -579,7 +592,7 @@ class TestReconSuccess(TestCase):
|
||||
self.mockos.ismount_output = True
|
||||
rv = self.app.get_diskusage()
|
||||
self.assertEquals(self.mockos.statvfs_calls,
|
||||
[(('/srv/node/canhazdrive1',), {})])
|
||||
[(('/srv/node/canhazdrive1',), {})])
|
||||
self.assertEquals(rv, du_resp)
|
||||
|
||||
def test_get_diskusage_checkmount_fail(self):
|
||||
@ -590,7 +603,7 @@ class TestReconSuccess(TestCase):
|
||||
rv = self.app.get_diskusage()
|
||||
self.assertEquals(self.mockos.listdir_calls, [(('/srv/node/',), {})])
|
||||
self.assertEquals(self.mockos.ismount_calls,
|
||||
[(('/srv/node/canhazdrive1',), {})])
|
||||
[(('/srv/node/canhazdrive1',), {})])
|
||||
self.assertEquals(rv, du_resp)
|
||||
|
||||
def test_get_quarantine_count(self):
|
||||
@ -619,8 +632,9 @@ class TestReconSuccess(TestCase):
|
||||
'']
|
||||
oart = OpenAndReadTester(sockstat_content)
|
||||
self.app.get_socket_info(openr=oart.open)
|
||||
self.assertEquals(oart.open_calls, [(('/proc/net/sockstat', 'r'), {}),
|
||||
(('/proc/net/sockstat6', 'r'), {})])
|
||||
self.assertEquals(oart.open_calls, [
|
||||
(('/proc/net/sockstat', 'r'), {}),
|
||||
(('/proc/net/sockstat6', 'r'), {})])
|
||||
|
||||
|
||||
class TestReconMiddleware(unittest.TestCase):
|
||||
@ -651,7 +665,8 @@ class TestReconMiddleware(unittest.TestCase):
|
||||
self.assertEquals(resp, get_mem_resp)
|
||||
|
||||
def test_recon_get_version(self):
|
||||
req = Request.blank('/recon/version', environ={'REQUEST_METHOD': 'GET'})
|
||||
req = Request.blank('/recon/version',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.app(req.environ, start_response)
|
||||
self.assertEquals(resp, [json.dumps({'version': swiftver})])
|
||||
|
||||
|
@ -144,7 +144,8 @@ class FakeApp(object):
|
||||
self.get_c4_called = True
|
||||
return self.listing(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c4/one.txt':
|
||||
return Response(status='200 Ok',
|
||||
return Response(
|
||||
status='200 Ok',
|
||||
headers={'x-object-meta-test': 'value'},
|
||||
body='1')(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c4/two.txt':
|
||||
@ -204,8 +205,9 @@ class FakeApp(object):
|
||||
elif env['PATH_INFO'] in ('/v1/a/c11', '/v1/a/c11/'):
|
||||
return self.listing(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11/subdir/':
|
||||
return Response(status='200 Ok', headers={'Content-Type':\
|
||||
'application/directory'})(env, start_response)
|
||||
return Response(status='200 Ok', headers={
|
||||
'Content-Type': 'application/directory'})(
|
||||
env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11/subdir/index.html':
|
||||
return Response(status='200 Ok', body='''
|
||||
<html>
|
||||
@ -215,24 +217,24 @@ class FakeApp(object):
|
||||
</html>
|
||||
'''.strip())(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11/subdir2/':
|
||||
return Response(status='200 Ok', headers={'Content-Type':\
|
||||
return Response(status='200 Ok', headers={'Content-Type':
|
||||
'application/directory'})(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11/subdir2/index.html':
|
||||
return Response(status='404 Not Found')(env, start_response)
|
||||
elif env['PATH_INFO'] in ('/v1/a/c11a', '/v1/a/c11a/'):
|
||||
return self.listing(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11a/subdir/':
|
||||
return Response(status='200 Ok', headers={'Content-Type':\
|
||||
return Response(status='200 Ok', headers={'Content-Type':
|
||||
'text/directory'})(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11a/subdir/index.html':
|
||||
return Response(status='404 Not Found')(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11a/subdir2/':
|
||||
return Response(status='200 Ok', headers={'Content-Type':\
|
||||
return Response(status='200 Ok', headers={'Content-Type':
|
||||
'application/directory'})(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11a/subdir2/index.html':
|
||||
return Response(status='404 Not Found')(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11a/subdir3/':
|
||||
return Response(status='200 Ok', headers={'Content-Type':\
|
||||
return Response(status='200 Ok', headers={'Content-Type':
|
||||
'not_a/directory'})(env, start_response)
|
||||
elif env['PATH_INFO'] == '/v1/a/c11a/subdir3/index.html':
|
||||
return Response(status='404 Not Found')(env, start_response)
|
||||
@ -246,10 +248,11 @@ class FakeApp(object):
|
||||
raise Exception('Unknown path %r' % env['PATH_INFO'])
|
||||
|
||||
def listing(self, env, start_response):
|
||||
headers = {'x-container-read': '.r:*'}
|
||||
if env['PATH_INFO'] in ('/v1/a/c3', '/v1/a/c4', '/v1/a/c8', \
|
||||
'/v1/a/c9') and \
|
||||
env['QUERY_STRING'] == 'delimiter=/&format=json&prefix=subdir/':
|
||||
headers = {'x-container-read': '.r:*'}
|
||||
if ((env['PATH_INFO'] in (
|
||||
'/v1/a/c3', '/v1/a/c4', '/v1/a/c8', '/v1/a/c9'))
|
||||
and (env['QUERY_STRING'] ==
|
||||
'delimiter=/&format=json&prefix=subdir/')):
|
||||
headers.update({'X-Container-Object-Count': '12',
|
||||
'X-Container-Bytes-Used': '73763',
|
||||
'X-Container-Read': '.r:*',
|
||||
@ -297,9 +300,10 @@ class FakeApp(object):
|
||||
"content_type":"text/plain",
|
||||
"last_modified":"2011-03-24T04:27:52.709100"}]
|
||||
'''.strip()
|
||||
elif env['PATH_INFO'] == '/v1/a/c10' and (env['QUERY_STRING'] == \
|
||||
elif env['PATH_INFO'] == '/v1/a/c10' and (
|
||||
env['QUERY_STRING'] ==
|
||||
'delimiter=/&format=json&prefix=%E2%98%83/' or
|
||||
env['QUERY_STRING'] == \
|
||||
env['QUERY_STRING'] ==
|
||||
'delimiter=/&format=json&prefix=%E2%98%83/%E2%98%83/'):
|
||||
headers.update({'X-Container-Object-Count': '12',
|
||||
'X-Container-Bytes-Used': '73763',
|
||||
@ -418,12 +422,14 @@ class TestStaticWeb(unittest.TestCase):
|
||||
|
||||
def test_container1_web_mode_explicitly_off(self):
|
||||
resp = Request.blank('/v1/a/c1',
|
||||
headers={'x-web-mode': 'false'}).get_response(self.test_staticweb)
|
||||
headers={'x-web-mode': 'false'}).get_response(
|
||||
self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
|
||||
def test_container1_web_mode_explicitly_on(self):
|
||||
resp = Request.blank('/v1/a/c1',
|
||||
headers={'x-web-mode': 'true'}).get_response(self.test_staticweb)
|
||||
headers={'x-web-mode': 'true'}).get_response(
|
||||
self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
def test_container2(self):
|
||||
@ -434,7 +440,8 @@ class TestStaticWeb(unittest.TestCase):
|
||||
int(resp.headers['x-container-object-count']))
|
||||
|
||||
def test_container2_web_mode_explicitly_off(self):
|
||||
resp = Request.blank('/v1/a/c2',
|
||||
resp = Request.blank(
|
||||
'/v1/a/c2',
|
||||
headers={'x-web-mode': 'false'}).get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assertEquals(resp.content_type, 'text/plain')
|
||||
@ -442,25 +449,27 @@ class TestStaticWeb(unittest.TestCase):
|
||||
int(resp.headers['x-container-object-count']))
|
||||
|
||||
def test_container2_web_mode_explicitly_on(self):
|
||||
resp = Request.blank('/v1/a/c2',
|
||||
resp = Request.blank(
|
||||
'/v1/a/c2',
|
||||
headers={'x-web-mode': 'true'}).get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
def test_container2onetxt(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c2/one.txt').get_response(self.test_staticweb)
|
||||
'/v1/a/c2/one.txt').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
def test_container2json(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c2?format=json').get_response(self.test_staticweb)
|
||||
'/v1/a/c2?format=json').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assertEquals(resp.content_type, 'application/json')
|
||||
self.assertEquals(len(json.loads(resp.body)),
|
||||
int(resp.headers['x-container-object-count']))
|
||||
|
||||
def test_container2json_web_mode_explicitly_off(self):
|
||||
resp = Request.blank('/v1/a/c2?format=json',
|
||||
resp = Request.blank(
|
||||
'/v1/a/c2?format=json',
|
||||
headers={'x-web-mode': 'false'}).get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assertEquals(resp.content_type, 'application/json')
|
||||
@ -468,7 +477,8 @@ class TestStaticWeb(unittest.TestCase):
|
||||
int(resp.headers['x-container-object-count']))
|
||||
|
||||
def test_container2json_web_mode_explicitly_on(self):
|
||||
resp = Request.blank('/v1/a/c2?format=json',
|
||||
resp = Request.blank(
|
||||
'/v1/a/c2?format=json',
|
||||
headers={'x-web-mode': 'true'}).get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
@ -485,18 +495,18 @@ class TestStaticWeb(unittest.TestCase):
|
||||
|
||||
def test_container3subsubdir(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c3/subdir3/subsubdir').get_response(self.test_staticweb)
|
||||
'/v1/a/c3/subdir3/subsubdir').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 301)
|
||||
|
||||
def test_container3subsubdircontents(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c3/subdir3/subsubdir/').get_response(self.test_staticweb)
|
||||
'/v1/a/c3/subdir3/subsubdir/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assertEquals(resp.body, 'index file')
|
||||
|
||||
def test_container3subdir(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c3/subdir/').get_response(self.test_staticweb)
|
||||
'/v1/a/c3/subdir/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('Listing of /v1/a/c3/subdir/' in resp.body)
|
||||
self.assert_('</style>' in resp.body)
|
||||
@ -505,22 +515,22 @@ class TestStaticWeb(unittest.TestCase):
|
||||
|
||||
def test_container3subdirx(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c3/subdirx/').get_response(self.test_staticweb)
|
||||
'/v1/a/c3/subdirx/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
def test_container3subdiry(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c3/subdiry/').get_response(self.test_staticweb)
|
||||
'/v1/a/c3/subdiry/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
def test_container3subdirz(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c3/subdirz').get_response(self.test_staticweb)
|
||||
'/v1/a/c3/subdirz').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 301)
|
||||
|
||||
def test_container3unknown(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c3/unknown').get_response(self.test_staticweb)
|
||||
'/v1/a/c3/unknown').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assert_("Chrome's 404 fancy-page sucks." not in resp.body)
|
||||
|
||||
@ -538,22 +548,26 @@ class TestStaticWeb(unittest.TestCase):
|
||||
def test_container4indexhtmlauthed(self):
|
||||
resp = Request.blank('/v1/a/c4').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 301)
|
||||
resp = Request.blank('/v1/a/c4',
|
||||
environ={'REMOTE_USER': 'authed'}).get_response(self.test_staticweb)
|
||||
resp = Request.blank(
|
||||
'/v1/a/c4',
|
||||
environ={'REMOTE_USER': 'authed'}).get_response(
|
||||
self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
resp = Request.blank('/v1/a/c4', headers={'x-web-mode': 't'},
|
||||
environ={'REMOTE_USER': 'authed'}).get_response(self.test_staticweb)
|
||||
resp = Request.blank(
|
||||
'/v1/a/c4', headers={'x-web-mode': 't'},
|
||||
environ={'REMOTE_USER': 'authed'}).get_response(
|
||||
self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 301)
|
||||
|
||||
def test_container4unknown(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c4/unknown').get_response(self.test_staticweb)
|
||||
'/v1/a/c4/unknown').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assert_("Chrome's 404 fancy-page sucks." in resp.body)
|
||||
|
||||
def test_container4subdir(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c4/subdir/').get_response(self.test_staticweb)
|
||||
'/v1/a/c4/subdir/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('Listing of /v1/a/c4/subdir/' in resp.body)
|
||||
self.assert_('</style>' not in resp.body)
|
||||
@ -564,12 +578,12 @@ class TestStaticWeb(unittest.TestCase):
|
||||
|
||||
def test_container4onetxt(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c4/one.txt').get_response(self.test_staticweb)
|
||||
'/v1/a/c4/one.txt').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
|
||||
def test_container4twotxt(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c4/two.txt').get_response(self.test_staticweb)
|
||||
'/v1/a/c4/two.txt').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 503)
|
||||
|
||||
def test_container5indexhtml(self):
|
||||
@ -578,13 +592,13 @@ class TestStaticWeb(unittest.TestCase):
|
||||
|
||||
def test_container5unknown(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c5/unknown').get_response(self.test_staticweb)
|
||||
'/v1/a/c5/unknown').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assert_("Chrome's 404 fancy-page sucks." not in resp.body)
|
||||
|
||||
def test_container6subdir(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c6/subdir').get_response(self.test_staticweb)
|
||||
'/v1/a/c6/subdir').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 301)
|
||||
|
||||
def test_container7listing(self):
|
||||
@ -593,25 +607,25 @@ class TestStaticWeb(unittest.TestCase):
|
||||
|
||||
def test_container8listingcss(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c8/').get_response(self.test_staticweb)
|
||||
'/v1/a/c8/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('Listing of /v1/a/c8/' in resp.body)
|
||||
self.assert_('<link' in resp.body)
|
||||
self.assert_(
|
||||
'href="http://localhost/stylesheets/listing.css"' in resp.body)
|
||||
'href="http://localhost/stylesheets/listing.css"' in resp.body)
|
||||
|
||||
def test_container8subdirlistingcss(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c8/subdir/').get_response(self.test_staticweb)
|
||||
'/v1/a/c8/subdir/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('Listing of /v1/a/c8/subdir/' in resp.body)
|
||||
self.assert_('<link' in resp.body)
|
||||
self.assert_(
|
||||
'href="http://localhost/stylesheets/listing.css"' in resp.body)
|
||||
'href="http://localhost/stylesheets/listing.css"' in resp.body)
|
||||
|
||||
def test_container9listingcss(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c9/').get_response(self.test_staticweb)
|
||||
'/v1/a/c9/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('Listing of /v1/a/c9/' in resp.body)
|
||||
self.assert_('<link' in resp.body)
|
||||
@ -619,7 +633,7 @@ class TestStaticWeb(unittest.TestCase):
|
||||
|
||||
def test_container9subdirlistingcss(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c9/subdir/').get_response(self.test_staticweb)
|
||||
'/v1/a/c9/subdir/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('Listing of /v1/a/c9/subdir/' in resp.body)
|
||||
self.assert_('<link' in resp.body)
|
||||
@ -627,50 +641,50 @@ class TestStaticWeb(unittest.TestCase):
|
||||
|
||||
def test_container10unicodesubdirlisting(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c10/').get_response(self.test_staticweb)
|
||||
'/v1/a/c10/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('Listing of /v1/a/c10/' in resp.body)
|
||||
resp = Request.blank(
|
||||
'/v1/a/c10/\xe2\x98\x83/').get_response(self.test_staticweb)
|
||||
'/v1/a/c10/\xe2\x98\x83/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('Listing of /v1/a/c10/\xe2\x98\x83/' in resp.body)
|
||||
resp = Request.blank(
|
||||
'/v1/a/c10/\xe2\x98\x83/\xe2\x98\x83/'
|
||||
'/v1/a/c10/\xe2\x98\x83/\xe2\x98\x83/'
|
||||
).get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_(
|
||||
'Listing of /v1/a/c10/\xe2\x98\x83/\xe2\x98\x83/' in resp.body)
|
||||
'Listing of /v1/a/c10/\xe2\x98\x83/\xe2\x98\x83/' in resp.body)
|
||||
|
||||
def test_container11subdirmarkerobjectindex(self):
|
||||
resp = Request.blank('/v1/a/c11/subdir/').get_response(
|
||||
self.test_staticweb)
|
||||
self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('<h2>c11 subdir index</h2>' in resp.body)
|
||||
|
||||
def test_container11subdirmarkermatchdirtype(self):
|
||||
resp = Request.blank('/v1/a/c11a/subdir/').get_response(
|
||||
self.test_staticweb)
|
||||
self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
def test_container11subdirmarkeraltdirtype(self):
|
||||
resp = Request.blank('/v1/a/c11a/subdir2/').get_response(
|
||||
self.test_staticweb)
|
||||
self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
|
||||
def test_container11subdirmarkerinvaliddirtype(self):
|
||||
resp = Request.blank('/v1/a/c11a/subdir3/').get_response(
|
||||
self.test_staticweb)
|
||||
self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
|
||||
|
||||
def test_container12unredirectedrequest(self):
|
||||
resp = Request.blank('/v1/a/c12/').get_response(
|
||||
self.test_staticweb)
|
||||
self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assert_('index file' in resp.body)
|
||||
|
||||
def test_container_unicode_stdlib_json(self):
|
||||
with mock.patch('swift.common.middleware.staticweb.json', new=stdlib_json):
|
||||
with mock.patch('swift.common.middleware.staticweb.json',
|
||||
new=stdlib_json):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c10/').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
@ -688,7 +702,7 @@ class TestStaticWeb(unittest.TestCase):
|
||||
|
||||
def test_subrequest_once_if_possible(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c4/one.txt').get_response(self.test_staticweb)
|
||||
'/v1/a/c4/one.txt').get_response(self.test_staticweb)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assertEquals(resp.headers['x-object-meta-test'], 'value')
|
||||
self.assertEquals(resp.body, '1')
|
||||
|
@ -95,9 +95,10 @@ class TestTempURL(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
|
||||
def assert_valid_sig(self, expires, path, keys, sig):
|
||||
req = self._make_request(path, keys=keys,
|
||||
req = self._make_request(
|
||||
path, keys=keys,
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
self.tempurl.app = FakeApp(iter([('200 Ok', (), '123')]))
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
@ -188,9 +189,10 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assertFalse('content-disposition' in resp.headers)
|
||||
@ -204,10 +206,11 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'REQUEST_METHOD': 'PUT',
|
||||
'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -219,10 +222,11 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'REQUEST_METHOD': 'PUT',
|
||||
'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assertEquals(req.environ['swift.authorize_override'], True)
|
||||
@ -235,9 +239,10 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -249,7 +254,8 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_expires=%s' % expires})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
@ -262,7 +268,8 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s' % sig})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
@ -275,9 +282,10 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -289,9 +297,10 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
req = self._make_request(
|
||||
path, keys=[],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -303,10 +312,11 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'REQUEST_METHOD': 'HEAD',
|
||||
'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assertEquals(req.environ['swift.authorize_override'], True)
|
||||
@ -319,10 +329,11 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'REQUEST_METHOD': 'HEAD',
|
||||
'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assertEquals(req.environ['swift.authorize_override'], True)
|
||||
@ -338,10 +349,11 @@ class TestTempURL(unittest.TestCase):
|
||||
# Deliberately fudge expires to show HEADs aren't just automatically
|
||||
# allowed.
|
||||
expires += 1
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'REQUEST_METHOD': 'HEAD',
|
||||
'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
|
||||
@ -352,10 +364,11 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'REQUEST_METHOD': 'POST',
|
||||
'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -367,10 +380,11 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'REQUEST_METHOD': 'DELETE',
|
||||
'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -383,10 +397,11 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'REQUEST_METHOD': 'DELETE',
|
||||
'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
|
||||
@ -397,10 +412,11 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'REQUEST_METHOD': 'UNKNOWN',
|
||||
'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -412,9 +428,10 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path + '2', keys=[key],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
req = self._make_request(
|
||||
path + '2', keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -430,9 +447,10 @@ class TestTempURL(unittest.TestCase):
|
||||
sig = sig[:-1] + '0'
|
||||
else:
|
||||
sig = sig[:-1] + '1'
|
||||
req = self._make_request(path, keys=[key],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -444,10 +462,10 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' %
|
||||
(sig, expires + 1)})
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires + 1)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -459,9 +477,10 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key + '2'],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
req = self._make_request(
|
||||
path, keys=[key + '2'],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
@ -475,10 +494,11 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
headers={'x-remove-this': 'value'},
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assertTrue('x-remove-this' not in self.app.request.headers)
|
||||
@ -493,11 +513,12 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
headers={'x-remove-this-one': 'value1',
|
||||
'x-remove-this-except-this': 'value2'},
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assertTrue('x-remove-this-one' not in self.app.request.headers)
|
||||
@ -513,9 +534,10 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assertTrue('x-test-header-one-a' not in resp.headers)
|
||||
@ -531,9 +553,10 @@ class TestTempURL(unittest.TestCase):
|
||||
key = 'abc'
|
||||
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||
req = self._make_request(path, keys=[key],
|
||||
environ={'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (sig, expires)})
|
||||
req = self._make_request(
|
||||
path, keys=[key],
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEquals(resp.status_int, 404)
|
||||
self.assertEquals(resp.headers['x-test-header-one-a'], 'value1')
|
||||
@ -573,29 +596,47 @@ class TestTempURL(unittest.TestCase):
|
||||
def test_get_temp_url_info(self):
|
||||
s = 'f5d5051bddf5df7e27c628818738334f'
|
||||
e = int(time() + 86400)
|
||||
self.assertEquals(self.tempurl._get_temp_url_info({'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (s, e)}), (s, e, None))
|
||||
self.assertEquals(self.tempurl._get_temp_url_info({
|
||||
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s&'
|
||||
'filename=bobisyouruncle' % (s, e)}), (s, e, 'bobisyouruncle'))
|
||||
self.assertEquals(self.tempurl._get_temp_url_info({}),
|
||||
(None, None, None))
|
||||
self.assertEquals(self.tempurl._get_temp_url_info({'QUERY_STRING':
|
||||
'temp_url_expires=%s' % e}), (None, e, None))
|
||||
self.assertEquals(self.tempurl._get_temp_url_info({'QUERY_STRING':
|
||||
'temp_url_sig=%s' % s}), (s, None, None))
|
||||
self.assertEquals(self.tempurl._get_temp_url_info({'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=bad' % s}), (s, 0, None))
|
||||
self.assertEquals(
|
||||
self.tempurl._get_temp_url_info(
|
||||
{'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
s, e)}),
|
||||
(s, e, None))
|
||||
self.assertEquals(
|
||||
self.tempurl._get_temp_url_info(
|
||||
{'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s&'
|
||||
'filename=bobisyouruncle' % (s, e)}),
|
||||
(s, e, 'bobisyouruncle'))
|
||||
self.assertEquals(
|
||||
self.tempurl._get_temp_url_info({}),
|
||||
(None, None, None))
|
||||
self.assertEquals(
|
||||
self.tempurl._get_temp_url_info(
|
||||
{'QUERY_STRING': 'temp_url_expires=%s' % e}),
|
||||
(None, e, None))
|
||||
self.assertEquals(
|
||||
self.tempurl._get_temp_url_info(
|
||||
{'QUERY_STRING': 'temp_url_sig=%s' % s}),
|
||||
(s, None, None))
|
||||
self.assertEquals(
|
||||
self.tempurl._get_temp_url_info(
|
||||
{'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=bad' % (
|
||||
s)}),
|
||||
(s, 0, None))
|
||||
e = int(time() - 1)
|
||||
self.assertEquals(self.tempurl._get_temp_url_info({'QUERY_STRING':
|
||||
'temp_url_sig=%s&temp_url_expires=%s' % (s, e)}), (s, 0, None))
|
||||
self.assertEquals(
|
||||
self.tempurl._get_temp_url_info(
|
||||
{'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||
s, e)}),
|
||||
(s, 0, None))
|
||||
|
||||
def test_get_hmac(self):
|
||||
self.assertEquals(self.tempurl._get_hmac(
|
||||
self.assertEquals(
|
||||
self.tempurl._get_hmac(
|
||||
{'REQUEST_METHOD': 'GET', 'PATH_INFO': '/v1/a/c/o'},
|
||||
1, 'abc'),
|
||||
'026d7f7cc25256450423c7ad03fc9f5ffc1dab6d')
|
||||
self.assertEquals(self.tempurl._get_hmac(
|
||||
self.assertEquals(
|
||||
self.tempurl._get_hmac(
|
||||
{'REQUEST_METHOD': 'HEAD', 'PATH_INFO': '/v1/a/c/o'},
|
||||
1, 'abc', request_method='GET'),
|
||||
'026d7f7cc25256450423c7ad03fc9f5ffc1dab6d')
|
||||
@ -605,34 +646,40 @@ class TestTempURL(unittest.TestCase):
|
||||
def _start_response(status, headers, exc_info=None):
|
||||
self.assertTrue(status, '401 Unauthorized')
|
||||
|
||||
self.assertTrue('Temp URL invalid' in
|
||||
''.join(self.tempurl._invalid({'REQUEST_METHOD': 'GET'},
|
||||
_start_response)))
|
||||
self.assertEquals('',
|
||||
''.join(self.tempurl._invalid({'REQUEST_METHOD': 'HEAD'},
|
||||
_start_response)))
|
||||
self.assertTrue('Temp URL invalid' in ''.join(
|
||||
self.tempurl._invalid({'REQUEST_METHOD': 'GET'},
|
||||
_start_response)))
|
||||
self.assertEquals('', ''.join(
|
||||
self.tempurl._invalid({'REQUEST_METHOD': 'HEAD'},
|
||||
_start_response)))
|
||||
|
||||
def test_clean_incoming_headers(self):
|
||||
irh = ''
|
||||
iah = ''
|
||||
env = {'HTTP_TEST_HEADER': 'value'}
|
||||
tempurl.TempURL(None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah})._clean_incoming_headers(env)
|
||||
tempurl.TempURL(
|
||||
None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah}
|
||||
)._clean_incoming_headers(env)
|
||||
self.assertTrue('HTTP_TEST_HEADER' in env)
|
||||
|
||||
irh = 'test-header'
|
||||
iah = ''
|
||||
env = {'HTTP_TEST_HEADER': 'value'}
|
||||
tempurl.TempURL(None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah})._clean_incoming_headers(env)
|
||||
tempurl.TempURL(
|
||||
None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah}
|
||||
)._clean_incoming_headers(env)
|
||||
self.assertTrue('HTTP_TEST_HEADER' not in env)
|
||||
|
||||
irh = 'test-header-*'
|
||||
iah = ''
|
||||
env = {'HTTP_TEST_HEADER_ONE': 'value',
|
||||
'HTTP_TEST_HEADER_TWO': 'value'}
|
||||
tempurl.TempURL(None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah})._clean_incoming_headers(env)
|
||||
tempurl.TempURL(
|
||||
None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah}
|
||||
)._clean_incoming_headers(env)
|
||||
self.assertTrue('HTTP_TEST_HEADER_ONE' not in env)
|
||||
self.assertTrue('HTTP_TEST_HEADER_TWO' not in env)
|
||||
|
||||
@ -640,8 +687,10 @@ class TestTempURL(unittest.TestCase):
|
||||
iah = 'test-header-two'
|
||||
env = {'HTTP_TEST_HEADER_ONE': 'value',
|
||||
'HTTP_TEST_HEADER_TWO': 'value'}
|
||||
tempurl.TempURL(None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah})._clean_incoming_headers(env)
|
||||
tempurl.TempURL(
|
||||
None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah}
|
||||
)._clean_incoming_headers(env)
|
||||
self.assertTrue('HTTP_TEST_HEADER_ONE' not in env)
|
||||
self.assertTrue('HTTP_TEST_HEADER_TWO' in env)
|
||||
|
||||
@ -652,8 +701,10 @@ class TestTempURL(unittest.TestCase):
|
||||
'HTTP_TEST_OTHER_HEADER': 'value',
|
||||
'HTTP_TEST_HEADER_YES': 'value',
|
||||
'HTTP_TEST_HEADER_YES_THIS': 'value'}
|
||||
tempurl.TempURL(None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah})._clean_incoming_headers(env)
|
||||
tempurl.TempURL(
|
||||
None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah}
|
||||
)._clean_incoming_headers(env)
|
||||
self.assertTrue('HTTP_TEST_HEADER_ONE' not in env)
|
||||
self.assertTrue('HTTP_TEST_HEADER_TWO' in env)
|
||||
self.assertTrue('HTTP_TEST_OTHER_HEADER' not in env)
|
||||
@ -664,26 +715,29 @@ class TestTempURL(unittest.TestCase):
|
||||
orh = ''
|
||||
oah = ''
|
||||
hdrs = {'test-header': 'value'}
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(None,
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(
|
||||
None,
|
||||
{'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
self.assertTrue('test-header' in hdrs)
|
||||
|
||||
orh = 'test-header'
|
||||
oah = ''
|
||||
hdrs = {'test-header': 'value'}
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(None,
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(
|
||||
None,
|
||||
{'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
self.assertTrue('test-header' not in hdrs)
|
||||
|
||||
orh = 'test-header-*'
|
||||
oah = ''
|
||||
hdrs = {'test-header-one': 'value',
|
||||
'test-header-two': 'value'}
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(None,
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(
|
||||
None,
|
||||
{'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
self.assertTrue('test-header-one' not in hdrs)
|
||||
self.assertTrue('test-header-two' not in hdrs)
|
||||
|
||||
@ -691,9 +745,10 @@ class TestTempURL(unittest.TestCase):
|
||||
oah = 'test-header-two'
|
||||
hdrs = {'test-header-one': 'value',
|
||||
'test-header-two': 'value'}
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(None,
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(
|
||||
None,
|
||||
{'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
self.assertTrue('test-header-one' not in hdrs)
|
||||
self.assertTrue('test-header-two' in hdrs)
|
||||
|
||||
@ -704,9 +759,10 @@ class TestTempURL(unittest.TestCase):
|
||||
'test-other-header': 'value',
|
||||
'test-header-yes': 'value',
|
||||
'test-header-yes-this': 'value'}
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(None,
|
||||
hdrs = HeaderKeyDict(tempurl.TempURL(
|
||||
None,
|
||||
{'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
)._clean_outgoing_headers(hdrs.iteritems()))
|
||||
self.assertTrue('test-header-one' not in hdrs)
|
||||
self.assertTrue('test-header-two' in hdrs)
|
||||
self.assertTrue('test-other-header' not in hdrs)
|
||||
|
Loading…
x
Reference in New Issue
Block a user