diff --git a/src/static/xapi_statement.schema.json b/src/static/xapi_statement.schema.json index e2a369185b5bb6b568faf3dee1d530effdf5dfcc..72577fd22d2ea8f16a00719665556d252c2357b5 100644 --- a/src/static/xapi_statement.schema.json +++ b/src/static/xapi_statement.schema.json @@ -36,7 +36,7 @@ }, "required": ["actor", "verb", "object"], "$defs": { - "iri": { "type": "string", "pattern": "^[a-zA-Z0-9_]+:" }, + "iri": { "type": "string", "pattern": "^[a-zA-Z0-9_]+" }, "languageMap": { "type": "object" }, "agent": { "type": "object", @@ -111,7 +111,7 @@ }, "required": ["id"] }, - "mbox": { "type": "string", "pattern": "mailto:[a-z0-9._%+!$&*=^|~#%{}/-]+@([a-z0-9-]+.){1,}([a-z]{2,22})" }, + "mbox": { "type": "string", "pattern": "(mailto:[a-z0-9._%+!$&*=^|~#%{}/-]+@([a-z0-9-]+.){1,}([a-z]{2,22}))|(system:[0-9]+)" }, "mbox_sha1sum": { "type": "string", "pattern": "^\b[0-9a-f]{5,40}$" }, "account": { "type": "object", diff --git a/src/xapi/tests/test_xapi_statement_validation.py b/src/xapi/tests/test_xapi_statement_validation.py index ad8c8f265f615eb947e6b857d558d01e75073a0e..a1079271ac153d999eb8e6e9b434c4dbf53d9f8f 100644 --- a/src/xapi/tests/test_xapi_statement_validation.py +++ b/src/xapi/tests/test_xapi_statement_validation.py @@ -7,7 +7,7 @@ from jsonschema import ValidationError, validate PROJECT_PATH = os.path.abspath(os.path.dirname(__name__)) -class TestxAPIStatementeValidation(TestCase): +class TestxAPIStatementValidation(TestCase): def setUp(self): with open(os.path.join(PROJECT_PATH, "static/xapi_statement.schema.json")) as f: self.schema = json.load(f) @@ -167,3 +167,24 @@ class TestxAPIStatementeValidation(TestCase): validate(statement, self.schema) except ValueError: assert False + + def test_validate_statement_with_tan(self): + statement = { + "actor": { + "objectType": "Agent", + "tan": "u4gueb983fnklerg", + }, + "verb": { + "id": "http://adlnet.gov/expapi/verbs/failed", + "display": {"en-US": "failed"}, + }, + "object": { + "id": "https://example.adlnet.gov/AUidentifier", + "objectType": "Activity", + }, + } + + try: + validate(statement, self.schema) + except ValueError: + assert False \ No newline at end of file diff --git a/src/xapi/tests/tests.py b/src/xapi/tests/tests.py index 4467c61f5627b96c6fad2bd447ec25ee79594841..5e764908923f95d9cd69d0993fa4a5c1325ccc93 100644 --- a/src/xapi/tests/tests.py +++ b/src/xapi/tests/tests.py @@ -197,9 +197,13 @@ class XAPITestCase(TestCase): "actor": {"mbox": f"system:{provider.id}"}, "verb": {"id": "some_id"}, "object": { - "id": "some_other_id", + "id": "someOtherId", "objectType": "Activity", - "definition": "object_definition", + "definition": { + "name": { + "de-DE": "Testobjekt" + } + }, }, "timestamp": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"), }, @@ -506,7 +510,7 @@ class TestxAPIStatementActorAccount(BaseTestCase): { "valid": False, "accepted": False, - "reason": "User missing in statement", + "reason": "'name' is a required property", } ], }, diff --git a/src/xapi/views.py b/src/xapi/views.py index 4af3b782062a9b77b3e71a87599925342ff3a361..31a7f138295c3d236e5f7bf67e485678102994d2 100644 --- a/src/xapi/views.py +++ b/src/xapi/views.py @@ -52,7 +52,7 @@ def process_statement(x_api_statement, provider, latest_schema): Process xAPI statement by checking for validation errors and user consent settings. """ try: - validate(x_api_statement, x_api_statement) + validate(x_api_statement, schema) except ValidationError as e: return {"valid": False, "accepted": False, "reason": e.message} @@ -164,7 +164,7 @@ def process_tan_statement(x_api_statement): Process xAPI statement by checking for validation errors. """ try: - validate(x_api_statement, x_api_statement) + validate(x_api_statement, schema) except ValidationError as e: return {"valid": False, "reason": e.message}