Skip to content

Commit 4105db5

Browse files
committed
Implement comments
1 parent 321f13f commit 4105db5

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

monitoring/monitorlib/schema_validation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class F3411_22a(str, Enum):
5050

5151
class F3548_21(str, Enum):
5252
OpenAPIPath = "interfaces/astm-utm/Protocol/utm.yaml"
53+
ErrorResponse = "components.schemas.ErrorResponse"
5354
GetOperationalIntentDetailsResponse = (
5455
"components.schemas.GetOperationalIntentDetailsResponse"
5556
)

monitoring/uss_qualifier/resources/astm/f3548/v21/dss.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ def __init__(
446446
def can_use_scope(self, scope: str) -> bool:
447447
return scope in self._auth_adapter.scopes
448448

449+
def get_authorized_scopes(self) -> Set[str]:
450+
return self._auth_adapter.scopes.copy()
451+
449452
def get_instance(self, scopes_required: Dict[str, str]) -> DSSInstance:
450453
"""Get a client object ready to be used.
451454

monitoring/uss_qualifier/scenarios/astm/utm/dss/authentication/authentication_validation.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ for multiple scopes (so that a wrong scope may be used in place of the correct o
1717

1818
This scenario will check for the scope's availability and transparently ignore checks that can't be conducted.
1919

20-
The scopes the scenario is expected to be allowed to use are:
20+
Required scopes for minimal coverage:
2121

2222
- `utm.strategic_coordination`
23+
24+
Optional scopes that will allow the scenario to provide additional coverage:
25+
2326
- `utm.availability_arbitration`
2427
- `""` (empty string)
2528

monitoring/uss_qualifier/scenarios/astm/utm/dss/authentication/authentication_validation.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import random
12
from datetime import datetime, timedelta
23

34
from uas_standards.astm.f3548.v21.constants import (
@@ -28,10 +29,11 @@
2829

2930
class AuthenticationValidation(TestScenario):
3031
"""
31-
A scenario that verifies that the DSS properly authenticates requests to all its endpoints.
32+
A scenario that verifies that the DSS properly authenticates requests to all its endpoints,
33+
and properly validates the scopes of the requests depending on the action being performed.
3234
33-
This scenario does not (yet) cover anything related to authorization: this first version
34-
is intended to cover DSS0210,A2-7-2,7
35+
Note that this scenario does not verif that a DSS only allows an entity owner to modify the:
36+
this is covered in other scenarios.
3537
"""
3638

3739
SUB_TYPE = register_resource_type(
@@ -58,14 +60,18 @@ def __init__(
5860
"""
5961
super().__init__()
6062
scopes = {Scope.StrategicCoordination: "create and delete subscriptions"}
61-
# We use the AvailabilityArbitration scope as the 'wrong' scope for some tests
62-
# this checks if we are allowed to use it
63-
self._wrong_scope = None
64-
if dss.can_use_scope(Scope.AvailabilityArbitration):
63+
# For the 'wrong' scope we pick anything from the available scopes that isn't the SCD or empty scope:
64+
available_scopes = dss.get_authorized_scopes()
65+
available_scopes.remove(Scope.StrategicCoordination)
66+
available_scopes.remove("")
67+
68+
self._wrong_scope = (
69+
random.choice(list(available_scopes)) if available_scopes else None
70+
)
71+
if self._wrong_scope:
6572
scopes[
66-
Scope.AvailabilityArbitration
73+
self._wrong_scope
6774
] = "Attempt to query subscriptions with wrong scope"
68-
self._wrong_scope = Scope.AvailabilityArbitration
6975

7076
self._test_missing_scope = False
7177
if dss.can_use_scope(""):

monitoring/uss_qualifier/scenarios/astm/utm/dss/authentication/generic.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from uas_standards.astm.f3548.v21.constants import Scope
22

3-
from monitoring.monitorlib import fetch
3+
from monitoring.monitorlib import fetch, schema_validation
44
from monitoring.monitorlib.auth import InvalidTokenSignatureAuth
55
from monitoring.monitorlib.infrastructure import UTMClientSession
6+
from monitoring.monitorlib.schema_validation import F3548_21
67
from monitoring.uss_qualifier.resources.astm.f3548.v21.dss import DSSInstance
78
from monitoring.uss_qualifier.scenarios.scenario import TestScenario
89

@@ -39,7 +40,7 @@ def query_invalid_token(self, **query_kwargs) -> fetch.Query:
3940
"""
4041
q = fetch.query_and_describe(
4142
client=self._invalid_token_session,
42-
scope=Scope.StrategicCoordination,
43+
scope=self._valid_scope,
4344
**query_kwargs,
4445
)
4546
self._scenario.record_query(q)
@@ -80,22 +81,20 @@ def query_valid_auth(self, **query_kwargs) -> fetch.Query:
8081
return q
8182

8283
def verify_4xx_response(self, q: fetch.Query):
83-
"""Verifies that the passed query response's body is a valid ErrorResponse:
84-
it is either empty or contains a single 'message' field, as per the OpenAPI spec.
84+
"""Verifies that the passed query response's body is a valid ErrorResponse, as per the OpenAPI spec."""
8585

86-
Note that 409 responses to Operational Intent Reference mutations will contain more fields,
87-
these are not handled here.
88-
"""
8986
with self._scenario.check(
9087
"Unauthorized requests return the proper error message body"
9188
) as check:
92-
if len(q.response.json) == 0:
93-
return
94-
elif len(q.response.json) == 1 and "message" in q.response.json:
95-
return
96-
else:
89+
errors = schema_validation.validate(
90+
F3548_21.OpenAPIPath,
91+
F3548_21.ErrorResponse,
92+
q.response.json,
93+
)
94+
if errors:
9795
check.record_failed(
9896
summary="Unexpected error response body",
99-
details=f"Response body for {q.request.method} query to {q.request.url} should be empty or contain a single 'message' field. Was: {q.response.json}",
97+
details=f"Response body for {q.request.method} query to {q.request.url} failed validation: {errors}, "
98+
f"body content was: {q.response.json}",
10099
query_timestamps=[q.request.timestamp],
101100
)

0 commit comments

Comments
 (0)