|
5 | 5 | import access.manage.Contact; |
6 | 6 | import access.manage.MetaData; |
7 | 7 | import access.model.Application; |
| 8 | +import access.model.Connection; |
8 | 9 | import access.model.ConnectionStatus; |
9 | 10 | import access.model.EntityType; |
| 11 | +import access.model.Environment; |
10 | 12 | import access.model.Organization; |
11 | 13 | import com.fasterxml.jackson.core.type.TypeReference; |
12 | 14 | import io.restassured.common.mapper.TypeRef; |
|
17 | 19 | import org.springframework.core.io.ClassPathResource; |
18 | 20 | import org.springframework.http.HttpStatus; |
19 | 21 |
|
20 | | -import java.lang.reflect.Type; |
21 | 22 | import java.nio.charset.Charset; |
22 | 23 | import java.util.List; |
23 | 24 | import java.util.Map; |
@@ -132,7 +133,7 @@ void find() { |
132 | 133 | Map<String, Object> o = (Map<String, Object>) connections.stream() |
133 | 134 | .filter(connection -> ((Map<String, Object>) connection).get("status").equals(ConnectionStatus.PROD_READY.name())) |
134 | 135 | .findFirst().get(); |
135 | | - assertEquals(2, ((List)o.get("changeRequests")).size()); |
| 136 | + assertEquals(2, ((List) o.get("changeRequests")).size()); |
136 | 137 | } |
137 | 138 |
|
138 | 139 | @Test |
@@ -160,6 +161,63 @@ void update() { |
160 | 161 | assertEquals(application.getName(), applicationFromDB.getName()); |
161 | 162 | } |
162 | 163 |
|
| 164 | + @Test |
| 165 | + void updateSignContractNotAllowed() { |
| 166 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(EXTERNAL_USER_SUB); |
| 167 | + Application application = applicationRepository.findById(seedIdentifiers.get(BUDDY_CHECK)).get(); |
| 168 | + application.setSignedContract(true); |
| 169 | + Organization organization = application.getOrganization(); |
| 170 | + //Otherwise rest-assured does not deserialize the Organization |
| 171 | + Map<String, Object> applicationData = objectMapper.convertValue(application, new TypeReference<>() { |
| 172 | + }); |
| 173 | + applicationData.put("organization", Map.of("id", organization.getId())); |
| 174 | + |
| 175 | + given() |
| 176 | + .when() |
| 177 | + .filter(accessCookieFilter.cookieFilter()) |
| 178 | + .header(csrfHeader(accessCookieFilter)) |
| 179 | + .accept(ContentType.JSON) |
| 180 | + .contentType(ContentType.JSON) |
| 181 | + .body(applicationData) |
| 182 | + .put("/api/v1/applications") |
| 183 | + .then() |
| 184 | + .statusCode(HttpStatus.FORBIDDEN.value()); |
| 185 | + } |
| 186 | + |
| 187 | + @Test |
| 188 | + void updateMetaDataChanged() { |
| 189 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(EXTERNAL_USER_SUB); |
| 190 | + Application application = applicationRepository.findById(seedIdentifiers.get(BUDDY_CHECK)).get(); |
| 191 | + application.getMetaData().put("information", Map.of("descriptionEN", "Changed")); |
| 192 | + Organization organization = application.getOrganization(); |
| 193 | + //Otherwise rest-assured does not deserialize the Organization |
| 194 | + Map<String, Object> applicationData = objectMapper.convertValue(application, new TypeReference<>() { |
| 195 | + }); |
| 196 | + applicationData.put("organization", Map.of("id", organization.getId())); |
| 197 | + |
| 198 | + //The details of the connections are retrieved |
| 199 | + super.stubForGetProvider(EntityType.oidc10_rp, MANAGE_IDENTIFIER, Environment.PROD, "5"); |
| 200 | + Connection connectionProd = connectionRepository.findById(seedIdentifiers.get(BUDDY_CHECK_PROD)).get(); |
| 201 | + connectionProd.setManageIdentifier("5"); |
| 202 | + super.stubForSaveProvider(connectionProd); |
| 203 | + Connection connectionTest = connectionRepository.findById(seedIdentifiers.get(BUDDY_CHECK_TEST)).get(); |
| 204 | + super.stubForSaveProvider(connectionTest); |
| 205 | + |
| 206 | + Application savedApplication = given() |
| 207 | + .when() |
| 208 | + .filter(accessCookieFilter.cookieFilter()) |
| 209 | + .header(csrfHeader(accessCookieFilter)) |
| 210 | + .accept(ContentType.JSON) |
| 211 | + .contentType(ContentType.JSON) |
| 212 | + .body(applicationData) |
| 213 | + .put("/api/v1/applications") |
| 214 | + .as(new TypeRef<>() { |
| 215 | + }); |
| 216 | + Application applicationFromDB = applicationRepository.findById(savedApplication.getId()).get(); |
| 217 | + assertEquals(application.getMetaData(), applicationFromDB.getMetaData()); |
| 218 | + |
| 219 | + } |
| 220 | + |
163 | 221 | @Test |
164 | 222 | void delete() { |
165 | 223 | AccessCookieFilter accessCookieFilter = mockLoginFlow(MANAGE_SUB); |
|
0 commit comments