improved router, thanks Jonathan
This commit is contained in:
@@ -13,6 +13,7 @@ if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon')) # running from web2py base
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../')) # running from gluon/tests/
|
||||
os.environ['web2py_path'] = os.path.realpath('../../') # for settings
|
||||
|
||||
from rewrite import load, filter_url, filter_err, get_effective_router, map_url_out
|
||||
from html import URL
|
||||
@@ -794,6 +795,49 @@ class TestRouter(unittest.TestCase):
|
||||
self.assertEqual(filter_err(399), 399)
|
||||
self.assertEqual(filter_err(400), 400)
|
||||
|
||||
def test_router_static_path(self):
|
||||
'''
|
||||
Test validation of static paths
|
||||
Stock pattern: file_match = r'([-+=@$%\w]+[./]?)+$'
|
||||
|
||||
'''
|
||||
load(rdict=dict())
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/to/static'), "%s/applications/welcome/static/path/to/static" % root)
|
||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/welcome/static/bad/path/to/st~tic')
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/to--/static'), "%s/applications/welcome/static/path/to--/static" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/==to--/static'), "%s/applications/welcome/static/path/==to--/static" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/-+=@$%/static'), "%s/applications/welcome/static/path/-+=@$%%/static" % root)
|
||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/welcome/static/bad/path/to/.static')
|
||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/welcome/static/bad/path/to/s..tatic')
|
||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/welcome/static/bad/path/to//static')
|
||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/welcome/static/bad/path/to/#static')
|
||||
|
||||
router_static = dict(
|
||||
BASE = dict(
|
||||
file_match = r'([-+=@$%#\w]+[./]?)+$', # legal static path
|
||||
),
|
||||
)
|
||||
load(rdict=router_static)
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/to/#static'), "%s/applications/welcome/static/path/to/#static" % root)
|
||||
|
||||
router_static = dict(
|
||||
BASE = dict(
|
||||
file_match = r'[-+=@$%#.\w]+$', # legal static path element
|
||||
),
|
||||
)
|
||||
load(rdict=router_static)
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/to/static'), "%s/applications/welcome/static/path/to/static" % root)
|
||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/welcome/static/bad/path/to/st~tic')
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/to--/static'), "%s/applications/welcome/static/path/to--/static" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/==to--/static'), "%s/applications/welcome/static/path/==to--/static" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/-+=@$%/static'), "%s/applications/welcome/static/path/-+=@$%%/static" % root)
|
||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/welcome/static/bad/path/to//static')
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/to/#static'), "%s/applications/welcome/static/path/to/#static" % root)
|
||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/welcome/static/bad/path/./static')
|
||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/welcome/static/bad/path/../static')
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/.../static'), "%s/applications/welcome/static/path/.../static" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/welcome/static/path/to/.static'), "%s/applications/welcome/static/path/to/.static" % root)
|
||||
|
||||
def test_router_args(self):
|
||||
'''
|
||||
Test URL args parsing/generation
|
||||
|
||||
@@ -13,6 +13,7 @@ if os.path.isdir('gluon'):
|
||||
sys.path.append(os.path.realpath('gluon')) # running from web2py base
|
||||
else:
|
||||
sys.path.append(os.path.realpath('../')) # running from gluon/tests/
|
||||
os.environ['web2py_path'] = os.path.realpath('../../') # for settings
|
||||
|
||||
from rewrite import load, filter_url, filter_err, get_effective_router, regex_filter_out, regex_select
|
||||
from html import URL
|
||||
|
||||
Reference in New Issue
Block a user