Skip to content

Commit 0959858

Browse files
committed
Add moodle API tests
1 parent e88a635 commit 0959858

9 files changed

Lines changed: 752 additions & 0 deletions

moodle/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Moodle Security Tests
2+
3+
Security tests for the Adler Moodle plugins using [Hurl](https://hurl.dev/).
4+
5+
## Setup
6+
7+
1. Install Hurl following the [official installation guide](https://hurl.dev/docs/installation.html)
8+
2. Have the Adler Stack compose running and set up (see [Setup and Usage](../docs/setup.md)).
9+
The whole snapshot topic is not required as this project works without resetting.
10+
Nevertheless, it might still be useful to be able to reset the environment to the initial state.
11+
12+
## Project Structure
13+
14+
- **`setup_test_environment/setup.hurl`** - Creates test users (students s1/s2, managers m1/m2) and
15+
a test course c1 with m1 as author. Enrolls s1 to c1 and completes a learning element. All variables are
16+
documented at the start of the file.
17+
- **`tests/*.hurl`** - Individual test files
18+
- **`envrionments/*.env`** - Environment configuration files containing host URLs and admin credentials etc.
19+
20+
## Running Tests
21+
22+
Tests are run by piping the setup file and test file together. Run from within the `moodle` directory:
23+
24+
```bash
25+
cat setup_test_environment/setup.hurl tests/<testfile>.hurl | hurl --variables-file envrionments/<env file>.env
26+
```
27+
28+
example:
29+
30+
```bash
31+
cat setup_test_environment/setup.hurl tests/local_adler_get_element_ids_by_uuids.hurl | hurl --variables-file envrionments/env_localhost_adler_stack.env
32+
```
33+
34+
## Test Design
35+
36+
Tests are designed to run **without requiring a reset** between executions. Each test run:
37+
- Creates fresh test users and courses via the setup file
38+
- Only interacts with resources created in that specific test run
39+
- Never modifies or accesses existing system data
40+
41+
This ensures tests can run repeatedly and in parallel without slow resets. Note that this way test isolation is
42+
not perfect. For example a `drop database` would still break other tests.
43+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
host=http://localhost:5080
2+
admin_username=admin
3+
admin_password=pass
4+
manager_username=manager
5+
manager_password=Manager1234!1234
6+
student_username=student
7+
student_password=Student1234!1234
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
host=http://localhost:26875
2+
admin_username=admin
3+
admin_password=pass
4+
manager_username=integration_test_manager
5+
manager_password=Manager1234!1234
6+
student_username=integration_test_student
7+
student_password=Student1234!1234
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{
2+
"$type": "ATF",
3+
"fileVersion": "2.3.0",
4+
"amgVersion": "2.2.2",
5+
"author": "",
6+
"language": "de",
7+
"world": {
8+
"$type": "LearningWorld",
9+
"evaluationLink": "",
10+
"enrolmentKey": "",
11+
"worldName": "testwelt",
12+
"worldUUID": "95e16ff0-f85a-4f2f-90ad-e16dd0cea8df",
13+
"worldDescription": "",
14+
"worldGoals": [
15+
""
16+
],
17+
"topics": [],
18+
"spaces": [
19+
{
20+
"$type": "LearningSpace",
21+
"spaceGoals": [],
22+
"spaceStory": {
23+
"$type": "SimpleSpaceStory",
24+
"introStory": null,
25+
"outroStory": null
26+
},
27+
"spaceName": "testraum",
28+
"requiredPointsToComplete": 2,
29+
"spaceId": 1,
30+
"spaceUUID": "8fada1da-f4d7-48f9-aae7-9edca49c65ea",
31+
"spaceDescription": "",
32+
"spaceSlotContents": [
33+
1,
34+
null,
35+
null,
36+
null,
37+
2,
38+
null
39+
],
40+
"requiredSpacesToEnter": "",
41+
"spaceTemplate": "R_20X20_6L",
42+
"spaceTemplateStyle": "CampusAschaffenburg"
43+
},
44+
{
45+
"$type": "LearningSpace",
46+
"spaceGoals": [],
47+
"spaceStory": {
48+
"$type": "SimpleSpaceStory",
49+
"introStory": null,
50+
"outroStory": null
51+
},
52+
"spaceName": "testraum2",
53+
"requiredPointsToComplete": 1,
54+
"spaceId": 2,
55+
"spaceUUID": "53b441bd-db01-4e81-9244-1739157c31cf",
56+
"spaceDescription": "",
57+
"spaceSlotContents": [
58+
3,
59+
null,
60+
null,
61+
null,
62+
null,
63+
null
64+
],
65+
"requiredSpacesToEnter": "1",
66+
"spaceTemplate": "R_20X20_6L",
67+
"spaceTemplateStyle": "CampusAschaffenburg"
68+
}
69+
],
70+
"elements": [
71+
{
72+
"$type": "LearningElement",
73+
"elementDescription": "",
74+
"elementGoals": [
75+
""
76+
],
77+
"elementMaxScore": 1,
78+
"elementModel": "l_random",
79+
"learningSpaceParentId": 1,
80+
"url": "",
81+
"elementId": 1,
82+
"elementUUID": "f734f354-6b0a-4102-a19d-57ab6f151146",
83+
"elementName": "test_LE",
84+
"elementCategory": "text",
85+
"elementFileType": "txt"
86+
},
87+
{
88+
"$type": "AdaptivityElement",
89+
"elementId": 2,
90+
"elementUUID": "b228a001-d5a6-4298-9321-56270b476465",
91+
"elementName": "adaptivitaet",
92+
"elementDescription": "",
93+
"elementGoals": [
94+
""
95+
],
96+
"elementCategory": "adaptivity",
97+
"elementFileType": "adaptivity",
98+
"elementMaxScore": 1,
99+
"elementModel": "a_npc_alerobot",
100+
"learningSpaceParentId": 1,
101+
"adaptivityContent": {
102+
"$type": "adaptivityContent",
103+
"introText": "",
104+
"adaptivityTasks": [
105+
{
106+
"$type": "adaptivityTask",
107+
"taskId": 1,
108+
"taskUUID": "c1e3bad9-db13-45e8-9d6d-3059263b29a2",
109+
"taskTitle": "Neue Aufgabe 1",
110+
"optional": false,
111+
"requiredDifficulty": 100,
112+
"adaptivityQuestions": [
113+
{
114+
"$type": "adaptivityQuestion",
115+
"questionType": "singleResponse",
116+
"questionId": 1,
117+
"questionUUID": "ac525937-0dd3-45a6-9e31-7e64936db61d",
118+
"questionDifficulty": 100,
119+
"questionText": "frage",
120+
"adaptivityRules": [],
121+
"choices": [
122+
{
123+
"$type": "AdaptivityQuestionAnswer",
124+
"answerText": "richtig",
125+
"isCorrect": true
126+
},
127+
{
128+
"$type": "AdaptivityQuestionAnswer",
129+
"answerText": "falsch",
130+
"isCorrect": false
131+
}
132+
]
133+
}
134+
]
135+
}
136+
]
137+
}
138+
},
139+
{
140+
"$type": "LearningElement",
141+
"elementDescription": "",
142+
"elementGoals": [
143+
""
144+
],
145+
"elementMaxScore": 1,
146+
"elementModel": "l_random",
147+
"learningSpaceParentId": 2,
148+
"url": "",
149+
"elementId": 3,
150+
"elementUUID": "df84cdb5-6d2e-47d6-b18b-6cffbea3b727",
151+
"elementName": "testElement",
152+
"elementCategory": "text",
153+
"elementFileType": "txt"
154+
}
155+
]
156+
}
157+
}
7.43 KB
Binary file not shown.

0 commit comments

Comments
 (0)