Commit d4613cc9 authored by Łukasz Nowak's avatar Łukasz Nowak

XXX simplify tests and rewrite to new backend

parent edd40a23
Pipeline #38532 failed with stage
in 0 seconds
...@@ -30,6 +30,8 @@ import os ...@@ -30,6 +30,8 @@ import os
from recurls import Recurls from recurls import Recurls
import http.client import http.client
import json import json
import io
import gzip
import multiprocessing import multiprocessing
import subprocess import subprocess
from unittest import skip from unittest import skip
...@@ -2521,16 +2523,6 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2521,16 +2523,6 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
def test_auth_to_backend(self): def test_auth_to_backend(self):
parameter_dict = self.assertSlaveBase('auth-to-backend') parameter_dict = self.assertSlaveBase('auth-to-backend')
path = 'test-path/deep/.././deeper'
backend_url = self.getSlaveParameterDictDict()['auth-to-backend']['url']
config_result = mimikra.config(
backend_url + path,
headers=setUpHeaders([
('X-Config-Timeout', '10')
])
)
self.assertEqual(config_result.status_code, http.client.CREATED)
self.startAuthenticatedServerProcess() self.startAuthenticatedServerProcess()
try: try:
# assert that you can't fetch nothing without key # assert that you can't fetch nothing without key
...@@ -2543,51 +2535,34 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2543,51 +2535,34 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
# (so it means that auth to backend worked) # (so it means that auth to backend worked)
result = fakeHTTPSResult( result = fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['domain'],
path, '/',
headers=setUpHeaders([
('Accept-Encoding', 'gzip'),
])
) )
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
result.certificate) result.certificate)
self.assertEqualResultJson(result, 'Path', '/test-path/deeper') # proof that proper backend was accessed
self.assertEqual(
'Auth Backend',
result.headers['X-Backend-Identification']
)
self.assertEqualResultJson(result, 'Path', '/')
try: try:
j = result.json() j = result.json()
except Exception: except Exception:
raise ValueError('JSON decode problem in:\n%s' % (result.text,)) raise ValueError('JSON decode problem in:\n%s' % (result.text,))
self.assertFalse('Content-Encoding' in result.headers)
self.assertRequestHeaders( self.assertRequestHeaders(
j['Incoming Headers'], parameter_dict['domain']) j['Incoming Headers'], parameter_dict['domain'])
self.assertEqual(
'secured=value;secure, nonsecured=value',
result.headers['Set-Cookie']
)
# proof that proper backend was accessed
self.assertEqual(
'Auth Backend',
result.headers['X-Backend-Identification']
)
finally: finally:
self.stopAuthenticatedServerProcess() self.stopAuthenticatedServerProcess()
def test_auth_to_backend_not_configured(self): def test_auth_to_backend_not_configured(self):
parameter_dict = self.assertSlaveBase('auth-to-backend-not-configured') parameter_dict = self.assertSlaveBase('auth-to-backend-not-configured')
path = 'test-path/deep/.././deeper'
backend_url = self.getSlaveParameterDictDict()[
'auth-to-backend-not-configured']['url']
config_result = mimikra.config(
backend_url + path,
headers=setUpHeaders([
('X-Config-Timeout', '10')
])
)
self.assertEqual(config_result.status_code, http.client.CREATED)
self.startAuthenticatedServerProcess() self.startAuthenticatedServerProcess()
try: try:
# assert that you can't fetch nothing without key # assert that you can't fetch nothing without key
...@@ -2600,10 +2575,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2600,10 +2575,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
# (so it means that auth to backend worked) # (so it means that auth to backend worked)
result = fakeHTTPSResult( result = fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['domain'],
path, '/',
headers=setUpHeaders([
('Accept-Encoding', 'gzip'),
])
) )
self.assertEqual( self.assertEqual(
...@@ -2623,10 +2595,6 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2623,10 +2595,6 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
result = fakeHTTPSResult( result = fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['domain'],
'test-path/deep/.././deeper', 'test-path/deep/.././deeper',
headers={
'Timeout': '10', # more than default backend-connect-timeout == 5
'Accept-Encoding': 'gzip',
}
) )
self.assertEqual( self.assertEqual(
...@@ -2643,11 +2611,6 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2643,11 +2611,6 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
self.assertFalse('Content-Encoding' in result.headers) self.assertFalse('Content-Encoding' in result.headers)
self.assertRequestHeaders(j['Incoming Headers'], parameter_dict['domain']) self.assertRequestHeaders(j['Incoming Headers'], parameter_dict['domain'])
self.assertEqual(
'secured=value;secure, nonsecured=value',
result.headers['Set-Cookie']
)
result_http = fakeHTTPResult( result_http = fakeHTTPResult(
parameter_dict['domain'], parameter_dict['domain'],
'test-path/deep/.././deeper') 'test-path/deep/.././deeper')
...@@ -2664,6 +2627,11 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2664,6 +2627,11 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
) )
def test_compressed_result(self): def test_compressed_result(self):
"""Fix the test
* configure with compressed data
* send them from the backend
* compare some checksum of compressed data
"""
parameter_dict = self.assertSlaveBase( parameter_dict = self.assertSlaveBase(
'Url', 'Url',
{ {
...@@ -2673,36 +2641,42 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2673,36 +2641,42 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
} }
) )
data = 'This is some compressed information'
out = io.BytesIO()
with gzip.GzipFile(fileobj=out, mode="wb", compresslevel=9) as f:
f.write(data.encode())
data_compressed = out.getvalue()
path = '/compressed'
config_result = mimikra.config(
self.backend_url.rstrip('/') + '?a=b&c=' + path,
data=data_compressed,
headers=setUpHeaders([
('X-Config-Reply-Header-Content-Encoding', 'gzip'),
('X-Config-Reply-Header-Content-Length', 'calculate'),
])
)
self.assertEqual(config_result.status_code, http.client.CREATED)
result_compressed = fakeHTTPSResult( result_compressed = fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['domain'],
'test-path/deep/.././deeper', path,
headers={ headers=setUpHeaders([
'Accept-Encoding': 'gzip', ('Accept-Encoding', 'gzip'),
'Compress': '1', ])
}
) )
self.assertEqual( self.assertEqual(
'gzip', 'gzip',
result_compressed.headers['Content-Encoding'] result_compressed.headers['Content-Encoding']
) )
# Assert that no tampering was done with the request
# (compression/decompression)
# Backend compresses with 0 level, so decompression/compression
# would change somthing
self.assertEqual( self.assertEqual(
result_compressed.headers['Content-Length'], len(data_compressed),
result_compressed.headers['Backend-Content-Length'] int(result_compressed.headers['Content-Length'])
) )
result_not_compressed = fakeHTTPSResult( self.assertEqual(
parameter_dict['domain'], data_compressed,
'test-path/deep/.././deeper', result_compressed.raw_bytes
headers={
'Accept-Encoding': 'gzip',
}
) )
self.assertFalse('Content-Encoding' in result_not_compressed.headers)
def test_no_content_type_alter(self): def test_no_content_type_alter(self):
parameter_dict = self.assertSlaveBase( parameter_dict = self.assertSlaveBase(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment