Skip to content

Commit 55ab55d

Browse files
committed
Added tests
1 parent 19c2ec9 commit 55ab55d

8 files changed

Lines changed: 124 additions & 18 deletions

File tree

client/src/locale/en.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,8 @@ const en = {
10671067
appAccess: {
10681068
title: "Central Access",
10691069
users: "Users from {{name}}",
1070-
requestedAccessNotification: "You have requested access to this application. If the supplier (SP) approves this, you can manage access to the app below. Still don't want to connect?",
1071-
requestedDisconnectNotification: "You have requested to have no longer access to this application. Still want to remain connected?",
1070+
requestedAccessNotification: "You have requested access to this application - ticket {{ticketKey}}. If the supplier (SP) approves this, you can manage access to the app below. Still don't want to connect?",
1071+
requestedDisconnectNotification: "You have requested to have no longer access to this application - ticket {{ticketKey}}. Still want to remain connected?",
10721072
cancelRequest: "Cancel the request.",
10731073
cancelRequestTitle: "Cancel the request.",
10741074
cancelRequestQuestion: "Are you sure you don't want to have access to this application? The request for a connection will be withdrawn.",

client/src/locale/nl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,8 @@ const nl = {
10641064
appAccess: {
10651065
title: "Centrale toegang",
10661066
users: "Gebruikers van {{name}}",
1067-
requestedAccessNotification: "Je hebt toegang tot deze applicatie aangevraagd. Als de leverancier (SP) dit goedkeurt, kun je hieronder de toegang beheren. Wil je toch niet verbinden?",
1068-
requestedDisconnectNotification: "Je hebt verzocht geen toegang meer te hebben tot deze applicatie. Wil je toch verbonden blijven?",
1067+
requestedAccessNotification: "Je hebt toegang tot deze applicatie aangevraagd - ticket {{ticketKey}}. Als de leverancier (SP) dit goedkeurt, kun je hieronder de toegang beheren. Wil je toch niet verbinden?",
1068+
requestedDisconnectNotification: "Je hebt verzocht geen toegang meer te hebben tot deze applicatie - ticket {{ticketKey}}. Wil je toch verbonden blijven?",
10691069
cancelRequest: "Verzoek annuleren.",
10701070
cancelRequestTitle: "Verzoek annuleren.",
10711071
cancelRequestQuestion: "Weet je zeker dat je geen toegang meer wilt tot deze applicatie? Het verzoek om verbinding wordt ingetrokken.",

client/src/utils/Permissions.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,26 @@ export const deriveAccess = (user, spEntityId) => {
8686
const allowedEntities = user.identityProvider.data.allowedEntities.map(e => e.name);
8787
isAccessible = allowedEntities.includes(spEntityId);
8888
isReadOnly = !isAccessible;
89-
89+
let ticketKey = null;
9090
if (!isAccessible) {
91-
isAccessible = user.changeRequests.some(cr =>
91+
const changeRequestAdd = user.changeRequests.find(cr =>
9292
cr.requestType === CHANGE_REQUEST_TYPE.LINK_REQUEST &&
9393
cr.pathUpdateType === "ADDITION" &&
9494
cr.pathUpdates.allowedEntities.name === spEntityId
9595
);
96+
isAccessible = !isEmpty(changeRequestAdd);
97+
ticketKey = isEmpty(changeRequestAdd) ? null : changeRequestAdd.ticketKey
9698
}
97-
isPendingDisconnect = user.changeRequests.some(cr =>
98-
cr.requestType === CHANGE_REQUEST_TYPE.UNLINK_REQUEST &&
99-
cr.pathUpdateType === "REMOVAL" &&
100-
cr.pathUpdates.allowedEntities.name === spEntityId
101-
);
102-
103-
return {isAccessible, isReadOnly, isPendingDisconnect};
99+
const changeRequestRemoval = user.changeRequests.find(cr =>
100+
cr.requestType === CHANGE_REQUEST_TYPE.UNLINK_REQUEST &&
101+
cr.pathUpdateType === "REMOVAL" &&
102+
cr.pathUpdates.allowedEntities.name === spEntityId
103+
);
104+
isPendingDisconnect = !isEmpty(changeRequestRemoval);
105+
if (ticketKey === null) {
106+
ticketKey = isEmpty(changeRequestRemoval) ? null : changeRequestRemoval.ticketKey;
107+
}
108+
return {isAccessible, isReadOnly, isPendingDisconnect, ticketKey};
104109
}
105110

106111
export const isAdmin = (user, authorities) => {

server/src/main/java/access/manage/LocalManage.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,10 @@ public Map<String, Object> saveIdentityProvider(Organization organization) {
107107
@SneakyThrows
108108
@Override
109109
public Map<String, Object> saveProvider(Connection connection) {
110-
Map<String, Object> baseStructure = StringUtils.hasText(connection.getManageIdentifier()) ?
110+
Map<String, Object> provider = StringUtils.hasText(connection.getManageIdentifier()) ?
111111
providerByConnection(connection) :
112112
baseStructureProvider();
113113

114-
Map<String, Object> provider = converter.convert(connection, baseStructure, false);
115114
boolean existingProvider = provider.containsKey("id");
116115
if (existingProvider) {
117116
provider.put("version", (int) provider.get("version") + 1);

server/src/main/java/access/model/Connection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void updateRemoteManageData(Map<String, Object> provider) {
209209
this.manageVersion = (Integer) provider.get("version");
210210
Map<String, Object> data = (Map<String, Object>) provider.get("data");
211211
this.manageEid = (Integer) data.get("eid");
212-
this.state = State.valueOf((String) data.get("state"));
212+
this.state = State.valueOf((String) data.getOrDefault("state", "testaccepted"));
213213
}
214214

215215
@JsonIgnore

server/src/test/java/access/AbstractTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,20 @@ protected Map<String, Object> stubForGetProvider(EntityType entityType, String m
464464
return provider;
465465
}
466466

467+
@SneakyThrows
468+
protected Map<String, Object> stubForGetProvider(EntityType entityType, String manageIdentifier, Environment environment,
469+
String actualManageIdentifier) {
470+
Map<String, Object> provider = localManage.providerByManageIdentifier(entityType, actualManageIdentifier, environment);
471+
String body = objectMapper.writeValueAsString(provider);
472+
stubFor(get(String.format("/manage/api/internal/metadata/%s/%s",
473+
entityType.name(),
474+
manageIdentifier))
475+
.willReturn(aResponse().withHeader("Content-Type", "application/json")
476+
.withBody(body)
477+
.withStatus(200)));
478+
return provider;
479+
}
480+
467481
@SneakyThrows
468482
protected void stubForGetChangeRequests(List<Map<String, Object>> changeRequests) {
469483
String body = objectMapper.writeValueAsString(changeRequests);

server/src/test/java/access/api/ApplicationControllerTest.java

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import access.manage.Contact;
66
import access.manage.MetaData;
77
import access.model.Application;
8+
import access.model.Connection;
89
import access.model.ConnectionStatus;
910
import access.model.EntityType;
11+
import access.model.Environment;
1012
import access.model.Organization;
1113
import com.fasterxml.jackson.core.type.TypeReference;
1214
import io.restassured.common.mapper.TypeRef;
@@ -17,7 +19,6 @@
1719
import org.springframework.core.io.ClassPathResource;
1820
import org.springframework.http.HttpStatus;
1921

20-
import java.lang.reflect.Type;
2122
import java.nio.charset.Charset;
2223
import java.util.List;
2324
import java.util.Map;
@@ -132,7 +133,7 @@ void find() {
132133
Map<String, Object> o = (Map<String, Object>) connections.stream()
133134
.filter(connection -> ((Map<String, Object>) connection).get("status").equals(ConnectionStatus.PROD_READY.name()))
134135
.findFirst().get();
135-
assertEquals(2, ((List)o.get("changeRequests")).size());
136+
assertEquals(2, ((List) o.get("changeRequests")).size());
136137
}
137138

138139
@Test
@@ -160,6 +161,63 @@ void update() {
160161
assertEquals(application.getName(), applicationFromDB.getName());
161162
}
162163

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+
163221
@Test
164222
void delete() {
165223
AccessCookieFilter accessCookieFilter = mockLoginFlow(MANAGE_SUB);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package access.manage;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class CidrNotationTest {
8+
9+
@Test
10+
void getIpInfoIPv4() {
11+
CidrNotation cidrNotation = new CidrNotation("192.168.1.1", 16);
12+
IPInfo ipInfo = cidrNotation.getIpInfo();
13+
assertEquals("192.168.255.255", ipInfo.getBroadcastAddress());
14+
assertEquals("192.168.0.0", ipInfo.getNetworkAddress());
15+
assertEquals(65536.0, ipInfo.getCapacity());
16+
assertEquals(16, ipInfo.getPrefix());
17+
assertTrue(ipInfo.isIpv4());
18+
}
19+
20+
@Test
21+
void getIpInfoIPv6() {
22+
CidrNotation cidrNotation = new CidrNotation("2001:db8:3333:4444:5555:6666:7777:8888", 64);
23+
IPInfo ipInfo = cidrNotation.getIpInfo();
24+
assertEquals("2001:db8:3333:4444:ffff:ffff:ffff:ffff", ipInfo.getBroadcastAddress());
25+
assertEquals("2001:db8:3333:4444:0:0:0:0", ipInfo.getNetworkAddress());
26+
assertEquals(1.8446744073709552E19, ipInfo.getCapacity());
27+
assertEquals(64, ipInfo.getPrefix());
28+
assertFalse(ipInfo.isIpv4());
29+
}
30+
}

0 commit comments

Comments
 (0)