Permalink
Browse files

fix headers and URL rewriting in recorder (TSUN-178)

  • Loading branch information...
1 parent 3919e94 commit dc17030c25c973dd989b932f897e7bea887ba3d4 @nniclausse nniclausse committed Jan 19, 2011
Showing with 21 additions and 4 deletions.
  1. +16 −0 src/test/ts_test_proxy.erl
  2. +3 −3 src/tsung/ts_utils.erl
  3. +2 −1 src/tsung_recorder/ts_proxy_http.erl
View
@@ -26,6 +26,14 @@ relative_url_test()->
?assertMatch({ok,"foo /bar/foo.html foo bar"},
ts_proxy_http:relative_url(false,String,AbsURI,RelURL)).
+relative_url2_test()->
+ myset_env(),
+ String= "foo http://www.glop.com/(;-)/foo.html foo bar",
+ AbsURI="http://www.glop.com/(;-)/foo.html?toto=bar",
+ RelURL="/(;-)/foo.html?toto=bar",
+ ?assertMatch({ok,"foo /(;-)/foo.html foo bar"},
+ ts_proxy_http:relative_url(false,String,AbsURI,RelURL)).
+
rewrite_http_none_test()->
myset_env(),
Data="HTTP/1.1 200 OK
@@ -104,13 +112,21 @@ rewrite_http_encode_test()->
{ok, Res} = ts_utils:to_https({request,Data}),
?assertEqual(list_to_binary(NewData), iolist_to_binary(Res)).
+
rewrite_http_encode2_test()->
myset_env(),
Data="GET http://gforge-qualif.foo.fr/ HTTP/1.1\r\nHost: gforge-qualif.foo.fr\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.1.6) Gecko/20100107 Fedora/3.5.6-1.fc12 Firefox/3.5.6\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: fr,en-us;q=0.7,en;q=0.3\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 300\r\nProxy-Connection: keep-alive\r\nPragma: no-cache\r\nCache-Control: no-cache\r\n\r\n",
NewData="GET http://gforge-qualif.foo.fr/ HTTP/1.1\r\nHost: gforge-qualif.foo.fr\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.1.6) Gecko/20100107 Fedora/3.5.6-1.fc12 Firefox/3.5.6\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: fr,en-us;q=0.7,en;q=0.3\r\nAccept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 300\r\nProxy-Connection: keep-alive\r\nPragma: no-cache\r\nCache-Control: no-cache\r\n\r\n",
{ok, Res} = ts_utils:to_https({request,Data}),
?assertEqual(list_to_binary(NewData), iolist_to_binary(Res)).
+rewrite_http_encode3_test()->
+ myset_env(),
+ Data="GET http://-secure.foo.com/ HTTP/1.1\r\nHost: -secure.com\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0b9) Gecko/20100101 Firefox/4.0b9\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: fr,en-us;q=0.7,en;q=0.3\r\nAccept-Encoding: gzip, deflate\r\nAccept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 115\r\nProxy-Connection: keep-alive\r\n\r\n",
+ NewData="GET https://secure.foo.com/ HTTP/1.1\r\nHost: secure.com\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0b9) Gecko/20100101 Firefox/4.0b9\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: fr,en-us;q=0.7,en;q=0.3\r\nAccept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 115\r\nProxy-Connection: keep-alive\r\n\r\n",
+ {ok, Res} = ts_utils:to_https({request,Data}),
+ ?assertEqual(list_to_binary(NewData), iolist_to_binary(Res)).
+
rewrite_webdav_test()->
myset_env(),
Data = "REPORT /tsung/!svn/vcc/default HTTP/1.1\r\nUser-Agent: SVN/1.4.4 (r25188) neon/0.25.5\r\nConnection: TE\r\nTE: trailers\r\nContent-Length: 172\r\nContent-Type: text/xml\r\nAccept-Encoding: svndiff1;q=0.9,svndiff;q=0.8\r\nAccept-Encoding: gzip\r\nAccept-Encoding: gzip\r\n\r\n<S:update-report send-all=\"true\" xmlns:S=\"svn:\"><S:src-path>http://-svn.process-one.net/tsung/trunk/examples</S:src-path><S:entry rev=\"816\" ></S:entry></S:update-report>",
View
@@ -431,12 +431,12 @@ to_https({request, String}) when is_list(String) ->
EndOfHeader = string:str(String, "\r\n\r\n"),
Header = string:substr(String, 1, EndOfHeader - 1) ++ "\r\n",
Body = string:substr(String, EndOfHeader + 4),
- ReOpts=[global],
+ ReOpts=[global,{return,list}],
TmpHeader = re:replace(Header,"http://-","https://",ReOpts),
- TmpHeader2 = re:replace(TmpHeader,"Accept-Encoding: [0-9,a-zA-Z_]+\r\n","",ReOpts),
+ TmpHeader2 = re:replace(TmpHeader,"Accept-Encoding: [0-9,a-zA-Z_ ]+\r\n","",ReOpts),
RealHeader = re:replace(TmpHeader2,"Host: -","Host: ",ReOpts),
RealBody = re:replace(Body,"http://-","https://",ReOpts),
- RealString = [RealHeader, "\r\n" , RealBody],
+ RealString = RealHeader++ "\r\n" ++ RealBody,
{ok, RealString}.
@@ -172,7 +172,8 @@ relative_url(true,String,_RequestURI,_RelURL)->
relative_url(false,String,RequestURI,RelURL)->
[FullURL_noargs|_] = string:tokens(RequestURI,"?"),
[RelURL_noargs|_] = string:tokens(RelURL,"?"),
- RealString = re:replace(String,FullURL_noargs,RelURL_noargs,[{return,list}]),
+ FullURL = re:replace(FullURL_noargs,"(\\)|\\()","\\\\&",[global,{return,list}]),
+ RealString = re:replace(String,FullURL,RelURL_noargs,[{return,list}]),
{ok, RealString}.
%%--------------------------------------------------------------------

0 comments on commit dc17030

Please sign in to comment.