From: <am...@us...> - 2009-11-29 16:11:51
|
Revision: 6951 http://jython.svn.sourceforge.net/jython/?rev=6951&view=rev Author: amak Date: 2009-11-29 16:11:42 +0000 (Sun, 29 Nov 2009) Log Message: ----------- Fixing a bug with callable_query_string. Making treatment more strict when no value is supplied. Added unit tests to cover varying scenarios. modjy crashes if any query string parameters are not set with '=' http://bugs.jython.org/issue1507 Modified Paths: -------------- trunk/jython/Lib/modjy/modjy_publish.py trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java Modified: trunk/jython/Lib/modjy/modjy_publish.py =================================================================== --- trunk/jython/Lib/modjy/modjy_publish.py 2009-11-25 08:48:20 UTC (rev 6950) +++ trunk/jython/Lib/modjy/modjy_publish.py 2009-11-29 16:11:42 UTC (rev 6951) @@ -42,11 +42,16 @@ callable_name = self.params['app_callable_name'] if self.params['callable_query_name']: query_string = req.getQueryString() - if query_string and '=' in query_string: + if query_string: for name_val in query_string.split('&'): - name, value = name_val.split('=') + if name_val.find('=') != -1: + name, value = name_val.split('=', 1) + else: + name, value = name_val, '' if name == self.params['callable_query_name']: callable_name = value + else: + callable_name = '' return source_uri, callable_name def get_app_object(self, req, environ): @@ -55,7 +60,7 @@ environ["PATH_INFO"] = path_info environ["PATH_TRANSLATED"] = File(self.app_directory, path_info).getPath() - if self.params['app_import_name'] is not None: + if self.params['app_import_name']: return self.get_app_object_importable(self.params['app_import_name']) else: if self.cache is None: Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java 2009-11-25 08:48:20 UTC (rev 6950) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java 2009-11-29 16:11:42 UTC (rev 6951) @@ -68,6 +68,16 @@ return importPath.toString(); } + public void testAppImportCallableNoValue() throws Exception { + appInvocationTestSetUp(); + String importableName = setupAppImport("WSGIHandlerFunction"); + setAppImportable(""); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + public void testAppImportCallable() throws Exception { appInvocationTestSetUp(); String importableName = setupAppImport("WSGIHandlerFunction"); @@ -183,4 +193,66 @@ doGet(); assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); } + + protected void callableQueryAppInvocationTestSetUp() throws Exception { + baseSetUp(); + setRealPath("/test_apps_dir", "test_apps_dir"); + setAppDir("$/test_apps_dir"); + setAppFile("invocation_tests.py"); + // Callable query names should never fall back on app_callable_name + setAppName("should_never_be_called"); + setCallableQueryName(""); + setQueryString(""); + } + + public void testCallableQueryString() throws Exception { + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + setQueryString("python_object=valid_callable"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("valid_callable invoked", result); + } + + public void testCallableQueryStringNoParam() throws Exception { + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + + public void testCallableQueryStringParamNoValue() throws Exception { + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + setQueryString("python_object"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + + public void testCallableQueryStringParamTwoValues() throws Exception { + // This has to fail, because a python identifier cannot contain an '=' + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + setQueryString("python_object=valid_callable=extra_value"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + + public void testCallableQueryStringParamNonExistentValue() throws Exception { + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + setQueryString("python_object=invalid_callable"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + } Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-11-25 08:48:20 UTC (rev 6950) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-11-29 16:11:42 UTC (rev 6951) @@ -173,6 +173,10 @@ setInitParameter("app_callable_name", app_name); } + public void setCallableQueryName(String query_name) { + setInitParameter("callable_query_name", query_name); + } + public void setAppImportable(String app_path) { setAppDir(""); setAppFile(""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |