@@ -70,9 +70,11 @@ def __init__(self, env: Env, proxy_auth: bool = False):
70
70
self ._logs_dir = os .path .join (self ._apache_dir , 'logs' )
71
71
self ._error_log = os .path .join (self ._logs_dir , 'error_log' )
72
72
self ._tmp_dir = os .path .join (self ._apache_dir , 'tmp' )
73
- self ._passwords = os .path .join (self ._conf_dir , 'passwords' )
73
+ self ._basic_passwords = os .path .join (self ._conf_dir , 'basic.passwords' )
74
+ self ._digest_passwords = os .path .join (self ._conf_dir , 'digest.passwords' )
74
75
self ._mods_dir = None
75
- self ._proxy_auth = proxy_auth
76
+ self ._auth_digest = True
77
+ self ._proxy_auth_basic = proxy_auth
76
78
self ._extra_configs = {}
77
79
assert env .apxs
78
80
p = subprocess .run (args = [env .apxs , '-q' , 'libexecdir' ],
@@ -108,7 +110,7 @@ def clear_extra_configs(self):
108
110
self ._extra_configs = {}
109
111
110
112
def set_proxy_auth (self , active : bool ):
111
- self ._proxy_auth = active
113
+ self ._proxy_auth_basic = active
112
114
113
115
def _run (self , args , intext = '' ):
114
116
env = {}
@@ -219,9 +221,15 @@ def _write_config(self):
219
221
'server' : f'{ domain2 } ' ,
220
222
}
221
223
fd .write (JSONEncoder ().encode (data ))
222
- if self ._proxy_auth :
223
- with open (self ._passwords , 'w' ) as fd :
224
+ if self ._proxy_auth_basic :
225
+ with open (self ._basic_passwords , 'w' ) as fd :
224
226
fd .write ('proxy:$apr1$FQfeInbs$WQZbODJlVg60j0ogEIlTW/\n ' )
227
+ if self ._auth_digest :
228
+ with open (self ._digest_passwords , 'w' ) as fd :
229
+ fd .write ('test:restricted area:57123e269fd73d71ae0656594e938e2f\n ' )
230
+ self ._mkpath (os .path .join (self .docs_dir , 'restricted/digest' ))
231
+ with open (os .path .join (self .docs_dir , 'restricted/digest/data.json' ), 'w' ) as fd :
232
+ fd .write ('{"area":"digest"}\n ' )
225
233
with open (self ._conf_file , 'w' ) as fd :
226
234
for m in self .MODULES :
227
235
if os .path .exists (os .path .join (self ._mods_dir , f'mod_{ m } .so' )):
@@ -252,7 +260,7 @@ def _write_config(self):
252
260
f' DocumentRoot "{ self ._docs_dir } "' ,
253
261
f' Protocols h2c http/1.1' ,
254
262
])
255
- conf .extend (self ._curltest_conf ())
263
+ conf .extend (self ._curltest_conf (domain1 ))
256
264
conf .extend ([
257
265
f'</VirtualHost>' ,
258
266
f'' ,
@@ -267,7 +275,7 @@ def _write_config(self):
267
275
f' SSLCertificateKeyFile { creds1 .pkey_file } ' ,
268
276
f' DocumentRoot "{ self ._docs_dir } "' ,
269
277
])
270
- conf .extend (self ._curltest_conf ())
278
+ conf .extend (self ._curltest_conf (domain1 ))
271
279
if domain1 in self ._extra_configs :
272
280
conf .extend (self ._extra_configs [domain1 ])
273
281
conf .extend ([
@@ -283,7 +291,7 @@ def _write_config(self):
283
291
f' SSLCertificateKeyFile { creds2 .pkey_file } ' ,
284
292
f' DocumentRoot "{ self ._docs_dir } /two"' ,
285
293
])
286
- conf .extend (self ._curltest_conf ())
294
+ conf .extend (self ._curltest_conf (domain2 ))
287
295
if domain2 in self ._extra_configs :
288
296
conf .extend (self ._extra_configs [domain2 ])
289
297
conf .extend ([
@@ -329,13 +337,13 @@ def _write_config(self):
329
337
]))
330
338
331
339
def _get_proxy_conf (self ):
332
- if self ._proxy_auth :
340
+ if self ._proxy_auth_basic :
333
341
return [
334
342
f' <Proxy "*">' ,
335
343
f' AuthType Basic' ,
336
344
f' AuthName "Restricted Proxy"' ,
337
345
f' AuthBasicProvider file' ,
338
- f' AuthUserFile "{ self ._passwords } "' ,
346
+ f' AuthUserFile "{ self ._basic_passwords } "' ,
339
347
f' Require user proxy' ,
340
348
f' </Proxy>' ,
341
349
]
@@ -355,9 +363,10 @@ def _get_log_level(self):
355
363
return 'debug'
356
364
return 'info'
357
365
358
- def _curltest_conf (self ) -> List [str ]:
366
+ def _curltest_conf (self , servername ) -> List [str ]:
367
+ lines = []
359
368
if Httpd .MOD_CURLTEST is not None :
360
- return [
369
+ lines . extend ( [
361
370
f' <Location /curltest/echo>' ,
362
371
f' SetHandler curltest-echo' ,
363
372
f' </Location>' ,
@@ -367,8 +376,20 @@ def _curltest_conf(self) -> List[str]:
367
376
f' <Location /curltest/tweak>' ,
368
377
f' SetHandler curltest-tweak' ,
369
378
f' </Location>' ,
370
- ]
371
- return []
379
+ ])
380
+ if self ._auth_digest :
381
+ lines .extend ([
382
+ f' <Directory { self .docs_dir } /restricted/digest>' ,
383
+ f' AuthType Digest' ,
384
+ f' AuthName "restricted area"' ,
385
+ f' AuthDigestDomain "https://{ servername } "' ,
386
+ f' AuthBasicProvider file' ,
387
+ f' AuthUserFile "{ self ._digest_passwords } "' ,
388
+ f' Require valid-user' ,
389
+ f' </Directory>' ,
390
+
391
+ ])
392
+ return lines
372
393
373
394
def _init_curltest (self ):
374
395
if Httpd .MOD_CURLTEST is not None :
0 commit comments