Skip to content

Commit bd5ed2d

Browse files
committed
Add system test changes
1 parent d519360 commit bd5ed2d

4 files changed

Lines changed: 179 additions & 27 deletions

File tree

‎tests/system_tests/compose.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ services:
4242
ports:
4343
- 8081:8080
4444
healthcheck:
45-
test: /opt/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin --password admin
45+
test: /opt/keycloak/bin/kcadm.sh config credentials --server http://keycloak:8080 --realm master --user admin --password admin
4646
interval: 5s
4747
timeout: 5s
4848
retries: 10
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"clientId": "ixx-blueapi",
3+
"name": "ixx-blueapi",
4+
"description": "Service account client used to run automated system tests for Blueapi.",
5+
"rootUrl": "",
6+
"adminUrl": "",
7+
"baseUrl": "",
8+
"surrogateAuthRequired": false,
9+
"enabled": true,
10+
"alwaysDisplayInConsole": false,
11+
"clientAuthenticatorType": "client-secret",
12+
"secret": "secret",
13+
"redirectUris": [
14+
"/*"
15+
],
16+
"webOrigins": [
17+
"/*"
18+
],
19+
"notBefore": 0,
20+
"bearerOnly": false,
21+
"consentRequired": false,
22+
"standardFlowEnabled": false,
23+
"implicitFlowEnabled": false,
24+
"directAccessGrantsEnabled": false,
25+
"serviceAccountsEnabled": true,
26+
"publicClient": false,
27+
"frontchannelLogout": true,
28+
"protocol": "openid-connect",
29+
"attributes": {
30+
"realm_client": "false",
31+
"oidc.ciba.grant.enabled": "false",
32+
"client.secret.creation.time": "1748358661",
33+
"backchannel.logout.session.required": "true",
34+
"standard.token.exchange.enabled": "false",
35+
"oauth2.device.authorization.grant.enabled": "false",
36+
"display.on.consent.screen": "false",
37+
"backchannel.logout.revoke.offline.tokens": "false",
38+
"dpop.bound.access.tokens": "false",
39+
"pkce.code.challenge.method": "",
40+
"login_theme": "",
41+
"consent.screen.text": "",
42+
"frontchannel.logout.url": "",
43+
"frontchannel.logout.session.required": "true"
44+
},
45+
"authenticationFlowBindingOverrides": {},
46+
"fullScopeAllowed": true,
47+
"nodeReRegistrationTimeout": -1,
48+
"protocolMappers": [
49+
{
50+
"name": "alice",
51+
"protocol": "openid-connect",
52+
"protocolMapper": "oidc-hardcoded-claim-mapper",
53+
"consentRequired": false,
54+
"config": {
55+
"introspection.token.claim": "true",
56+
"claim.value": "alice",
57+
"userinfo.token.claim": "true",
58+
"id.token.claim": "true",
59+
"lightweight.claim": "false",
60+
"access.token.claim": "true",
61+
"claim.name": "fedid",
62+
"jsonType.label": "String",
63+
"access.tokenResponse.claim": "false"
64+
}
65+
},
66+
{
67+
"name": "Client Host",
68+
"protocol": "openid-connect",
69+
"protocolMapper": "oidc-usersessionmodel-note-mapper",
70+
"consentRequired": false,
71+
"config": {
72+
"user.session.note": "clientHost",
73+
"introspection.token.claim": "true",
74+
"userinfo.token.claim": "true",
75+
"id.token.claim": "true",
76+
"access.token.claim": "true",
77+
"claim.name": "clientHost",
78+
"jsonType.label": "String"
79+
}
80+
},
81+
{
82+
"name": "Client ID",
83+
"protocol": "openid-connect",
84+
"protocolMapper": "oidc-usersessionmodel-note-mapper",
85+
"consentRequired": false,
86+
"config": {
87+
"user.session.note": "client_id",
88+
"introspection.token.claim": "true",
89+
"userinfo.token.claim": "true",
90+
"id.token.claim": "true",
91+
"access.token.claim": "true",
92+
"claim.name": "client_id",
93+
"jsonType.label": "String"
94+
}
95+
},
96+
{
97+
"name": "Client IP Address",
98+
"protocol": "openid-connect",
99+
"protocolMapper": "oidc-usersessionmodel-note-mapper",
100+
"consentRequired": false,
101+
"config": {
102+
"user.session.note": "clientAddress",
103+
"introspection.token.claim": "true",
104+
"userinfo.token.claim": "true",
105+
"id.token.claim": "true",
106+
"access.token.claim": "true",
107+
"claim.name": "clientAddress",
108+
"jsonType.label": "String"
109+
}
110+
},
111+
{
112+
"name": "blueapi",
113+
"protocol": "openid-connect",
114+
"protocolMapper": "oidc-audience-mapper",
115+
"consentRequired": false,
116+
"config": {
117+
"id.token.claim": "false",
118+
"lightweight.claim": "false",
119+
"introspection.token.claim": "true",
120+
"access.token.claim": "true",
121+
"included.custom.audience": "blueapi",
122+
"userinfo.token.claim": "false"
123+
}
124+
}
125+
],
126+
"defaultClientScopes": [
127+
"web-origins",
128+
"service_account",
129+
"acr",
130+
"profile",
131+
"roles",
132+
"basic",
133+
"email"
134+
],
135+
"optionalClientScopes": [
136+
"address",
137+
"phone",
138+
"organization",
139+
"offline_access",
140+
"microprofile-jwt"
141+
],
142+
"access": {
143+
"view": true,
144+
"configure": true,
145+
"manage": true
146+
},
147+
"authorizationServicesEnabled": false
148+
}

‎tests/system_tests/services/keycloak_config/startup.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ for i in $allowed_protocol_mappers $allowed_client_scopes;do
1919
done
2020

2121
kcreg.sh config credentials --server http://localhost:8080 --realm master --user admin --password admin
22-
kcreg.sh get "blueapi-ci" >/dev/null 2>&1 || kcreg.sh create --file "/mnt/blueapi-ci.json"
22+
client="ixx-blueapi"
23+
kcreg.sh get $client >/dev/null 2>&1 || kcreg.sh create --file "/mnt/$client.json"

‎tests/system_tests/test_blueapi_system.py‎

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from asyncio import Queue
44
from collections.abc import Generator
55
from pathlib import Path
6-
from unittest import mock
7-
from unittest.mock import patch
6+
from unittest.mock import MagicMock, patch
87

98
import pytest
109
import requests
@@ -18,7 +17,7 @@
1817
BlueskyRemoteControlError,
1918
)
2019
from blueapi.client.event_bus import AnyEvent
21-
from blueapi.client.rest import UnknownPlanError
20+
from blueapi.client.rest import BlueskyRequestError
2221
from blueapi.config import (
2322
ApplicationConfig,
2423
ConfigLoader,
@@ -79,34 +78,20 @@
7978
# docker compose -f tests/system_tests/compose.yaml down
8079

8180
# This client will give tokens for alice
82-
CLIENT_ID = "blueapi-ci"
81+
CLIENT_ID = "ixx-blueapi"
8382
CLIENT_SECRET = "secret"
8483
OIDC_TOKEN_ENDPOINT = (
8584
"http://localhost:8081/realms/master/protocol/openid-connect/token"
8685
)
8786

8887

8988
@pytest.fixture
90-
def client_without_auth(tmp_path: Path) -> BlueapiClient:
91-
return BlueapiClient.from_config(config=ApplicationConfig(auth_token_path=tmp_path))
92-
93-
94-
@pytest.fixture
95-
def client_with_stomp() -> Generator[BlueapiClient]:
96-
mock_session_manager = mock.MagicMock
97-
mock_session_manager.get_valid_access_token = get_access_token
89+
def client_without_auth() -> Generator[BlueapiClient]:
9890
with patch(
9991
"blueapi.service.authentication.SessionManager.from_cache",
100-
return_value=mock.MagicMock,
92+
return_value=None,
10193
):
102-
yield BlueapiClient.from_config(
103-
config=ApplicationConfig(
104-
stomp=StompConfig(
105-
enabled=True,
106-
auth=BasicAuthentication(username="guest", password="guest"), # type: ignore
107-
)
108-
)
109-
)
94+
yield BlueapiClient.from_config(config=ApplicationConfig())
11095

11196

11297
def get_access_token() -> str:
@@ -123,9 +108,27 @@ def get_access_token() -> str:
123108
return response.json().get("access_token")
124109

125110

111+
@pytest.fixture
112+
def client_with_stomp() -> Generator[BlueapiClient]:
113+
mock_session_manager = MagicMock
114+
mock_session_manager.get_valid_access_token = get_access_token
115+
with patch(
116+
"blueapi.service.authentication.SessionManager.from_cache",
117+
return_value=mock_session_manager,
118+
):
119+
yield BlueapiClient.from_config(
120+
config=ApplicationConfig(
121+
stomp=StompConfig(
122+
enabled=True,
123+
auth=BasicAuthentication(username="guest", password="guest"), # type: ignore
124+
)
125+
)
126+
)
127+
128+
126129
@pytest.fixture(scope="module")
127130
def client() -> Generator[BlueapiClient]:
128-
mock_session_manager = mock.MagicMock
131+
mock_session_manager = MagicMock
129132
mock_session_manager.get_valid_access_token = get_access_token
130133
with patch(
131134
"blueapi.service.authentication.SessionManager.from_cache",
@@ -211,14 +214,14 @@ def reset_numtracker(server_config: ApplicationConfig):
211214

212215

213216
def test_cannot_access_endpoints(
214-
client: BlueapiClient, blueapi_client_get_methods: list[str]
217+
client_without_auth: BlueapiClient, blueapi_client_get_methods: list[str]
215218
):
216219
blueapi_client_get_methods.remove(
217220
"get_oidc_config"
218221
) # get_oidc_config can be accessed without auth
219222
for get_method in blueapi_client_get_methods:
220223
with pytest.raises(BlueskyRemoteControlError, match=r"<Response \[401\]>"):
221-
getattr(client, get_method)()
224+
getattr(client_without_auth, get_method)()
222225

223226

224227
def test_can_get_oidc_config_without_auth(client_without_auth: BlueapiClient):
@@ -279,7 +282,7 @@ def test_instrument_session_propagated(client: BlueapiClient):
279282

280283

281284
def test_create_task_validation_error(client: BlueapiClient):
282-
with pytest.raises(UnknownPlanError):
285+
with pytest.raises(BlueskyRequestError, match="Internal Server Error"):
283286
client.create_task(
284287
TaskRequest(
285288
name="Not-exists",

0 commit comments

Comments
 (0)