File: virtualhost.test

package info (click to toggle)
libapache2-mod-rivet 3.2.2-1
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 6,296 kB
  • sloc: xml: 8,554; tcl: 7,568; ansic: 7,094; sh: 5,017; makefile: 195; sql: 91; lisp: 78
file content (245 lines) | stat: -rw-r--r-- 7,758 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# virtualhost.test -- test virtual host setups.

# $Id$

set docroot1 [file join [pwd] docroot1]
set docroot2 [file join [pwd] docroot2]

set vhostconf {
    #NameVirtualHost 127.0.0.1
    <VirtualHost *>
        DocumentRoot $docroot1
        ServerName vhost1
    </VirtualHost>

    <VirtualHost *>
        DocumentRoot $docroot2
        ServerName vhost2
    </VirtualHost>
}

# Make sure virtual hosts work.

::tcltest::test vhost-1.1 {basic virtual host} {
    apachetest::start {} $vhostconf {
        set page1 [::http::geturl "${urlbase}basic1.rvt" -headers [list Host vhost1]]
        set page2 [::http::geturl "${urlbase}basic2.rvt" -headers [list Host vhost2]]
        set match1 [::http::data $page1]
        set match2 [::http::data $page2]
        ::http::cleanup $page1
        ::http::cleanup $page2
    }
    list [string match {Virtual Host1 Test*} $match1] \
	     [string match {Virtual Host2 Test*} $match2]
} {1 1}

# Try virtual hosts with and without a childinitscript.

::tcltest::test vhost-2.1 {virtual host w/ ChildInitScript} {
    set data {}
    apachetest::start {} {
        RivetServerConf SeparateVirtualInterps off
        RivetServerConf ChildInitScript "source [file join $docroot1 childinit.tcl]"
        #NameVirtualHost 127.0.0.1
        <VirtualHost *>
            DocumentRoot $docroot1
            ServerName vhost1
        </VirtualHost>

        <VirtualHost *>
            RivetServerConf ChildInitScript "source [file join $docroot2 childinit.tcl]"
            DocumentRoot $docroot2
            ServerName vhost2
        </VirtualHost>
    } {
        set page2 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
        set page1 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
        set data "[::http::data $page1][::http::data $page2]"
        ::http::cleanup $page1
        ::http::cleanup $page2
    }
#   puts ">>>$data<<<"
    regexp "::childinit1 exists.*::childinit2 exists" $data match
} 1

# Test out a ChildInitScript that is only in a vhost.

::tcltest::test vhost-2.2 {virtual host w/ ChildInitScript in vhost} {
    set data {}
    apachetest::start {} {
	#NameVirtualHost 127.0.0.1
	<VirtualHost *>
        DocumentRoot $docroot1
        ServerName vhost1
	</VirtualHost>

	<VirtualHost *>
        RivetServerConf ChildInitScript "source [file join $docroot2 childinit.tcl]"
        DocumentRoot $docroot2
        ServerName vhost2
	</VirtualHost>
    } {
        set page {}
        lappend page [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
        lappend page [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
        foreach p $page {
            lappend data [::http::data $p]
            ::http::cleanup $p
        }
    }
#   set data
    regexp "vhost2 hello world<br>\n::childinit2 exists<br>" $data match
} 1

# Test out a beforescript in a virtual host.

::tcltest::test vhost-3.1 {virtual host w/ BeforeScript} {
    set data {}
    apachetest::start {} {
	RivetServerConf BeforeScript "source [file join $docroot1 beforescript.tcl]"
	#NameVirtualHost 127.0.0.1
	<VirtualHost *>
	DocumentRoot $docroot1
	ServerName vhost1
	</VirtualHost>

	<VirtualHost *>
	RivetServerConf BeforeScript "source [file join $docroot2 beforescript.tcl]"
	DocumentRoot $docroot2
	ServerName vhost2
	</VirtualHost>
    } {
        set page1 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
        set page2 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
        set data1 [::http::data $page1]
        set data2 [::http::data $page2]
        ::http::cleanup $page1
        ::http::cleanup $page2
    }
    list [regexp "^beforescript2\nVirtual Host2 Test" $data1 match] \
	     [regexp "^beforescript1\nVirtual Host1 Test" $data2 match]
#    list $data1 $data2
} {1 1}


# Turn on separate interpreters per virtual host.

::tcltest::test vhost-4.1 {virtual host w/ separate interps} {
    set data {}
    apachetest::start {} {
        RivetServerConf SeparateVirtualInterps on
        #NameVirtualHost 127.0.0.1
        <VirtualHost *>
            RivetServerConf ChildInitScript "set ::childinit1 1"
            DocumentRoot $docroot1
            ServerName vhost1
        </VirtualHost>

        <VirtualHost *>
            RivetServerConf ChildInitScript "set ::childinit2 1"
            DocumentRoot $docroot2
            ServerName vhost2
        </VirtualHost>
    } {
        set page1 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
        set page2 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
        set data1 [::http::data $page1]
        set data2 [::http::data $page2]
        ::http::cleanup $page1
        ::http::cleanup $page2
    }
#   puts "--$data1--"
#   puts "--$data2--"
    list \
	[regexp "vhost2 hello world<br>\n::childinit2 exists<br>" $data1 match] \
	[regexp "vhost1 hello world<br>\n::childinit1 exists<br>" $data2 match]
#    list $data1 $data2
} {1 1}

# Run through a list of config options, the files they use and the
# regexps that match the results.

# Format: directive, file, 2 regexps to match
set configs {
    ChildInitScript childinit.tcl "vhost2 hello world<br>\n::childinit2 exists<br>\n::childinit1 exists<br>\n" \
                                  "vhost1 hello world<br>\n::childinit1 exists<br>\n::childinit2 exists<br>"
    BeforeScript beforescript.tcl "^beforescript2\nVirtual Host2 Test" "^beforescript1\nVirtual Host1 Test"
    AfterScript afterscript.tcl "afterscript2" "afterscript1"
}

set i 1
foreach {conf file re1 re2} $configs {
    ::tcltest::test vhost-5.$i [list vhost with $conf] {
	apachetest::start {} "
RivetServerConf SeparateVirtualInterps off
RivetServerConf $conf \"source [file join $docroot1 $file]\"
#NameVirtualHost 127.0.0.1
<VirtualHost *>
DocumentRoot $docroot1
ServerName vhost1
</VirtualHost>

<VirtualHost *>
RivetServerConf $conf \"source [file join $docroot2 $file]\"
DocumentRoot $docroot2
ServerName vhost2
</VirtualHost>
" {
	set page1 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
	set page2 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
	set data1 [::http::data $page1]
	set data2 [::http::data $page2]
	::http::cleanup $page1
	::http::cleanup $page2
}
#puts "--$re1--\n--$data1--"
#puts "--$re2--\n--$data2--"

list [regexp $re1 $data1 match] [regexp $re1 $data1 match]
#list $data1 $data2
    } {1 1}
}

set configs {
    ChildInitScript childinit.tcl "vhost2 hello world<br>\n::childinit2 exists<br>\n" "vhost1 hello world<br>\n::childinit1 exists<br>\n"
    BeforeScript beforescript.tcl "^beforescript2\nVirtual Host2 Test" "^beforescript1\nVirtual Host1 Test"
    AfterScript afterscript.tcl "afterscript2" "afterscript1"
}

# Now run through a similar list, using per vhost interps.

set i 1
foreach {conf file re1 re2} $configs {
    ::tcltest::test vhost-6.$i [list vhost with $conf and SeparateVirtualInterps] {
	apachetest::start {} "
RivetServerConf SeparateVirtualInterps on
RivetServerConf $conf \"source [file join $docroot1 $file]\"
#NameVirtualHost 127.0.0.1
<VirtualHost *>
DocumentRoot $docroot1
ServerName vhost1
</VirtualHost>

<VirtualHost *>
RivetServerConf $conf \"source [file join $docroot2 $file]\"
DocumentRoot $docroot2
ServerName vhost2
</VirtualHost>
" {
	set page1 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
	set page2 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
	set data1 [::http::data $page1]
	set data2 [::http::data $page2]
	::http::cleanup $page1
	::http::cleanup $page2
}
#puts "--$re1--\n--$data1--"
#puts "--$re2--\n--$data2--"

list [regexp $re1 $data1 match] [regexp $re1 $data1 match]
    } {1 1}

incr i
}