Skip to content

Commit f763756

Browse files
committed
Added test for #378
1 parent edd3034 commit f763756

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

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

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static access.security.SecurityConfig.API_TOKEN_HEADER;
2727
import static com.github.tomakehurst.wiremock.client.WireMock.*;
2828
import static io.restassured.RestAssured.given;
29+
import static java.util.Collections.emptyList;
2930
import static org.junit.jupiter.api.Assertions.*;
3031

3132
@SuppressWarnings("unchecked")
@@ -86,6 +87,7 @@ void newInvitation() throws Exception {
8687
false,
8788
List.of("new@new.nl"),
8889
roleIdentifiers,
90+
null,
8991
Instant.now().plus(365, ChronoUnit.DAYS),
9092
Instant.now().plus(12, ChronoUnit.DAYS));
9193

@@ -118,7 +120,8 @@ void newInvitationEmptyRoles() throws Exception {
118120
false,
119121
false,
120122
List.of("new@new.nl"),
121-
Collections.emptyList(),
123+
emptyList(),
124+
null,
122125
Instant.now().plus(365, ChronoUnit.DAYS),
123126
Instant.now().plus(12, ChronoUnit.DAYS));
124127

@@ -152,6 +155,7 @@ void newInvitationWithInvitationUrls() throws Exception {
152155
true,
153156
List.of("new@new.nl"),
154157
roleIdentifiers,
158+
null,
155159
Instant.now().plus(365, ChronoUnit.DAYS),
156160
Instant.now().plus(12, ChronoUnit.DAYS));
157161

@@ -613,6 +617,7 @@ void newInvitationInvalidEmail() throws Exception {
613617
false,
614618
List.of("nope"),
615619
roleIdentifiers,
620+
null,
616621
Instant.now().plus(365, ChronoUnit.DAYS),
617622
Instant.now().plus(12, ChronoUnit.DAYS));
618623

@@ -807,5 +812,64 @@ void invitationsSearchInviterWithKeyword404() throws Exception {
807812
.statusCode(404);
808813
}
809814

815+
@Test
816+
void newInvitationInstitutionAdmin() throws Exception {
817+
//Because the user is changed and provisionings are queried
818+
stubForManageProvidersAllowedByIdP(ORGANISATION_GUID);
819+
AccessCookieFilter accessCookieFilter = openIDConnectFlow("/api/v1/users/login", INSTITUTION_ADMIN_SUB);
820+
821+
stubForManageProviderById(EntityType.SAML20_SP, "1");
822+
823+
InvitationRequest invitationRequest = new InvitationRequest(
824+
Authority.INSTITUTION_ADMIN,
825+
"Message",
826+
Language.en,
827+
false,
828+
false,
829+
false,
830+
false,
831+
List.of("new@new.nl"),
832+
emptyList(),
833+
ORGANISATION_GUID,
834+
Instant.now().plus(365, ChronoUnit.DAYS),
835+
Instant.now().plus(12, ChronoUnit.DAYS));
836+
837+
Map<String, Object> results = given()
838+
.when()
839+
.filter(accessCookieFilter.cookieFilter())
840+
.accept(ContentType.JSON)
841+
.header(accessCookieFilter.csrfToken().getHeaderName(), accessCookieFilter.csrfToken().getToken())
842+
.contentType(ContentType.JSON)
843+
.body(invitationRequest)
844+
.post("/api/v1/invitations")
845+
.as(new TypeRef<>() {
846+
});
847+
assertEquals(201, results.get("status"));
848+
List recipientInvitationURLs = (List) results.get("recipientInvitationURLs");
849+
assertEquals(1, recipientInvitationURLs.size());
850+
//Now Accept the invitation with a new user
851+
String invitationURL = ((Map<String, String>) recipientInvitationURLs.getFirst()).get("invitationURL");
852+
MultiValueMap<String, String> queryParams = UriComponentsBuilder.fromUriString(invitationURL).build().getQueryParams();
853+
String hash = queryParams.getFirst("hash");
854+
Invitation invitation = invitationRepository.findByHash(hash).get();
855+
856+
AccessCookieFilter guestAccessCookieFilter = openIDConnectFlow("/api/v1/users/login", "user@dodo.com");
857+
AcceptInvitation acceptInvitation = new AcceptInvitation(hash, invitation.getId());
858+
given()
859+
.when()
860+
.filter(guestAccessCookieFilter.cookieFilter())
861+
.accept(ContentType.JSON)
862+
.header(guestAccessCookieFilter.csrfToken().getHeaderName(), guestAccessCookieFilter.csrfToken().getToken())
863+
.contentType(ContentType.JSON)
864+
.body(acceptInvitation)
865+
.post("/api/v1/invitations/accept")
866+
.then()
867+
.statusCode(201);
868+
869+
User user = userRepository.findBySubIgnoreCase("user@dodo.com").get();
870+
assertTrue(user.isInstitutionAdmin());
871+
assertTrue(user.isInstitutionAdminByInvite());
872+
}
873+
810874

811875
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void newInvitationCustomDisplayName() throws Exception {
6060
false,
6161
List.of("new@new.nl"),
6262
roleIdentifiers,
63+
null,
6364
Instant.now().plus(365, ChronoUnit.DAYS),
6465
Instant.now().plus(12, ChronoUnit.DAYS));
6566

server/src/test/java/access/internal/InternalInviteControllerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void newInvitation() {
139139
false,
140140
List.of("new@new.nl"),
141141
roleIdentifiers,
142+
null,
142143
Instant.now().plus(365, ChronoUnit.DAYS),
143144
Instant.now().plus(12, ChronoUnit.DAYS));
144145

0 commit comments

Comments
 (0)