Add integration tests for auth on HTTP external dictionaries

This commit is contained in:
Guillaume Tassery 2019-09-26 12:27:22 +02:00
parent 53b10d5b60
commit 7c93ef1706
2 changed files with 24 additions and 0 deletions

View File

@ -331,6 +331,16 @@ class SourceHTTPBase(ExternalSource):
<http>
<url>{url}</url>
<format>TabSeparated</format>
<credentials>
<user>foo</user>
<password>bar</password>
</credentials>
<headers>
<header>
<name>api-key</name>
<value>secret</value>
</header>
</headers>
</http>
'''.format(url=url)

View File

@ -6,12 +6,26 @@ import ssl
import csv
# Decorator used to see if authentification works for external dictionary who use a HTTP source.
def check_auth(fn):
def wrapper(req):
auth_header = self.headers.get('Authorization', None)
api_key = self.headers.get('api-key', None)
if not auth_header or auth_header != 'Zm9vOmJhcg==' or not api_key or api_key != 'secret':
req.send_response(401)
else:
fn(req)
return wrapper
def start_server(server_address, data_path, schema, cert_path, address_family):
class TSVHTTPHandler(BaseHTTPRequestHandler):
@check_auth
def do_GET(self):
self.__send_headers()
self.__send_data()
@check_auth
def do_POST(self):
ids = self.__read_and_decode_post_ids()
print "ids=", ids