I’d like to come up with some automated tests to validate my servers handling of invalid request URIs. For example, a tester was able to send this as his url using curl on windows:
http://127.0.0.1/C:\an\incorrect\path\file.txt
I have handling on the server to deal with that, but still want to add tests if possible. Tried to do it with HttpClient but HttpClient doesn’t like the invalid characters 😉
// Run client
String Url = targetHost + filePath + fileName;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Url);
// run test
InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(sourceDir.getAbsolutePath() + LusConstants.DIR_SEPERATOR + fileName),-1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(chunked);
httppost.setEntity(reqEntity);
httpclient.execute(httppost);
Exception from HttpClient:
aused by: java.net.URISyntaxException: Illegal character in path at index 39: http://127.0.0.1:8080//a/deeper/path/an\incorrect\path\file.txt
at java.net.URI$Parser.fail(Unknown Source)
at java.net.URI$Parser.checkChars(Unknown Source)
at java.net.URI$Parser.parseHierarchical(Unknown Source)
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
... 4 more
Any thoughts?
\i escapes. The result is a tab.
An url may only hold printable US-ASCII code.
There is a % notation for other codes
use for backslash
%5c = “\”