aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/test/java')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java31
1 files changed, 30 insertions, 1 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
index 4f58b12..db849f2 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
@@ -6,6 +6,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
+import java.time.LocalDateTime;
+import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
@@ -105,5 +107,32 @@ public class AuthServiceTest {
assertDoesNotThrow(() -> authService.logout(key));
}
-
+
+ @Test
+ void keyIsValid() throws IOException {
+ String key = "sowgro";
+ when(mockAuthDAO.getUserAuth(key)).thenReturn(null);
+
+ assertThrows(IllegalAccessException.class, () -> authService.keyIsValid(key));
+ }
+
+ @Test
+ void keyHasAccessToCupboard1() throws IOException {
+ String key = "sowgro";
+ when(mockAuthDAO.getUserAuth(key)).thenReturn(null);
+
+ assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToCupboard(key));
+ }
+
+ @Test
+ void keyHasAccessToCupboard2() throws IOException {
+ String key = "sowgro";
+ UserAuth userAuth = new UserAuth("sowgro", "sowgro", LocalDateTime.MAX);
+ User user = new User("sowgro", 8675309, List.of(), User.UserType.HELPER);
+
+ when(mockAuthDAO.getUserAuth(key)).thenReturn(userAuth);
+ when(mockUserService.getUser(key)).thenReturn(user);
+
+ assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToCupboard(key));
+ }
}