-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomScopeTest.java
171 lines (116 loc) · 5.77 KB
/
CustomScopeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package nl.contezza.drc.tests.custom;
import static io.restassured.RestAssured.given;
import org.json.JSONArray;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import nl.contezza.drc.rest.RestTest;
import nl.contezza.drc.service.AuthService;
import nl.contezza.drc.service.DRCRequestSpecification;
import nl.contezza.drc.service.EIOService;
import nl.contezza.drc.service.ZTCService;
/**
* Some custom unit tests which are not mapped to any python scripts.
*/
//@Log4j2
public class CustomScopeTest extends RestTest {
/**
* Create necessary dependencies.
*/
@BeforeTest(groups = "CustomScope")
public void init() {
// Create random catalogi
ZTCService ztcService = new ZTCService();
JsonPath json = new JsonPath(ztcService.createCatalogus().asString());
// Create informatieobjecttype
String catalogusUrl = json.getString("url").replace(ZTC_BASE_URI, ZTC_DOCKER_URI);
json = new JsonPath(ztcService.createInformatieObjectType(catalogusUrl).asString());
informatieobjecttypeUrl = json.getString("url").replace(ZTC_BASE_URI, ZTC_DOCKER_URI);
Response res = ztcService.publishInformatieObjectType(informatieobjecttypeUrl.substring(informatieobjecttypeUrl.lastIndexOf('/') + 1).trim());
Assert.assertEquals(res.getStatusCode(), 200);
}
@Test(groups = "CustomScope")
public void document_create_with_correct_scope() {
AuthService authService = new AuthService();
// can create document
authService.updateReadOnlyClientScope(new JSONArray().put("documenten.lezen").put("documenten.aanmaken"), "zeer_geheim", informatieobjecttypeUrl);
wait(2000);
EIOService eioService = new EIOService();
Response res = eioService.testCreate(DRCRequestSpecification.getReadonly(), informatieobjecttypeUrl);
Assert.assertEquals(res.getStatusCode(), 201);
}
@Test(groups = "CustomScope")
public void document_create_with_wrong_scope() {
AuthService authService = new AuthService();
// cannot create document
authService.updateReadOnlyClientScope(new JSONArray().put("documenten.lezen"), "zeer_geheim", informatieobjecttypeUrl);
wait(2000);
EIOService eioService = new EIOService();
Response res = eioService.testCreate(DRCRequestSpecification.getReadonly(), informatieobjecttypeUrl);
Assert.assertEquals(res.getStatusCode(), 403);
}
@Test(groups = "CustomScope")
public void lock_document_with_wrong_scope() {
AuthService authService = new AuthService();
authService.updateReadOnlyClientScope(new JSONArray().put("documenten.lezen").put("documenten.aanmaken"), "zeer_geheim", informatieobjecttypeUrl);
wait(2000);
EIOService eioService = new EIOService();
JsonPath json = new JsonPath(eioService.testCreate(DRCRequestSpecification.getReadonly(), informatieobjecttypeUrl).asString());
String eioUrl = json.getString("url");
// cannot lock document
Response res = eioService.lock(DRCRequestSpecification.getReadonly(), eioUrl);
Assert.assertEquals(res.getStatusCode(), 403);
}
@Test(groups = "CustomScope")
public void lock_document_with_correct_scope() {
AuthService authService = new AuthService();
authService.updateReadOnlyClientScope(new JSONArray().put("documenten.lezen").put("documenten.aanmaken").put("documenten.lock"), "zeer_geheim", informatieobjecttypeUrl);
wait(2000);
EIOService eioService = new EIOService();
JsonPath json = new JsonPath(eioService.testCreate(DRCRequestSpecification.getReadonly(), informatieobjecttypeUrl).asString());
String eioUrl = json.getString("url");
Response res = eioService.lock(DRCRequestSpecification.getReadonly(), eioUrl);
Assert.assertEquals(res.getStatusCode(), 200);
}
@Test(groups = "CustomScope")
public void unlock_document_with_correct_scope() {
// Update read-only client scope
AuthService authService = new AuthService();
authService.updateReadOnlyClientScope(new JSONArray().put("documenten.lezen").put("documenten.aanmaken").put("documenten.lock"), "zeer_geheim", informatieobjecttypeUrl);
wait(2000);
// create document
EIOService eioService = new EIOService();
String eioUrl = new JsonPath(eioService.testCreate(DRCRequestSpecification.getReadonly(), informatieobjecttypeUrl).asString()).getString("url");
// lock document
String lock = new JsonPath(eioService.lock(DRCRequestSpecification.getReadonly(), eioUrl).asString()).getString("lock");
// unlock document
Response res = eioService.unlock(DRCRequestSpecification.getReadonly(), eioUrl, lock);
Assert.assertEquals(res.getStatusCode(), 204);
}
@Test(groups = "CustomScope")
public void cannot_read_with_create_document_scope() {
AuthService authService = new AuthService();
authService.updateReadOnlyClientScope(new JSONArray().put("documenten.aanmaken"), "zeer_geheim", informatieobjecttypeUrl);
wait(2000);
EIOService eioService = new EIOService();
Response res = eioService.listEIO(DRCRequestSpecification.getReadonly(), null, null, null);
Assert.assertEquals(res.getStatusCode(), 403);
}
@Test(groups = "CustomScope")
public void unlock_without_body_with_all_auths() {
EIOService eioService = new EIOService();
// Create EIO
JsonPath json = new JsonPath(eioService.testCreate(DRCRequestSpecification.getDefault(), informatieobjecttypeUrl).asString());
String eioUrl = json.getString("url");
AuthService authService = new AuthService();
authService.list("drc_api_tests", null);
// Lock file
eioService.lock(DRCRequestSpecification.getDefault(), eioUrl);
// Unlock without body
String id = eioUrl.substring(eioUrl.lastIndexOf('/') + 1).trim();
Response res = given().spec(DRCRequestSpecification.getDefault()).when().post("/enkelvoudiginformatieobjecten/" + id + "/unlock").then().extract().response();
Assert.assertEquals(res.getStatusCode(), 204);
}
}