Skip to content

Commit 5906b28

Browse files
committed
Fixes for unit tests, moving start LDAP
These should correct some of the problems in the last CI workflow. I moved the LDAP and docker image into the continuous_integration folder so it matches tiled.
1 parent 967fcba commit 5906b28

8 files changed

Lines changed: 340 additions & 30 deletions

File tree

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
popd
4444
4545
# Start LDAP
46-
source start_LDAP.sh
46+
source continuous_integration/scripts/start_LDAP.sh
4747
4848
# These packages are installed in the base environment but may be older
4949
# versions. Explicitly upgrade them because they often create

bluesky_httpserver/_authentication.py

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,22 @@ async def _complete_device_code_authorization(
632632
<!DOCTYPE html>
633633
<html>
634634
<head><title>Error</title>
635-
<style>body {{ font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }}
636-
.error {{ background-color: #f8d7da; border: 1px solid #f5c6cb; padding: 15px; border-radius: 5px; color: #721c24; }}</style>
635+
<style>
636+
body {{ font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }}
637+
.error {{
638+
background-color: #f8d7da;
639+
border: 1px solid #f5c6cb;
640+
padding: 15px;
641+
border-radius: 5px;
642+
color: #721c24;
643+
}}
644+
</style>
637645
</head>
638646
<body>
639647
<h1>Authorization Failed</h1>
640-
<div class="error">Invalid user code. It may have been mistyped, or the pending request may have expired.</div>
648+
<div class="error">
649+
Invalid user code. It may have been mistyped, or the pending request may have expired.
650+
</div>
641651
<br/><a href="{action.rsplit('?', 1)[0]}?code={code}">Try again</a>
642652
</body>
643653
</html>
@@ -651,12 +661,23 @@ async def _complete_device_code_authorization(
651661
<!DOCTYPE html>
652662
<html>
653663
<head><title>Authentication Failed</title>
654-
<style>body {{ font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }}
655-
.error {{ background-color: #f8d7da; border: 1px solid #f5c6cb; padding: 15px; border-radius: 5px; color: #721c24; }}</style>
664+
<style>
665+
body {{ font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }}
666+
.error {{
667+
background-color: #f8d7da;
668+
border: 1px solid #f5c6cb;
669+
padding: 15px;
670+
border-radius: 5px;
671+
color: #721c24;
672+
}}
673+
</style>
656674
</head>
657675
<body>
658676
<h1>Authentication Failed</h1>
659-
<div class="error">User code was correct but authentication with the identity provider failed. Please contact the administrator.</div>
677+
<div class="error">
678+
User code was correct but authentication with the identity provider failed.
679+
Please contact the administrator.
680+
</div>
660681
</body>
661682
</html>
662683
"""
@@ -668,8 +689,16 @@ async def _complete_device_code_authorization(
668689
<!DOCTYPE html>
669690
<html>
670691
<head><title>Authorization Failed</title>
671-
<style>body {{ font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }}
672-
.error {{ background-color: #f8d7da; border: 1px solid #f5c6cb; padding: 15px; border-radius: 5px; color: #721c24; }}</style>
692+
<style>
693+
body {{ font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }}
694+
.error {{
695+
background-color: #f8d7da;
696+
border: 1px solid #f5c6cb;
697+
padding: 15px;
698+
border-radius: 5px;
699+
color: #721c24;
700+
}}
701+
</style>
673702
</head>
674703
<body>
675704
<h1>Authorization Failed</h1>
@@ -693,12 +722,23 @@ async def _complete_device_code_authorization(
693722
<!DOCTYPE html>
694723
<html>
695724
<head><title>Success</title>
696-
<style>body {{ font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }}
697-
.success {{ background-color: #d4edda; border: 1px solid #c3e6cb; padding: 15px; border-radius: 5px; color: #155724; }}</style>
725+
<style>
726+
body {{ font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }}
727+
.success {{
728+
background-color: #d4edda;
729+
border: 1px solid #c3e6cb;
730+
padding: 15px;
731+
border-radius: 5px;
732+
color: #155724;
733+
}}
734+
</style>
698735
</head>
699736
<body>
700737
<h1>Success!</h1>
701-
<div class="success">You have been authenticated. Return to your terminal application - within {DEVICE_CODE_POLLING_INTERVAL} seconds it should be successfully logged in.</div>
738+
<div class="success">
739+
You have been authenticated. Return to your terminal application -
740+
within {DEVICE_CODE_POLLING_INTERVAL} seconds it should be successfully logged in.
741+
</div>
702742
</body>
703743
</html>
704744
"""
@@ -738,8 +778,21 @@ async def device_code_form(
738778
h1 {{ color: #333; }}
739779
form {{ margin-top: 20px; }}
740780
label {{ display: block; margin-bottom: 10px; }}
741-
input[type="text"] {{ padding: 10px; font-size: 16px; width: 200px; text-transform: uppercase; }}
742-
input[type="submit"] {{ padding: 10px 20px; font-size: 16px; background-color: #007bff; color: white; border: none; cursor: pointer; margin-top: 10px; }}
781+
input[type="text"] {{
782+
padding: 10px;
783+
font-size: 16px;
784+
width: 200px;
785+
text-transform: uppercase;
786+
}}
787+
input[type="submit"] {{
788+
padding: 10px 20px;
789+
font-size: 16px;
790+
background-color: #007bff;
791+
color: white;
792+
border: none;
793+
cursor: pointer;
794+
margin-top: 10px;
795+
}}
743796
input[type="submit"]:hover {{ background-color: #0056b3; }}
744797
</style>
745798
</head>

bluesky_httpserver/tests/conftest.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@
1818
_user_group = "primary"
1919

2020

21+
def _wait_for_http_server_ready(*, timeout=10, request_prefix="/api"):
22+
"""Wait until HTTP server accepts connections and responds to /status."""
23+
t_stop = ttime.time() + timeout
24+
url = f"http://{SERVER_ADDRESS}:{SERVER_PORT}{request_prefix}/status"
25+
while ttime.time() < t_stop:
26+
try:
27+
response = requests.get(url, timeout=0.5)
28+
# Any HTTP response means the server is up (auth may still reject request).
29+
if response.status_code:
30+
return
31+
except requests.RequestException:
32+
pass
33+
ttime.sleep(0.1)
34+
raise TimeoutError(f"HTTP server is not ready after {timeout} s: {url}")
35+
36+
2137
@pytest.fixture(scope="module")
2238
def fastapi_server(xprocess):
2339
class Starter(ProcessStarter):
@@ -29,6 +45,7 @@ class Starter(ProcessStarter):
2945
# args = f"start-bluesky-httpserver --host={SERVER_ADDRESS} --port {SERVER_PORT}".split()
3046

3147
xprocess.ensure("fastapi_server", Starter)
48+
_wait_for_http_server_ready()
3249

3350
yield
3451

@@ -55,7 +72,7 @@ class Starter(ProcessStarter):
5572
args = f"uvicorn --host={http_server_host} --port {http_server_port} {bqss.__name__}:app".split()
5673

5774
xprocess.ensure("fastapi_server", Starter)
58-
ttime.sleep(1)
75+
_wait_for_http_server_ready()
5976

6077
yield start
6178

0 commit comments

Comments
 (0)