test_tls.py (898:10333717f899) test_tls.py (970:2f4376c8f358)
1import re
2import ssl
3import time
4import subprocess
5import unittest
6import unit
7
8class TestUnitTLS(unit.TestUnitApplicationTLS):

--- 299 unchanged lines hidden (view full) ---

308
309 @unittest.expectedFailure
310 def test_tls_reconfigure(self):
311 self.load('empty')
312
313 self.certificate()
314
315 (resp, sock) = self.get(headers={
1import re
2import ssl
3import time
4import subprocess
5import unittest
6import unit
7
8class TestUnitTLS(unit.TestUnitApplicationTLS):

--- 299 unchanged lines hidden (view full) ---

308
309 @unittest.expectedFailure
310 def test_tls_reconfigure(self):
311 self.load('empty')
312
313 self.certificate()
314
315 (resp, sock) = self.get(headers={
316 'Connection': 'keep-alive',
317 'Host': 'localhost'
316 'Host': 'localhost',
317 'Connection': 'keep-alive'
318 }, start=True)
319
320 self.assertEqual(resp['status'], 200, 'initial status')
321
322 self.add_tls()
323
324 self.assertEqual(self.get(sock=sock)['status'], 200,
325 'reconfigure status')
326 self.assertEqual(self.get_ssl()['status'], 200,
327 'reconfigure tls status')
328
329 def test_tls_keepalive(self):
330 self.load('mirror')
331
332 self.certificate()
333
334 self.add_tls(application='mirror')
335
336 (resp, sock) = self.post_ssl(headers={
318 }, start=True)
319
320 self.assertEqual(resp['status'], 200, 'initial status')
321
322 self.add_tls()
323
324 self.assertEqual(self.get(sock=sock)['status'], 200,
325 'reconfigure status')
326 self.assertEqual(self.get_ssl()['status'], 200,
327 'reconfigure tls status')
328
329 def test_tls_keepalive(self):
330 self.load('mirror')
331
332 self.certificate()
333
334 self.add_tls(application='mirror')
335
336 (resp, sock) = self.post_ssl(headers={
337 'Host': 'localhost',
337 'Connection': 'keep-alive',
338 'Connection': 'keep-alive',
338 'Content-Type': 'text/html',
339 'Host': 'localhost'
339 'Content-Type': 'text/html'
340 }, start=True, body='0123456789')
341
342 self.assertEqual(resp['body'], '0123456789', 'keepalive 1')
343
344 resp = self.post_ssl(headers={
340 }, start=True, body='0123456789')
341
342 self.assertEqual(resp['body'], '0123456789', 'keepalive 1')
343
344 resp = self.post_ssl(headers={
345 'Host': 'localhost',
345 'Connection': 'close',
346 'Connection': 'close',
346 'Content-Type': 'text/html',
347 'Host': 'localhost'
347 'Content-Type': 'text/html'
348 }, sock=sock, body='0123456789')
349
350 self.assertEqual(resp['body'], '0123456789', 'keepalive 2')
351
352 @unittest.expectedFailure
353 def test_tls_keepalive_certificate_remove(self):
354 self.load('empty')
355
356 self.certificate()
357
358 self.add_tls()
359
360 (resp, sock) = self.get_ssl(headers={
348 }, sock=sock, body='0123456789')
349
350 self.assertEqual(resp['body'], '0123456789', 'keepalive 2')
351
352 @unittest.expectedFailure
353 def test_tls_keepalive_certificate_remove(self):
354 self.load('empty')
355
356 self.certificate()
357
358 self.add_tls()
359
360 (resp, sock) = self.get_ssl(headers={
361 'Connection': 'keep-alive',
362 'Host': 'localhost'
361 'Host': 'localhost',
362 'Connection': 'keep-alive'
363 }, start=True)
364
365 self.conf({
366 "application": "empty"
367 }, 'listeners/*:7080')
368 self.conf_delete('/certificates/default')
369
370 try:
371 resp = self.get_ssl(headers={
363 }, start=True)
364
365 self.conf({
366 "application": "empty"
367 }, 'listeners/*:7080')
368 self.conf_delete('/certificates/default')
369
370 try:
371 resp = self.get_ssl(headers={
372 'Connection': 'close',
373 'Host': 'localhost'
372 'Host': 'localhost',
373 'Connection': 'close'
374 }, sock=sock)
375 except:
376 resp = None
377
378 self.assertEqual(resp, None, 'keepalive remove certificate')
379
380 @unittest.expectedFailure
381 def test_tls_certificates_remove_all(self):

--- 10 unchanged lines hidden (view full) ---

392
393 self.certificate()
394
395 self.conf('1', 'applications/mirror/processes')
396
397 self.add_tls(application='mirror')
398
399 (resp, sock) = self.post_ssl(headers={
374 }, sock=sock)
375 except:
376 resp = None
377
378 self.assertEqual(resp, None, 'keepalive remove certificate')
379
380 @unittest.expectedFailure
381 def test_tls_certificates_remove_all(self):

--- 10 unchanged lines hidden (view full) ---

392
393 self.certificate()
394
395 self.conf('1', 'applications/mirror/processes')
396
397 self.add_tls(application='mirror')
398
399 (resp, sock) = self.post_ssl(headers={
400 'Host': 'localhost',
400 'Connection': 'keep-alive',
401 'Connection': 'keep-alive',
401 'Content-Type': 'text/html',
402 'Host': 'localhost'
402 'Content-Type': 'text/html'
403 }, start=True, body='0123456789')
404
405 app_id = self.findall(r'(\d+)#\d+ "mirror" application started')[0]
406
407 subprocess.call(['kill', '-9', app_id])
408
409 self.wait_for_record(re.compile(' (?!' + app_id +
410 '#)(\d+)#\d+ "mirror" application started'))
411
412 resp = self.post_ssl(headers={
403 }, start=True, body='0123456789')
404
405 app_id = self.findall(r'(\d+)#\d+ "mirror" application started')[0]
406
407 subprocess.call(['kill', '-9', app_id])
408
409 self.wait_for_record(re.compile(' (?!' + app_id +
410 '#)(\d+)#\d+ "mirror" application started'))
411
412 resp = self.post_ssl(headers={
413 'Host': 'localhost',
413 'Connection': 'close',
414 'Connection': 'close',
414 'Content-Type': 'text/html',
415 'Host': 'localhost'
415 'Content-Type': 'text/html'
416 }, sock=sock, body='0123456789')
417
418 self.assertEqual(resp['status'], 200, 'application respawn status')
419 self.assertEqual(resp['body'], '0123456789', 'application respawn body')
420
421if __name__ == '__main__':
422 TestUnitTLS.main()
416 }, sock=sock, body='0123456789')
417
418 self.assertEqual(resp['status'], 200, 'application respawn status')
419 self.assertEqual(resp['body'], '0123456789', 'application respawn body')
420
421if __name__ == '__main__':
422 TestUnitTLS.main()