mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
133a9b7452
If the tests are run with specific ports assigned to specific services, set through the environment variables, we continue to use those ports. We just don't hard-code them now, we pick them up from the environment variables. However, if the environment variables are not set, we generate a random port for each service. This allows us to run multiple tests in parallel in the future, independently. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6218 GitOrigin-RevId: 3d2a1880bf67544c848951888ce7b4fa1ba379dc
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
"""
|
|
Sample auth webhook to receive a cookie and respond
|
|
"""
|
|
from http import HTTPStatus
|
|
|
|
from context import ThreadedHTTPServer
|
|
from webserver import MkHandlers, RequestHandler, Response
|
|
|
|
class CookieAuth(RequestHandler):
|
|
def get(self, request):
|
|
print('auth GET request')
|
|
headers = {k.lower(): v for k, v in request.headers.items()}
|
|
|
|
print(headers)
|
|
cookieHdrs = []
|
|
if 'cookie' in headers and headers['cookie']:
|
|
res = {'x-hasura-role': 'admin'}
|
|
|
|
for k, v in headers.items():
|
|
if 'response-set-cookie' in k:
|
|
hdr = ('Set-Cookie', v)
|
|
cookieHdrs.append(hdr)
|
|
|
|
print('auth response: OK')
|
|
return Response(HTTPStatus.OK, res, cookieHdrs)
|
|
print('auth response: Unauthorized')
|
|
return Response(HTTPStatus.UNAUTHORIZED)
|
|
|
|
def post(self, request):
|
|
print('auth POST request')
|
|
headers = {k.lower(): v for k, v in request.json['headers'].items()}
|
|
cookieHdrs = []
|
|
|
|
if 'cookie' in headers and headers['cookie']:
|
|
res = {'x-hasura-role': 'admin'}
|
|
|
|
for k, v in headers.items():
|
|
if 'response-set-cookie' in k:
|
|
hdr = ('Set-Cookie', v)
|
|
cookieHdrs.append(hdr)
|
|
|
|
print('auth response: OK')
|
|
return Response(HTTPStatus.OK, res, headers)
|
|
print('auth response: Unauthorized')
|
|
return Response(HTTPStatus.UNAUTHORIZED)
|
|
|
|
|
|
handlers = MkHandlers({
|
|
'/auth': CookieAuth,
|
|
})
|
|
|
|
def create_server(server_address):
|
|
return ThreadedHTTPServer(server_address, handlers)
|
|
|
|
def stop_server(server):
|
|
server.shutdown()
|
|
server.server_close()
|