1# Copyright (C) 2018-2019  Dridi Boukelmoune
2# All rights reserved.
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17varnishtest "Sort unique parameters"
18
19server s1 "" -start
20
21varnish v1 -arg "-j none"
22varnish v1 -vcl+backend {
23	import querystring;
24
25	sub vcl_recv {
26		return (synth(200));
27	}
28
29	sub vcl_synth {
30		set resp.http.Sorted-URL = querystring.sort(req.url,
31		    uniq = true);
32	}
33} -start
34
35client c1 {
36	txreq -url "/?b&a&b"
37	rxresp
38	expect resp.http.Sorted-URL == "/?a&b"
39
40	txreq -url "/?a&b&b"
41	rxresp
42	expect resp.http.Sorted-URL == "/?a&b"
43
44	txreq -url "/?b&a&&b"
45	rxresp
46	expect resp.http.Sorted-URL == "/?a&b"
47
48	txreq -url "/?&b&a&b"
49	rxresp
50	expect resp.http.Sorted-URL == "/?a&b"
51
52	txreq -url "/?b&&a&b"
53	rxresp
54	expect resp.http.Sorted-URL == "/?a&b"
55
56	txreq -url "/?a&b&a&b"
57	rxresp
58	expect resp.http.Sorted-URL == "/?a&b"
59
60	txreq -url "/?b&a&ba&b"
61	rxresp
62	expect resp.http.Sorted-URL == "/?a&b&ba"
63} -run
64
65