Deleted
Added
test_access_log.py (1635:97afbb6c5a15) | test_access_log.py (1654:fc7d0578e124) |
---|---|
1import time 2 3import pytest 4 | 1import time 2 3import pytest 4 |
5from conftest import option 6from conftest import unit_stop |
|
5from unit.applications.lang.python import TestApplicationPython 6 7 8class TestAccessLog(TestApplicationPython): 9 prerequisites = {'modules': {'python': 'any'}} 10 11 def load(self, script): 12 super().load(script) 13 14 assert 'success' in self.conf( | 7from unit.applications.lang.python import TestApplicationPython 8 9 10class TestAccessLog(TestApplicationPython): 11 prerequisites = {'modules': {'python': 'any'}} 12 13 def load(self, script): 14 super().load(script) 15 16 assert 'success' in self.conf( |
15 '"' + self.temp_dir + '/access.log"', 'access_log' | 17 '"' + option.temp_dir + '/access.log"', 'access_log' |
16 ), 'access_log configure' 17 18 def wait_for_record(self, pattern, name='access.log'): 19 return super().wait_for_record(pattern, name) 20 21 def test_access_log_keepalive(self): 22 self.load('mirror') 23 --- 19 unchanged lines hidden (view full) --- 43 'Host': 'localhost', 44 'Connection': 'close', 45 'Content-Type': 'text/html', 46 }, 47 sock=sock, 48 body='0123456789', 49 ) 50 | 18 ), 'access_log configure' 19 20 def wait_for_record(self, pattern, name='access.log'): 21 return super().wait_for_record(pattern, name) 22 23 def test_access_log_keepalive(self): 24 self.load('mirror') 25 --- 19 unchanged lines hidden (view full) --- 45 'Host': 'localhost', 46 'Connection': 'close', 47 'Content-Type': 'text/html', 48 }, 49 sock=sock, 50 body='0123456789', 51 ) 52 |
51 self.stop() | 53 unit_stop() |
52 53 assert ( 54 self.wait_for_record(r'"POST / HTTP/1.1" 200 10') is not None 55 ), 'keepalive 2' 56 57 def test_access_log_pipeline(self): 58 self.load('empty') 59 --- 11 unchanged lines hidden (view full) --- 71Referer: Referer-3 72Connection: close 73 74""", 75 raw_resp=True, 76 raw=True, 77 ) 78 | 54 55 assert ( 56 self.wait_for_record(r'"POST / HTTP/1.1" 200 10') is not None 57 ), 'keepalive 2' 58 59 def test_access_log_pipeline(self): 60 self.load('empty') 61 --- 11 unchanged lines hidden (view full) --- 73Referer: Referer-3 74Connection: close 75 76""", 77 raw_resp=True, 78 raw=True, 79 ) 80 |
79 self.stop() | 81 unit_stop() |
80 81 assert ( 82 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-1" "-"') 83 is not None 84 ), 'pipeline 1' 85 assert ( 86 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-2" "-"') 87 is not None --- 5 unchanged lines hidden (view full) --- 93 94 def test_access_log_ipv6(self): 95 self.load('empty') 96 97 self.conf({"[::1]:7080": {"pass": "applications/empty"}}, 'listeners') 98 99 self.get(sock_type='ipv6') 100 | 82 83 assert ( 84 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-1" "-"') 85 is not None 86 ), 'pipeline 1' 87 assert ( 88 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "Referer-2" "-"') 89 is not None --- 5 unchanged lines hidden (view full) --- 95 96 def test_access_log_ipv6(self): 97 self.load('empty') 98 99 self.conf({"[::1]:7080": {"pass": "applications/empty"}}, 'listeners') 100 101 self.get(sock_type='ipv6') 102 |
101 self.stop() | 103 unit_stop() |
102 103 assert ( 104 self.wait_for_record( 105 r'::1 - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"' 106 ) 107 is not None 108 ), 'ipv6' 109 110 def test_access_log_unix(self): 111 self.load('empty') 112 | 104 105 assert ( 106 self.wait_for_record( 107 r'::1 - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"' 108 ) 109 is not None 110 ), 'ipv6' 111 112 def test_access_log_unix(self): 113 self.load('empty') 114 |
113 addr = self.temp_dir + '/sock' | 115 addr = option.temp_dir + '/sock' |
114 115 self.conf( 116 {"unix:" + addr: {"pass": "applications/empty"}}, 'listeners' 117 ) 118 119 self.get(sock_type='unix', addr=addr) 120 | 116 117 self.conf( 118 {"unix:" + addr: {"pass": "applications/empty"}}, 'listeners' 119 ) 120 121 self.get(sock_type='unix', addr=addr) 122 |
121 self.stop() | 123 unit_stop() |
122 123 assert ( 124 self.wait_for_record( 125 r'unix: - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"' 126 ) 127 is not None 128 ), 'unix' 129 130 def test_access_log_referer(self): 131 self.load('empty') 132 133 self.get( 134 headers={ 135 'Host': 'localhost', 136 'Referer': 'referer-value', 137 'Connection': 'close', 138 } 139 ) 140 | 124 125 assert ( 126 self.wait_for_record( 127 r'unix: - - \[.+\] "GET / HTTP/1.1" 200 0 "-" "-"' 128 ) 129 is not None 130 ), 'unix' 131 132 def test_access_log_referer(self): 133 self.load('empty') 134 135 self.get( 136 headers={ 137 'Host': 'localhost', 138 'Referer': 'referer-value', 139 'Connection': 'close', 140 } 141 ) 142 |
141 self.stop() | 143 unit_stop() |
142 143 assert ( 144 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "referer-value" "-"') 145 is not None 146 ), 'referer' 147 148 def test_access_log_user_agent(self): 149 self.load('empty') 150 151 self.get( 152 headers={ 153 'Host': 'localhost', 154 'User-Agent': 'user-agent-value', 155 'Connection': 'close', 156 } 157 ) 158 | 144 145 assert ( 146 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "referer-value" "-"') 147 is not None 148 ), 'referer' 149 150 def test_access_log_user_agent(self): 151 self.load('empty') 152 153 self.get( 154 headers={ 155 'Host': 'localhost', 156 'User-Agent': 'user-agent-value', 157 'Connection': 'close', 158 } 159 ) 160 |
159 self.stop() | 161 unit_stop() |
160 161 assert ( 162 self.wait_for_record( 163 r'"GET / HTTP/1.1" 200 0 "-" "user-agent-value"' 164 ) 165 is not None 166 ), 'user agent' 167 168 def test_access_log_http10(self): 169 self.load('empty') 170 171 self.get(http_10=True) 172 | 162 163 assert ( 164 self.wait_for_record( 165 r'"GET / HTTP/1.1" 200 0 "-" "user-agent-value"' 166 ) 167 is not None 168 ), 'user agent' 169 170 def test_access_log_http10(self): 171 self.load('empty') 172 173 self.get(http_10=True) 174 |
173 self.stop() | 175 unit_stop() |
174 175 assert ( 176 self.wait_for_record(r'"GET / HTTP/1.0" 200 0 "-" "-"') is not None 177 ), 'http 1.0' 178 179 def test_access_log_partial(self): 180 self.load('empty') 181 182 assert self.post()['status'] == 200, 'init' 183 184 resp = self.http(b"""GE""", raw=True, read_timeout=1) 185 186 time.sleep(1) 187 | 176 177 assert ( 178 self.wait_for_record(r'"GET / HTTP/1.0" 200 0 "-" "-"') is not None 179 ), 'http 1.0' 180 181 def test_access_log_partial(self): 182 self.load('empty') 183 184 assert self.post()['status'] == 200, 'init' 185 186 resp = self.http(b"""GE""", raw=True, read_timeout=1) 187 188 time.sleep(1) 189 |
188 self.stop() | 190 unit_stop() |
189 190 assert ( 191 self.wait_for_record(r'"GE" 400 0 "-" "-"') is not None 192 ), 'partial' 193 194 def test_access_log_partial_2(self): 195 self.load('empty') 196 197 assert self.post()['status'] == 200, 'init' 198 199 self.http(b"""GET /\n""", raw=True) 200 | 191 192 assert ( 193 self.wait_for_record(r'"GE" 400 0 "-" "-"') is not None 194 ), 'partial' 195 196 def test_access_log_partial_2(self): 197 self.load('empty') 198 199 assert self.post()['status'] == 200, 'init' 200 201 self.http(b"""GET /\n""", raw=True) 202 |
201 self.stop() | 203 unit_stop() |
202 203 assert ( 204 self.wait_for_record(r'"GET /" 400 \d+ "-" "-"') is not None 205 ), 'partial 2' 206 207 def test_access_log_partial_3(self): 208 self.load('empty') 209 210 assert self.post()['status'] == 200, 'init' 211 212 resp = self.http(b"""GET / HTTP/1.1""", raw=True, read_timeout=1) 213 214 time.sleep(1) 215 | 204 205 assert ( 206 self.wait_for_record(r'"GET /" 400 \d+ "-" "-"') is not None 207 ), 'partial 2' 208 209 def test_access_log_partial_3(self): 210 self.load('empty') 211 212 assert self.post()['status'] == 200, 'init' 213 214 resp = self.http(b"""GET / HTTP/1.1""", raw=True, read_timeout=1) 215 216 time.sleep(1) 217 |
216 self.stop() | 218 unit_stop() |
217 218 assert ( 219 self.wait_for_record(r'"GET /" 400 0 "-" "-"') is not None 220 ), 'partial 3' 221 222 def test_access_log_partial_4(self): 223 self.load('empty') 224 225 assert self.post()['status'] == 200, 'init' 226 227 resp = self.http(b"""GET / HTTP/1.1\n""", raw=True, read_timeout=1) 228 229 time.sleep(1) 230 | 219 220 assert ( 221 self.wait_for_record(r'"GET /" 400 0 "-" "-"') is not None 222 ), 'partial 3' 223 224 def test_access_log_partial_4(self): 225 self.load('empty') 226 227 assert self.post()['status'] == 200, 'init' 228 229 resp = self.http(b"""GET / HTTP/1.1\n""", raw=True, read_timeout=1) 230 231 time.sleep(1) 232 |
231 self.stop() | 233 unit_stop() |
232 233 assert ( 234 self.wait_for_record(r'"GET / HTTP/1.1" 400 0 "-" "-"') is not None 235 ), 'partial 4' 236 237 @pytest.mark.skip('not yet') 238 def test_access_log_partial_5(self): 239 self.load('empty') 240 241 assert self.post()['status'] == 200, 'init' 242 243 self.get(headers={'Connection': 'close'}) 244 | 234 235 assert ( 236 self.wait_for_record(r'"GET / HTTP/1.1" 400 0 "-" "-"') is not None 237 ), 'partial 4' 238 239 @pytest.mark.skip('not yet') 240 def test_access_log_partial_5(self): 241 self.load('empty') 242 243 assert self.post()['status'] == 200, 'init' 244 245 self.get(headers={'Connection': 'close'}) 246 |
245 self.stop() | 247 unit_stop() |
246 247 assert ( 248 self.wait_for_record(r'"GET / HTTP/1.1" 400 \d+ "-" "-"') 249 is not None 250 ), 'partial 5' 251 252 def test_access_log_get_parameters(self): 253 self.load('empty') 254 255 self.get(url='/?blah&var=val') 256 | 248 249 assert ( 250 self.wait_for_record(r'"GET / HTTP/1.1" 400 \d+ "-" "-"') 251 is not None 252 ), 'partial 5' 253 254 def test_access_log_get_parameters(self): 255 self.load('empty') 256 257 self.get(url='/?blah&var=val') 258 |
257 self.stop() | 259 unit_stop() |
258 259 assert ( 260 self.wait_for_record( 261 r'"GET /\?blah&var=val HTTP/1.1" 200 0 "-" "-"' 262 ) 263 is not None 264 ), 'get parameters' 265 266 def test_access_log_delete(self): 267 self.load('empty') 268 269 self.conf_delete('access_log') 270 271 self.get(url='/delete') 272 | 260 261 assert ( 262 self.wait_for_record( 263 r'"GET /\?blah&var=val HTTP/1.1" 200 0 "-" "-"' 264 ) 265 is not None 266 ), 'get parameters' 267 268 def test_access_log_delete(self): 269 self.load('empty') 270 271 self.conf_delete('access_log') 272 273 self.get(url='/delete') 274 |
273 self.stop() | 275 unit_stop() |
274 275 assert self.search_in_log(r'/delete', 'access.log') is None, 'delete' 276 | 276 277 assert self.search_in_log(r'/delete', 'access.log') is None, 'delete' 278 |
277 def test_access_log_change(self): | 279 def test_access_log_change(self, temp_dir): |
278 self.load('empty') 279 280 self.get() 281 | 280 self.load('empty') 281 282 self.get() 283 |
282 self.conf('"' + self.temp_dir + '/new.log"', 'access_log') | 284 self.conf('"' + option.temp_dir + '/new.log"', 'access_log') |
283 284 self.get() 285 | 285 286 self.get() 287 |
286 self.stop() | 288 unit_stop() |
287 288 assert ( 289 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log') 290 is not None 291 ), 'change' | 289 290 assert ( 291 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', 'new.log') 292 is not None 293 ), 'change' |