~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/inets/test/http_format_SUITE.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 2004-2011. All Rights Reserved.
 
5
%%
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%%
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%%
 
17
%% %CopyrightEnd%
 
18
%%
 
19
%%
 
20
 
 
21
-module(http_format_SUITE).
 
22
-author('ingela@erix.ericsson.se').
 
23
 
 
24
-include_lib("common_test/include/ct.hrl").
 
25
-include("test_server_line.hrl").
 
26
-include("http_internal.hrl").
 
27
 
 
28
%% Test server specific exports
 
29
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, init_per_testcase/2, end_per_testcase/2]).
 
30
 
 
31
%% Test cases must be exported.
 
32
-export([ chunk_decode/1, chunk_encode/1,
 
33
          chunk_extensions_otp_6005/1, chunk_decode_otp_6264/1,
 
34
          chunk_decode_empty_chunk_otp_6511/1,
 
35
          chunk_decode_trailer/1,
 
36
          http_response/1, http_request/1, validate_request_line/1,
 
37
          esi_parse_headers/1, cgi_parse_headers/1,
 
38
          is_absolut_uri/1, convert_netscapecookie_date/1]).
 
39
 
 
40
suite() -> [{ct_hooks,[ts_install_cth]}].
 
41
 
 
42
all() -> 
 
43
    [{group, chunk}, http_response, http_request,
 
44
     validate_request_line, {group, script}, is_absolut_uri,
 
45
     convert_netscapecookie_date].
 
46
 
 
47
groups() -> 
 
48
    [{script, [], [esi_parse_headers, cgi_parse_headers]},
 
49
     {chunk, [],
 
50
      [chunk_decode, chunk_encode, chunk_extensions_otp_6005,
 
51
       chunk_decode_otp_6264,
 
52
       chunk_decode_empty_chunk_otp_6511,
 
53
       chunk_decode_trailer]}].
 
54
 
 
55
init_per_suite(Config) ->
 
56
    Config.
 
57
 
 
58
end_per_suite(_Config) ->
 
59
    ok.
 
60
 
 
61
init_per_group(_GroupName, Config) ->
 
62
    Config.
 
63
 
 
64
end_per_group(_GroupName, Config) ->
 
65
    Config.
 
66
 
 
67
 
 
68
init_per_testcase(_, Config) ->
 
69
    Dog = test_server:timetrap(?t:minutes(1)),
 
70
    NewConfig = lists:keydelete(watchdog, 1, Config),
 
71
    [{watchdog, Dog} | NewConfig].
 
72
 
 
73
end_per_testcase(_, Config) ->
 
74
    Dog = ?config(watchdog, Config),
 
75
    test_server:timetrap_cancel(Dog),
 
76
    ok.
 
77
 
 
78
%%-------------------------------------------------------------------------
 
79
%% Test cases starts here.
 
80
%%-------------------------------------------------------------------------
 
81
 
 
82
 
 
83
%%-------------------------------------------------------------------------
 
84
chunk_decode(doc) ->
 
85
    ["Test http_chunk:decode/3"];
 
86
chunk_decode(suite) ->
 
87
    [];
 
88
chunk_decode(Config) when is_list(Config) ->
 
89
    ReqHeaders =  #http_request_h{'transfer-encoding' = "chunked"},
 
90
    ChunkedBody = "A" ++ ?CRLF ++ "1234567890" ++ ?CRLF ++ "4" ++
 
91
        ?CRLF ++ "HEJ!" ++ ?CRLF ++ "0" ++ ?CRLF ++ ?CRLF,    
 
92
    {ok, {Headers, Body}} = 
 
93
        http_chunk:decode(list_to_binary(ChunkedBody),
 
94
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
95
    "1234567890HEJ!"  = binary_to_list(Body),
 
96
    %% When the "chunked" is removed by the decoding the header
 
97
    %% will become empty in this case i.e. undefined!
 
98
    NewReqHeaders = http_chunk:handle_headers(ReqHeaders, Headers),
 
99
    undefined = NewReqHeaders#http_request_h.'transfer-encoding',
 
100
 
 
101
    NewChunkedBody = ["A" ++ [?CR], [?LF] ++ "12345", "67890" ++ ?CRLF ++ "4"
 
102
                      ++ ?CRLF ++ "HEJ!" ++ ?CRLF ++ "0" ++ [?CR], 
 
103
                      [?LF, ?CR, ?LF]], 
 
104
 
 
105
    {Module, Function, Args} = 
 
106
        http_chunk:decode(list_to_binary(hd(NewChunkedBody)),
 
107
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
108
 
 
109
    {_, Body} = parse(Module, Function, Args, tl(NewChunkedBody)),
 
110
    "1234567890HEJ!" = binary_to_list(Body),
 
111
 
 
112
    ok.
 
113
 
 
114
%%-------------------------------------------------------------------------
 
115
chunk_extensions_otp_6005(doc) ->
 
116
    ["Make sure so called extensions are ignored"];
 
117
chunk_extensions_otp_6005(suite) ->
 
118
    [];
 
119
chunk_extensions_otp_6005(Config) when is_list(Config)->
 
120
    ChunkedBody = "A;ignore this" ++ ?CRLF ++ "1234567890" ++
 
121
        ?CRLF ++ "4" ++ ?CRLF  ++ "HEJ!"++ ?CRLF  ++ "0" ++
 
122
        ";extensionname=extensionvalue;foo=bar" ++ ?CRLF ++ ?CRLF,
 
123
     {ok, {["content-length:14"], Body}} = 
 
124
        http_chunk:decode(list_to_binary(ChunkedBody),
 
125
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
126
        "1234567890HEJ!"  = binary_to_list(Body),
 
127
 
 
128
    ChunkedBody1 = ["A;", "ignore this" ++ [?CR], [?LF] ++ "1234567890" ++
 
129
                    ?CRLF ++ "4" ++ ?CRLF  ++ "HEJ!"++ ?CRLF  ++ "0" ++
 
130
                    ";extensionname=extensionvalue;foo=bar" ++ ?CRLF ++ ?CRLF],
 
131
    
 
132
    {Module1, Function1, Args1} = 
 
133
        http_chunk:decode(list_to_binary(hd(ChunkedBody1)),
 
134
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
135
    
 
136
    {_, NewBody} = parse(Module1, Function1, Args1, tl(ChunkedBody1)),
 
137
    "1234567890HEJ!" = binary_to_list(NewBody),
 
138
    ok.
 
139
 
 
140
%%-------------------------------------------------------------------------
 
141
chunk_decode_otp_6264(doc) ->
 
142
      ["Check that 0 in the body does not count as the last chunk"];
 
143
chunk_decode_otp_6264(suite) ->
 
144
    [];
 
145
chunk_decode_otp_6264(Config) when is_list(Config)->
 
146
    ChunkedBody = "A;ignore this" ++ ?CRLF ++ "1234567890" ++
 
147
        ?CRLF ++ "4" ++ ?CRLF  ++ "0123"++ ?CRLF  ++ "0" ++
 
148
        ";extensionname=extensionvalue;foo=bar" ++ ?CRLF ++ ?CRLF,
 
149
     {ok, {["content-length:14"], Body}} = 
 
150
        http_chunk:decode(list_to_binary(ChunkedBody),
 
151
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
152
        "12345678900123"  = binary_to_list(Body),
 
153
 
 
154
     NewChunkedBody = ["A" ++ [?CR], [?LF] ++ "12345", "67890" ++ ?CRLF ++ "1"
 
155
                      ++ ?CRLF ++ "0" ++ ?CRLF ++ "0" ++ [?CR], 
 
156
                      [?LF, ?CR, ?LF]],
 
157
 
 
158
    {Module, Function, Args} = 
 
159
        http_chunk:decode(list_to_binary(hd(NewChunkedBody)),
 
160
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
161
    
 
162
    {_, NewBody} = parse(Module, Function, Args, tl(NewChunkedBody)),
 
163
    "12345678900" = binary_to_list(NewBody),
 
164
    
 
165
    NewChunkedBody1 = ["A" ++ [?CR], [?LF] ++ "12345", "67890" ++ ?CRLF ++ "1"
 
166
                      ++ ?CRLF ++ "0", ?CRLF ++ "0", [?CR], [?LF], 
 
167
                      [?CR], [?LF]],
 
168
 
 
169
    {Module1, Function1, Args1} = 
 
170
        http_chunk:decode(list_to_binary(hd(NewChunkedBody1)),
 
171
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
172
    
 
173
    {_, NewBody} = parse(Module1, Function1, Args1, tl(NewChunkedBody1)),
 
174
    "12345678900" = binary_to_list(NewBody),
 
175
    
 
176
    ok.
 
177
%%-------------------------------------------------------------------------
 
178
chunk_decode_empty_chunk_otp_6511(doc) ->
 
179
    [""];
 
180
chunk_decode_empty_chunk_otp_6511(suite) ->
 
181
    [];
 
182
chunk_decode_empty_chunk_otp_6511(Config) when is_list(Config) ->
 
183
    ChunkedBody = "0" ++ ?CRLF ++ ?CRLF,
 
184
    {ok,{["content-length:0"],<<>>}}  = 
 
185
        http_chunk:decode(list_to_binary(ChunkedBody),
 
186
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
187
    ok.
 
188
    
 
189
%%-------------------------------------------------------------------------
 
190
chunk_decode_trailer(doc) ->
 
191
    ["Make sure trailers are handled correctly. Trailers should"
 
192
     "become new headers"];
 
193
chunk_decode_trailer(suite) ->
 
194
    [];
 
195
chunk_decode_trailer(Config) when is_list(Config)->
 
196
    ChunkedBody = "1a; ignore-stuff-here" ++ ?CRLF ++ 
 
197
        "abcdefghijklmnopqrstuvwxyz" ++ ?CRLF ++ "10"  ++ ?CRLF 
 
198
        ++ "1234567890abcdef" ++ ?CRLF  ++ "0" ++ ?CRLF 
 
199
        ++ "some-footer:some-value"  ++ ?CRLF 
 
200
        ++ "another-footer:another-value" ++ ?CRLF ++ ?CRLF,
 
201
 
 
202
    {ok, {Headers, Body}} = 
 
203
    http_chunk:decode(list_to_binary(ChunkedBody),
 
204
                      ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
205
    
 
206
    %% There is no guaranteed order of headers.
 
207
    true = lists:member("content-length:42", Headers),
 
208
    true = lists:member("some-footer:some-value", Headers),
 
209
    true = lists:member("another-footer:another-value", Headers),
 
210
    "abcdefghijklmnopqrstuvwxyz1234567890abcdef"  = binary_to_list(Body), 
 
211
 
 
212
    ChunkedBody1 = "1a" ++ ?CRLF ++ 
 
213
        "abcdefghijklmnopqrstuvwxyz" ++ ?CRLF ++ "10"  ++ ?CRLF 
 
214
        ++ "1234567890abcdef" ++ ?CRLF  ++ "0" ++ ?CRLF
 
215
        ++ "some-footer:some-value"  ++ ?CRLF  ++ ?CRLF,
 
216
    
 
217
    {ok, {Headers1, Body1}} = 
 
218
        http_chunk:decode(list_to_binary(ChunkedBody1),
 
219
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
220
    
 
221
    true = lists:member("content-length:42", Headers1),
 
222
    true = lists:member("some-footer:some-value", Headers1),
 
223
    false = lists:member("another-footer:another-value", Headers1),
 
224
    "abcdefghijklmnopqrstuvwxyz1234567890abcdef"  = binary_to_list(Body1), 
 
225
 
 
226
 
 
227
    ChunkedBody2 = ["1a", ?CRLF ++ 
 
228
                    "abcdefghijklmnopqrstuvwxyz" ++ ?CRLF ++ "10"  ++ ?CRLF 
 
229
                    ++ "1234567890abcdef" ++ ?CRLF  ++ "0", ";", 
 
230
                    "ignore stuff here=foobar", ?CRLF ++
 
231
                    "some-footer:some-value", ?CRLF, ?CRLF],
 
232
      
 
233
     {Module, Function, Args} = 
 
234
        http_chunk:decode(list_to_binary(hd(ChunkedBody2)),
 
235
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
236
    
 
237
     {_, NewBody} = parse(Module, Function, Args, tl(ChunkedBody2)),
 
238
     "abcdefghijklmnopqrstuvwxyz1234567890abcdef" = binary_to_list(NewBody),
 
239
   
 
240
    ChunkedBody3 = ["1a", ?CRLF ++ 
 
241
                    "abcdefghijklmnopqrstuvwxyz", ?CRLF ++ "10"  ++  ?CRLF
 
242
                    ++ "1234567890abcdef" ++  ?CRLF ++ "0" ++ ?CRLF 
 
243
                    ++ "some-footer:some-value", [?CR], [?LF] , ?CRLF],
 
244
    
 
245
     {Module1, Function1, Args1} = 
 
246
        http_chunk:decode(list_to_binary(hd(ChunkedBody3)),
 
247
                          ?HTTP_MAX_BODY_SIZE, ?HTTP_MAX_HEADER_SIZE),
 
248
    
 
249
     {_, NewBody} = parse(Module1, Function1, Args1, tl(ChunkedBody3)),
 
250
     "abcdefghijklmnopqrstuvwxyz1234567890abcdef" = binary_to_list(NewBody),
 
251
    
 
252
    ok.
 
253
 
 
254
%%-------------------------------------------------------------------------
 
255
chunk_encode(doc) ->
 
256
    ["Test http_chunk:encode/1 & http_chunk:encode_last/0"];
 
257
chunk_encode(suite) ->
 
258
    [];
 
259
chunk_encode(Config) when is_list(Config) ->
 
260
    <<54, ?CR, ?LF, 102,111,111,98,97,114, ?CR, ?LF>> = 
 
261
        http_chunk:encode(list_to_binary("foobar")),
 
262
    ["6", ?CR, ?LF,"foobar", ?CR, ?LF] = http_chunk:encode("foobar"),
 
263
    <<$0, ?CR, ?LF, ?CR, ?LF >> = http_chunk:encode_last(),
 
264
    ok.
 
265
 
 
266
 
 
267
%%-------------------------------------------------------------------------
 
268
http_response(doc) ->
 
269
    ["Test httpc_response:parse*. This test case will simulate that the "
 
270
     "message will be recived a little at the time on a socket and the "
 
271
     "package may be broken up into smaller parts at arbitrary point."];
 
272
http_response(suite) ->
 
273
    [];
 
274
http_response(Config) when is_list(Config) ->
 
275
 
 
276
    HttpHead1 = ["HTTP", "/1.1 ", "20", "0 ", "ok", [?CR, ?LF], 
 
277
                 "content-length:83" ++ ?CRLF ++ "content", "-type:", 
 
278
                 "text/html" ++ ?CRLF ++  
 
279
                 "date:Thu, 28 Oct 2004 07:57:43 GMT" ++ 
 
280
                 [?CR], [?LF, ?CR, ?LF]], 
 
281
    {"HTTP/1.1",
 
282
     200,
 
283
     "ok",
 
284
     #http_response_h{'content-length' = "83",
 
285
                      'content-type' = "text/html",
 
286
                      date = "Thu, 28 Oct 2004 07:57:43 GMT"},
 
287
     <<>>} =
 
288
        parse(httpc_response, parse, [?HTTP_MAX_HEADER_SIZE, false],
 
289
              HttpHead1),
 
290
 
 
291
    HttpHead2 = ["HTTP/1.1 200", " ok", [?CR], [?LF] ++ 
 
292
                 "content-length:83" ++ ?CRLF ++ "content-type:", 
 
293
                 "text/html" ++ ?CRLF ++  
 
294
                 "date:" ++ "Thu, 28 Oct 2004 07:57:43 GMT" ++ 
 
295
                 ?CRLF, ?CRLF], 
 
296
    {"HTTP/1.1",
 
297
     200,
 
298
     "ok",
 
299
     #http_response_h{'content-length' = "83",
 
300
                      'content-type' = "text/html",
 
301
                      date = "Thu, 28 Oct 2004 07:57:43 GMT"},
 
302
     <<>>} =
 
303
        parse(httpc_response, parse, [?HTTP_MAX_HEADER_SIZE, false], 
 
304
              HttpHead2),
 
305
 
 
306
    HttpHead3 = ["HTTP/1.1 200 ", "ok", ?CRLF ++ 
 
307
                 "content-length:83" ++ ?CRLF ++ "content-type:", 
 
308
                 "text/html" ++ ?CRLF ++  
 
309
                 "date:" ++ "Thu, 28 Oct 2004 07:57:43 GMT" ++ 
 
310
                 [?CR, ?LF,?CR], [?LF]], 
 
311
    {"HTTP/1.1",
 
312
     200,
 
313
     "ok",
 
314
     #http_response_h{'content-length' = "83",
 
315
                      'content-type' = "text/html",
 
316
                      date = "Thu, 28 Oct 2004 07:57:43 GMT"},
 
317
     <<>>} =
 
318
        parse(httpc_response, parse, [?HTTP_MAX_HEADER_SIZE, false], 
 
319
              HttpHead3),
 
320
    
 
321
    HttpBody = ["<HTML>\n<HEAD>\n<TITLE> dummy </TITLE>\n</HEAD>\n<BODY>\n",
 
322
                "<H1>dummy</H1>\n</BODY>\n</HTML>\n"],
 
323
    
 
324
    NewBody = lists:flatten(HttpBody), 
 
325
    Length = length(NewBody),
 
326
    NewBody = 
 
327
        binary_to_list(parse
 
328
                       (httpc_response, whole_body, [<<>>,Length], 
 
329
                        HttpBody)),
 
330
 
 
331
    HttpBody1 = ["<HTML", ">\n<HEAD>", "\n<TITLE> dummy </TITLE>\n</HEAD>\n",
 
332
                 "<BODY>\n", "<H1>du", "mmy</H1>\n</BODY>\n</HTML>\n"],
 
333
 
 
334
    NewBody1 = lists:flatten(HttpBody1),
 
335
    Length1 = length(NewBody1),
 
336
    NewBody1 = binary_to_list(parse
 
337
                              (httpc_response, whole_body,
 
338
                               [<<>>,Length1], HttpBody1)),
 
339
    ok.
 
340
%%-------------------------------------------------------------------------
 
341
http_request(doc) ->
 
342
    ["Test httpd_request:parse* This test case will simulate that the " 
 
343
     "message will be recived a little at the time on a socket and the " 
 
344
     "package may be broken up into smaller parts at arbitrary point."];
 
345
http_request(suite) ->
 
346
    [];
 
347
http_request(Config) when is_list(Config) ->
 
348
 
 
349
    HttpHead = ["GE", "T ", "http://www.erlang", ".org ", "HTTP", 
 
350
                "/1.1" ++ ?CRLF ++ "host:", 
 
351
                "www.erlang.org" ++ [?CR], 
 
352
                [?LF] ++ "te: " ++ ?CRLF, ?CRLF], 
 
353
    {"GET",
 
354
     "http://www.erlang.org",
 
355
     "HTTP/1.1",
 
356
     {#http_request_h{host = "www.erlang.org", te = []},
 
357
      ["te: ","host:www.erlang.org"]}, <<>>} =
 
358
        parse(httpd_request, parse, [?HTTP_MAX_HEADER_SIZE], HttpHead),
 
359
 
 
360
    HttpHead1 = ["GET http://www.erlang.org HTTP/1.1" ++ 
 
361
                 [?CR], [?LF, ?CR, ?LF]],
 
362
    {"GET",
 
363
     "http://www.erlang.org",
 
364
     "HTTP/1.1",
 
365
     {#http_request_h{}, []}, <<>>} =
 
366
        parse(httpd_request, parse, [?HTTP_MAX_HEADER_SIZE], HttpHead1),
 
367
 
 
368
 
 
369
    HttpHead2 = ["GET http://www.erlang.org HTTP/1.1" ++ 
 
370
                 [?CR, ?LF, ?CR], [?LF]],
 
371
    {"GET",
 
372
     "http://www.erlang.org",
 
373
     "HTTP/1.1",
 
374
     {#http_request_h{}, []}, <<>>} =
 
375
        parse(httpd_request, parse, [?HTTP_MAX_HEADER_SIZE], HttpHead2),
 
376
 
 
377
    %% Note the following body is not related to the headers above
 
378
    HttpBody = ["<HTML>\n<HEAD>\n<TITLE> dummy </TITLE>\n</HEAD>\n<BODY>\n",
 
379
                "<H1>dummy</H1>\n</BODY>\n</HTML>\n"],
 
380
 
 
381
    NewBody = lists:flatten(HttpBody),
 
382
    Length = length(NewBody),
 
383
    NewBody = 
 
384
        binary_to_list(parse
 
385
                       (httpd_request, whole_body, [<<>>,Length], HttpBody)),
 
386
 
 
387
    HttpBody1 = ["<HTML", ">\n<HEAD>", "\n<TITLE> dummy </TITLE>\n</HEAD>\n",
 
388
                 "<BODY>\n", "<H1>du", "mmy</H1>\n</BODY>\n</HTML>\n"],
 
389
 
 
390
    NewBody1 = lists:flatten(HttpBody1), 
 
391
    Length1 = length(NewBody1),
 
392
    NewBody1 =  
 
393
        binary_to_list(parse
 
394
                       (httpd_request, whole_body, 
 
395
                        [<<>>, Length1], HttpBody1)),    
 
396
    ok.
 
397
%%-------------------------------------------------------------------------
 
398
validate_request_line(doc) ->
 
399
    ["Test httpd_request:validate/3. Makes sure you can not get past"
 
400
     " the server_root and that the request is recognized by the server"
 
401
     " and protcol version." ];
 
402
validate_request_line(suite) ->
 
403
    [];
 
404
validate_request_line(Config) when is_list(Config) ->
 
405
 
 
406
    %% HTTP/0.9 only has GET requests
 
407
    ok = 
 
408
        httpd_request:validate("GET", "http://www.erlang/org", "HTTP/0.9"),
 
409
    {error, {not_supported, 
 
410
             {"HEAD", "http://www.erlang/org", "HTTP/0.9"}}} =
 
411
        httpd_request:validate("HEAD", "http://www.erlang/org", "HTTP/0.9"),
 
412
    {error, {not_supported, 
 
413
             {"TRACE", "http://www.erlang/org", "HTTP/0.9"}}} =
 
414
        httpd_request:validate("TRACE", "http://www.erlang/org", "HTTP/0.9"),
 
415
    {error, {not_supported, 
 
416
             {"POST", "http://www.erlang/org", "HTTP/0.9"}}} =
 
417
        httpd_request:validate("POST", "http://www.erlang/org", "HTTP/0.9"),
 
418
 
 
419
    %% HTTP/1.* 
 
420
    ok = httpd_request:validate("HEAD", "http://www.erlang/org", 
 
421
                               "HTTP/1.1"),
 
422
    ok = httpd_request:validate("GET", "http://www.erlang/org", 
 
423
                               "HTTP/1.1"),  
 
424
    ok = httpd_request:validate("POST","http://www.erlang/org", 
 
425
                               "HTTP/1.1"),
 
426
    ok = httpd_request:validate("TRACE","http://www.erlang/org",
 
427
                               "HTTP/1.1"),
 
428
    {error, {not_supported, 
 
429
             {"FOOBAR", "http://www.erlang/org", "HTTP/1.1"}}} =
 
430
        httpd_request:validate("FOOBAR", "http://www.erlang/org", 
 
431
                               "HTTP/1.1"),
 
432
 
 
433
    %% Attempts to get outside of server_root directory by relative links 
 
434
    ForbiddenUri = "http://127.0.0.1:8888/../../../../../etc/passwd",
 
435
    {error, {bad_request, {forbidden, ForbiddenUri}}} = 
 
436
        httpd_request:validate("GET", ForbiddenUri, "HTTP/1.1"),
 
437
 
 
438
    ForbiddenUri2 = 
 
439
        "http://127.0.0.1:8888/././././././../../../../../etc/passwd",
 
440
    {error, {bad_request, {forbidden, ForbiddenUri2}}} = 
 
441
        httpd_request:validate("GET", ForbiddenUri2, "HTTP/1.1"),
 
442
 
 
443
    HexForbiddenUri = "http://127.0.0.1:8888/%2e%2e/%2e%2e/%2e%2e/" 
 
444
        "home/ingela/test.html",
 
445
    {error, {bad_request, {forbidden, HexForbiddenUri}}} = 
 
446
        httpd_request:validate("GET", HexForbiddenUri, "HTTP/1.1"),
 
447
 
 
448
    NewForbiddenUri = 
 
449
        "http://127.0.0.1:8888/foobar/../../../home/ingela/test.html",
 
450
    {error, {bad_request, {forbidden, NewForbiddenUri}}} = 
 
451
        httpd_request:validate("GET", NewForbiddenUri, "HTTP/1.1"),
 
452
 
 
453
    NewForbiddenUri1 = 
 
454
        "http://127.0.0.1:8888/../home/ingela/test.html",
 
455
    {error, {bad_request, {forbidden, NewForbiddenUri1}}} = 
 
456
        httpd_request:validate("GET", NewForbiddenUri1, "HTTP/1.1"),
 
457
 
 
458
    ok.
 
459
%%-------------------------------------------------------------------------
 
460
esi_parse_headers(doc) ->
 
461
    ["Test httpd_esi:*. All header values are received in the same"
 
462
     " erlang message."];
 
463
esi_parse_headers(suite) ->
 
464
    [];
 
465
esi_parse_headers(Config) when is_list(Config) ->
 
466
 
 
467
    ESIResult = "content-type:text/html\r\ndate:Thu, 28 Oct 2004 07:57:43 "
 
468
        "GMT\r\nstatus:200 OK\r\n\r\nFoobar",
 
469
    
 
470
    {"content-type:text/html\r\ndate:Thu, 28 Oct 2004 07:57:43 GMT\r\nst"
 
471
     "atus:200 OK\r\n" = Headers,
 
472
     "Foobar"} = httpd_esi:parse_headers(ESIResult),
 
473
    
 
474
    {ok,[{"date","Thu, 28 Oct 2004 07:57:43 GMT"},
 
475
         {"content-type","text/html"}], 200} = 
 
476
        httpd_esi:handle_headers(Headers),
 
477
    
 
478
    ESIResult2 = 
 
479
        "location:http://foo.bar.se\r\ndate:Thu, 28 Oct 2004 07:57:43 "
 
480
        "GMT\r\n\r\n",
 
481
    
 
482
    {"location:http://foo.bar.se\r\ndate:Thu, 28 Oct 2004 07:57:43 GMT\r\n" = 
 
483
     Headers2,[]}
 
484
        = httpd_esi:parse_headers(ESIResult2),
 
485
    
 
486
    {ok,[{"date","Thu, 28 Oct 2004 07:57:43 GMT"},
 
487
         {"location","http://foo.bar.se"}], 302} =
 
488
        httpd_esi:handle_headers(Headers2),
 
489
    
 
490
    {proceed,"/foo/bar.html"} = 
 
491
        httpd_esi:handle_headers("location:/foo/bar.html\r\n"),
 
492
    ok.
 
493
 
 
494
%%--------------------------------------------------------------------
 
495
cgi_parse_headers(doc) ->
 
496
    ["Test httpd_cgi:*. This test case will simulate that the "
 
497
     "message will be recived a little at the time on a socket and the "
 
498
     "package may be broken up into smaller parts at arbitrary point."];
 
499
cgi_parse_headers(suite) ->
 
500
    [];
 
501
cgi_parse_headers(Config) when is_list(Config) ->
 
502
 
 
503
    CGIResult = ["content-type:text", "/html\ndate:Thu, 28 Oct 2004 07:57:43 "
 
504
                 "GMT\nst", "atus:200 OK\n", "\nFoobar"],
 
505
 
 
506
    {Headers, Body} = 
 
507
        parse(httpd_cgi, parse_headers, [<<>>, [], []], CGIResult),
 
508
    
 
509
    "Foobar" = binary_to_list(Body),
 
510
 
 
511
    {ok,[{"content-type","text/html"},
 
512
         {"date","Thu, 28 Oct 2004 07:57:43 GMT"}], {200,"OK"}}  = 
 
513
        httpd_cgi:handle_headers(Headers),
 
514
 
 
515
    CGIResult2 = ["location:http://foo.bar.se\ndate:Thu, 28 Oct 2004"
 
516
                  " 07:57:43 GMT\n\n"],
 
517
    {Headers2,  _} = parse(httpd_cgi, parse_headers, 
 
518
                           [<<>>, [], []], CGIResult2),
 
519
 
 
520
    {ok,[{"location","http://foo.bar.se"},
 
521
         {"date","Thu, 28 Oct 2004 07:57:43 GMT"}], {302,"Redirect"}} =
 
522
        httpd_cgi:handle_headers(Headers2),
 
523
    
 
524
    {proceed,"/foo/bar.html"} = 
 
525
        httpd_cgi:handle_headers(["location:/foo/bar.html\n"]),
 
526
 
 
527
    CGIHTTPResult = ["Content-Type:text", "/html\n", "Connection:close\r\n",
 
528
                     "Content-Language:en\r\nAge:", "4711\r\n\r\n\nfoobar"],
 
529
 
 
530
    {Headers3,  _} = parse(httpd_cgi, parse_headers, 
 
531
                           [<<>>, [], []], CGIHTTPResult),
 
532
 
 
533
    {ok,[{"content-type","text/html"},
 
534
         {"connection","close"},
 
535
         {"content-language","en"},
 
536
         {"age","4711"}], {200,"ok"}}  = httpd_cgi:handle_headers(Headers3),
 
537
 
 
538
    ok.
 
539
    
 
540
%%-------------------------------------------------------------------------
 
541
is_absolut_uri(doc) ->
 
542
    ["Test http_request:is_absolut_uri/1."];
 
543
is_absolut_uri(suite) ->
 
544
    [];
 
545
is_absolut_uri(Config) when is_list(Config) ->
 
546
    true = http_request:is_absolut_uri("http://www.erlang.org"),
 
547
    true = http_request:is_absolut_uri("https://www.erlang.org"),
 
548
    false = http_request:is_absolut_uri("index.html").
 
549
 
 
550
 
 
551
%%-------------------------------------------------------------------------
 
552
convert_netscapecookie_date(doc) ->
 
553
    ["Test http_util:convert_netscapecookie_date/1."];
 
554
convert_netscapecookie_date(suite) ->
 
555
    [];
 
556
convert_netscapecookie_date(Config) when is_list(Config) ->
 
557
    {{2006,1,6},{8,59,38}} = 
 
558
        http_util:convert_netscapecookie_date("Mon, 06-Jan-2006 08:59:38 GMT"),
 
559
    {{2006,2, 7},{8,59,38}} = 
 
560
        http_util:convert_netscapecookie_date("Tue, 07-Feb-2006 08:59:38 GMT"),
 
561
    {{2006,3,8},{8,59,38}} = 
 
562
        http_util:convert_netscapecookie_date("Wdy, 08-Mar-2006 08:59:38 GMT"),
 
563
    {{2006,4,9},{8,59,38}} = 
 
564
        http_util:convert_netscapecookie_date("Thu, 09-Apr-2006 08:59:38 GMT"),
 
565
    {{2006,5,10},{8,59,38}} = 
 
566
        http_util:convert_netscapecookie_date("Fri, 10-May-2006 08:59:38 GMT"),
 
567
    {{2006,6,11},{8,59,38}} = 
 
568
        http_util:convert_netscapecookie_date("Sat, 11-Jun-2006 08:59:38 GMT"),
 
569
    {{2006,7,12},{8,59,38}} = 
 
570
        http_util:convert_netscapecookie_date("Sun, 12-Jul-2006 08:59:38 GMT"),
 
571
    {{2006,8,12},{8,59,38}} = 
 
572
        http_util:convert_netscapecookie_date("Sun, 12-Aug-2006 08:59:38 GMT"),
 
573
    {{2006,9,12},{8,59,38}} = 
 
574
        http_util:convert_netscapecookie_date("Sun, 12-Sep-2006 08:59:38 GMT"),
 
575
    {{2006,10,12},{8,59,38}} = 
 
576
        http_util:convert_netscapecookie_date("Sun, 12-Oct-2006 08:59:38 GMT"),
 
577
    {{2006,11,12},{8,59,38}} = 
 
578
        http_util:convert_netscapecookie_date("Sun, 12-Nov-2006 08:59:38 GMT"),
 
579
    {{2006,12,12},{8,59,38}} = 
 
580
        http_util:convert_netscapecookie_date("Sun, 12-Dec-2006 08:59:38 GMT"),
 
581
    {{2006,12,12},{8,59,38}} = 
 
582
        http_util:convert_netscapecookie_date("Sun 12-Dec-2006 08:59:38 GMT"),
 
583
    {{2006,12,12},{8,59,38}} = 
 
584
        http_util:convert_netscapecookie_date("Sun, 12-Dec-06 08:59:38 GMT"),
 
585
    {{2006,12,12},{8,59,38}} = 
 
586
        http_util:convert_netscapecookie_date("Sun 12-Dec-06 08:59:38 GMT"),
 
587
     ok.
 
588
 
 
589
%%--------------------------------------------------------------------
 
590
%%% Internal functions
 
591
%%--------------------------------------------------------------------
 
592
 
 
593
parse(Module, Function, Args, [Data | Rest]) ->
 
594
    case  Module:Function([list_to_binary(Data) | Args]) of
 
595
        {ok, Result} ->
 
596
            Result;
 
597
        {NewModule, NewFunction, NewArgs} ->
 
598
            parse(NewModule, NewFunction, NewArgs, Rest)
 
599
    end.
 
600
 
 
601
 
 
602