Merge remote-tracking branch 'origin/master' into JavaDocComments
# Conflicts: # src/main/java/mops/gruppen2/service/ControllerService.java
This commit is contained in:
@ -1,16 +1,12 @@
|
|||||||
FROM gradle:jdk11 AS build
|
FROM gradle:jdk11 AS build
|
||||||
COPY --chown=gradle:gradle . /home/gradle/src
|
COPY --chown=gradle:gradle . /home/gradle/src
|
||||||
WORKDIR /home/gradle/src
|
WORKDIR /home/gradle/src
|
||||||
|
|
||||||
RUN chmod +x ./pull-wait-for-it.sh
|
|
||||||
RUN ./pull-wait-for-it.sh
|
|
||||||
RUN chmod +x ./wait-for-it.sh
|
|
||||||
|
|
||||||
RUN gradle bootJar --no-daemon
|
RUN gradle bootJar --no-daemon
|
||||||
|
|
||||||
FROM openjdk:11-jre-slim
|
FROM openjdk:11-jre-slim
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
COPY --from=build /home/gradle/src/build/libs/*.jar /app/gruppen2.jar
|
COPY --from=build /home/gradle/src/build/libs/*.jar /app/gruppen2.jar
|
||||||
COPY --from=build /home/gradle/src/wait-for-it.sh /app/wait-for-it.sh
|
COPY --from=build /home/gradle/src/wait-for-it.sh /app/wait-for-it.sh
|
||||||
|
RUN chmod +x /app/wait-for-it.sh
|
||||||
#ENTRYPOINT ["java"]
|
#ENTRYPOINT ["java"]
|
||||||
#CMD ["-Dspring.profiles.active=docker", "-jar", "/app/gruppen2.jar"]
|
#CMD ["-Dspring.profiles.active=docker", "-jar", "/app/gruppen2.jar"]
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ ! -f wait-for-it.sh ]; then
|
|
||||||
wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
|
|
||||||
fi
|
|
@ -280,8 +280,6 @@ public class WebController {
|
|||||||
validationService.checkGroup(group.getTitle());
|
validationService.checkGroup(group.getTitle());
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
|
|
||||||
//controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), group.getId());
|
|
||||||
|
|
||||||
if (group.getVisibility() == Visibility.PUBLIC) {
|
if (group.getVisibility() == Visibility.PUBLIC) {
|
||||||
return "redirect:/gruppen2/details/" + group.getId();
|
return "redirect:/gruppen2/details/" + group.getId();
|
||||||
}
|
}
|
||||||
@ -299,7 +297,7 @@ public class WebController {
|
|||||||
|
|
||||||
User user = new User(acc.getName(), acc.getGivenname(), acc.getFamilyname(), acc.getEmail());
|
User user = new User(acc.getName(), acc.getGivenname(), acc.getFamilyname(), acc.getEmail());
|
||||||
|
|
||||||
if (!validationService.checkIfUserInGroup(userService.getGroupById(UUID.fromString(groupId)), user)) {
|
if (!validationService.checkIfUserInGroupWithoutNoAccessAcception(userService.getGroupById(UUID.fromString(groupId)), user)) {
|
||||||
controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), UUID.fromString(groupId));
|
controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), UUID.fromString(groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package mops.gruppen2.repository;
|
package mops.gruppen2.repository;
|
||||||
|
|
||||||
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||||
|
import org.springframework.data.jdbc.repository.query.Modifying;
|
||||||
import org.springframework.data.jdbc.repository.query.Query;
|
import org.springframework.data.jdbc.repository.query.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
@ -12,6 +13,7 @@ public interface InviteRepository extends CrudRepository<InviteLinkDTO, Long> {
|
|||||||
@Query("SELECT group_id FROM invite WHERE invite_link = :link")
|
@Query("SELECT group_id FROM invite WHERE invite_link = :link")
|
||||||
String findGroupIdByLink(@Param("link") String link);
|
String findGroupIdByLink(@Param("link") String link);
|
||||||
|
|
||||||
|
@Modifying
|
||||||
@Query("DELETE FROM invite WHERE group_id = :group")
|
@Query("DELETE FROM invite WHERE group_id = :group")
|
||||||
void deleteLinkOfGroup(@Param("group") String group);
|
void deleteLinkOfGroup(@Param("group") String group);
|
||||||
|
|
||||||
|
@ -47,8 +47,7 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST,
|
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||||
proxyMode = ScopedProxyMode.TARGET_CLASS)
|
|
||||||
public AccessToken getAccessToken() {
|
public AccessToken getAccessToken() {
|
||||||
HttpServletRequest request =
|
HttpServletRequest request =
|
||||||
((ServletRequestAttributes) RequestContextHolder
|
((ServletRequestAttributes) RequestContextHolder
|
||||||
|
@ -132,7 +132,8 @@ public class ControllerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<User> readCsvFile(MultipartFile file) throws EventException {
|
private List<User> readCsvFile(MultipartFile file) throws EventException{
|
||||||
|
if(file == null) return new ArrayList<>();
|
||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
List<User> userList = CsvService.read(file.getInputStream());
|
List<User> userList = CsvService.read(file.getInputStream());
|
||||||
|
@ -62,6 +62,11 @@ public class ValidationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Warum ist das überhaupt nötig smh
|
||||||
|
public boolean checkIfUserInGroupWithoutNoAccessAcception(Group group, User user) {
|
||||||
|
return group.getMembers().contains(user);
|
||||||
|
}
|
||||||
|
|
||||||
public Group checkParent(UUID parentId) {
|
public Group checkParent(UUID parentId) {
|
||||||
Group parent = new Group();
|
Group parent = new Group();
|
||||||
if (!controllerService.idIsEmpty(parentId)) {
|
if (!controllerService.idIsEmpty(parentId)) {
|
||||||
|
@ -1,85 +1,304 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import com.github.javafaker.Faker;
|
import mops.gruppen2.Gruppen2Application;
|
||||||
|
import mops.gruppen2.domain.User;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.Role;
|
||||||
|
import mops.gruppen2.domain.Visibility;
|
||||||
|
import mops.gruppen2.domain.GroupType;
|
||||||
|
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import mops.gruppen2.repository.InviteRepository;
|
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.annotation.Rollback;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@SpringBootTest(classes = Gruppen2Application.class)
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
class ControllerServiceTest {
|
class ControllerServiceTest {
|
||||||
|
Account account, account2, account3;
|
||||||
Faker faker;
|
|
||||||
Account account;
|
|
||||||
ControllerService controllerService;
|
ControllerService controllerService;
|
||||||
EventService eventService;
|
EventService eventService;
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
@Autowired
|
||||||
EventRepository eventRepository;
|
EventRepository eventRepository;
|
||||||
GroupService groupService;
|
GroupService groupService;
|
||||||
|
@Autowired
|
||||||
JsonService jsonService;
|
JsonService jsonService;
|
||||||
InviteRepository inviteRepository;
|
@Autowired
|
||||||
InviteService inviteService;
|
InviteService inviteService;
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
jsonService = new JsonService();
|
|
||||||
eventRepository = mock(EventRepository.class);
|
|
||||||
eventService = new EventService(jsonService, eventRepository);
|
eventService = new EventService(jsonService, eventRepository);
|
||||||
groupService = new GroupService(eventService, eventRepository);
|
groupService = new GroupService(eventService, eventRepository);
|
||||||
userService = new UserService(groupService, eventService);
|
userService = new UserService(groupService, eventService);
|
||||||
inviteRepository = mock(InviteRepository.class);
|
|
||||||
inviteService = new InviteService(inviteRepository);
|
|
||||||
controllerService = new ControllerService(eventService, userService, inviteService);
|
controllerService = new ControllerService(eventService, userService, inviteService);
|
||||||
Set<String> roles = new HashSet<>();
|
Set<String> roles = new HashSet<>();
|
||||||
roles.add("l");
|
roles.add("l");
|
||||||
account = new Account("ich", "ich@hhu.de", "l", "ichdude", "jap", roles);
|
account = new Account("ich", "ich@hhu.de", "l", "ichdude", "jap", roles);
|
||||||
|
account2 = new Account("ich2", "ich2@hhu.de", "l", "ichdude2", "jap2", roles);
|
||||||
|
account3 = new Account("ich3", "ich3@hhu.de", "l", "ichdude3", "jap3", roles);
|
||||||
|
eventRepository.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createGroupTest() {
|
void createPublicGroupWithNoParentAndLimitedNumberTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createOrga() {
|
void createPublicGroupWithNoParentAndUnlimitedNumberTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
List<Group> groups = userService.getUserGroups(user);
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addUser() {
|
void createPrivateGroupWithNoParentAndUnlimitedNumberTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
||||||
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
List<Group> groups = userService.getUserGroups(user);
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addUserList() {
|
void createPrivateGroupWithNoParentAndLimitedNumberTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, null);
|
||||||
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
List<Group> groups = userService.getUserGroups(user);
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateTitle() {
|
void createPrivateGroupWithParentAndLimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account2, "test", "hi", null, true, true, null, null, null);
|
||||||
|
User user = new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail());
|
||||||
|
List<Group> groups1 = userService.getUserGroups(user);
|
||||||
|
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, groups1.get(0).getId());
|
||||||
|
User user2 = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
List<Group> groups = userService.getUserGroups(user2);
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
|
assertEquals(groups1.get(0).getId(), groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateDescription() {
|
void createPublicGroupWithParentAndLimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||||
|
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, groups1.get(0).getId());
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
|
assertEquals(groups1.get(0).getId(), groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateRoleTest() {
|
void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||||
|
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, true, true, null,groups1.get(0).getId());
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
|
assertEquals(groups1.get(0).getId(), groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteUser() {
|
void createPrivateGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||||
|
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
|
controllerService.createGroup(account, "test", "hi", true, true, true, null, groups1.get(0).getId());
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
|
assertEquals(groups1.get(0).getId(), groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteGroupEvent() {
|
void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account, "test", "hi", null, null, null, 20L, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||||
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void passIfLastAdmin() {
|
void createPublicOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account, "test", "hi", null, null, true, null, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||||
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createPrivateOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account, "test", "hi", true, null, null, 20L, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||||
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createPrivateOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account, "test", "hi", true, null, true, null, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||||
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createOrgaLectureGroupAndLimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account, "test", "hi", null, true, null, 20L, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
||||||
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException {
|
||||||
|
controllerService.createGroupAsOrga(account, "test", "hi", null, true, true, null, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
|
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
||||||
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
|
assertNull(groups.get(0).getParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteUserTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", true, true, true, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
|
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
||||||
|
assertTrue(userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail())).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateRoleAdminTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
|
controllerService.updateRole(account.getName(), groups.get(0).getId());
|
||||||
|
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateRoleMemberTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
|
controllerService.updateRole(account2.getName(), groups.get(0).getId());
|
||||||
|
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateRoleNonUserTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.updateRole(account2.getName(), groups.get(0).getId()));
|
||||||
|
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ControllerService)\"", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteNonUserTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.deleteUser(account2.getName(), groups.get(0).getId()));
|
||||||
|
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ControllerService)\"", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
void testTitleAndDescription(String title, String description) {
|
||||||
|
assertEquals("test", title);
|
||||||
|
assertEquals("hi", description);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void passIfLastAdminTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
|
controllerService.passIfLastAdmin(account, groups.get(0).getId());
|
||||||
|
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
||||||
|
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
|
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void dontPassIfNotLastAdminTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
|
controllerService.updateRole(account2.getName(), groups.get(0).getId());
|
||||||
|
controllerService.addUser(account3, groups.get(0).getId());
|
||||||
|
controllerService.passIfLastAdmin(account, groups.get(0).getId());
|
||||||
|
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
||||||
|
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
|
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getVeteranMemberTest() {
|
||||||
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
|
controllerService.addUser(account3, groups.get(0).getId());
|
||||||
|
controllerService.passIfLastAdmin(account, groups.get(0).getId());
|
||||||
|
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
||||||
|
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
|
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||||
|
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
182
wait-for-it.sh
Normal file
182
wait-for-it.sh
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Use this script to test if a given TCP host/port are available
|
||||||
|
|
||||||
|
WAITFORIT_cmdname=${0##*/}
|
||||||
|
|
||||||
|
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
cat << USAGE >&2
|
||||||
|
Usage:
|
||||||
|
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
|
||||||
|
-h HOST | --host=HOST Host or IP under test
|
||||||
|
-p PORT | --port=PORT TCP port under test
|
||||||
|
Alternatively, you specify the host and port as host:port
|
||||||
|
-s | --strict Only execute subcommand if the test succeeds
|
||||||
|
-q | --quiet Don't output any status messages
|
||||||
|
-t TIMEOUT | --timeout=TIMEOUT
|
||||||
|
Timeout in seconds, zero for no timeout
|
||||||
|
-- COMMAND ARGS Execute command with args after the test finishes
|
||||||
|
USAGE
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for()
|
||||||
|
{
|
||||||
|
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||||
|
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||||
|
else
|
||||||
|
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
|
||||||
|
fi
|
||||||
|
WAITFORIT_start_ts=$(date +%s)
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
|
||||||
|
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
|
||||||
|
WAITFORIT_result=$?
|
||||||
|
else
|
||||||
|
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
||||||
|
WAITFORIT_result=$?
|
||||||
|
fi
|
||||||
|
if [[ $WAITFORIT_result -eq 0 ]]; then
|
||||||
|
WAITFORIT_end_ts=$(date +%s)
|
||||||
|
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
return $WAITFORIT_result
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for_wrapper()
|
||||||
|
{
|
||||||
|
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
|
||||||
|
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
|
||||||
|
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||||
|
else
|
||||||
|
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||||
|
fi
|
||||||
|
WAITFORIT_PID=$!
|
||||||
|
trap "kill -INT -$WAITFORIT_PID" INT
|
||||||
|
wait $WAITFORIT_PID
|
||||||
|
WAITFORIT_RESULT=$?
|
||||||
|
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
|
||||||
|
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||||
|
fi
|
||||||
|
return $WAITFORIT_RESULT
|
||||||
|
}
|
||||||
|
|
||||||
|
# process arguments
|
||||||
|
while [[ $# -gt 0 ]]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
*:* )
|
||||||
|
WAITFORIT_hostport=(${1//:/ })
|
||||||
|
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
|
||||||
|
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
--child)
|
||||||
|
WAITFORIT_CHILD=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-q | --quiet)
|
||||||
|
WAITFORIT_QUIET=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-s | --strict)
|
||||||
|
WAITFORIT_STRICT=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-h)
|
||||||
|
WAITFORIT_HOST="$2"
|
||||||
|
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--host=*)
|
||||||
|
WAITFORIT_HOST="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-p)
|
||||||
|
WAITFORIT_PORT="$2"
|
||||||
|
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--port=*)
|
||||||
|
WAITFORIT_PORT="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-t)
|
||||||
|
WAITFORIT_TIMEOUT="$2"
|
||||||
|
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--timeout=*)
|
||||||
|
WAITFORIT_TIMEOUT="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
WAITFORIT_CLI=("$@")
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echoerr "Unknown argument: $1"
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
|
||||||
|
echoerr "Error: you need to provide a host and port to test."
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
|
||||||
|
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
|
||||||
|
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
|
||||||
|
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
|
||||||
|
|
||||||
|
# Check to see if timeout is from busybox?
|
||||||
|
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
|
||||||
|
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
|
||||||
|
|
||||||
|
WAITFORIT_BUSYTIMEFLAG=""
|
||||||
|
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
||||||
|
WAITFORIT_ISBUSY=1
|
||||||
|
# Check if busybox timeout uses -t flag
|
||||||
|
# (recent Alpine versions don't support -t anymore)
|
||||||
|
if timeout &>/dev/stdout | grep -q -e '-t '; then
|
||||||
|
WAITFORIT_BUSYTIMEFLAG="-t"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
WAITFORIT_ISBUSY=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
|
||||||
|
wait_for
|
||||||
|
WAITFORIT_RESULT=$?
|
||||||
|
exit $WAITFORIT_RESULT
|
||||||
|
else
|
||||||
|
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||||
|
wait_for_wrapper
|
||||||
|
WAITFORIT_RESULT=$?
|
||||||
|
else
|
||||||
|
wait_for
|
||||||
|
WAITFORIT_RESULT=$?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $WAITFORIT_CLI != "" ]]; then
|
||||||
|
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
|
||||||
|
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
|
||||||
|
exit $WAITFORIT_RESULT
|
||||||
|
fi
|
||||||
|
exec "${WAITFORIT_CLI[@]}"
|
||||||
|
else
|
||||||
|
exit $WAITFORIT_RESULT
|
||||||
|
fi
|
Reference in New Issue
Block a user