aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-03-17 23:16:29 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-03-17 23:16:29 -0400
commit68515441acd77d3356e8ec8b58700411661fec13 (patch)
treef3e08e4eecb5c06c8149d56ca08253a3c2d92607 /ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
parent7a5c5073e9e410b3ccc3ab7902a0d6f558277c7d (diff)
parent275a6062007380389b7a8f1b8958e8033b4f0925 (diff)
downloadJellySolutions-68515441acd77d3356e8ec8b58700411661fec13.tar.gz
JellySolutions-68515441acd77d3356e8ec8b58700411661fec13.tar.bz2
JellySolutions-68515441acd77d3356e8ec8b58700411661fec13.zip
Merge remote-tracking branch 'refs/remotes/origin/main' into funding_basket
# Conflicts: # ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java110
1 files changed, 110 insertions, 0 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
new file mode 100644
index 0000000..55cf7a9
--- /dev/null
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
@@ -0,0 +1,110 @@
+package com.ufund.api.ufundapi.service;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import com.ufund.api.ufundapi.DuplicateKeyException;
+import com.ufund.api.ufundapi.model.User;
+import com.ufund.api.ufundapi.model.UserAuth;
+import com.ufund.api.ufundapi.persistence.UserAuthDAO;
+
+@Tag("Service-tier")
+public class AuthServiceTest {
+
+ private UserAuthDAO mockAuthDAO;
+ private UserService mockUserService;
+ private AuthService authService;
+ private String username;
+ private String key;
+ private String password;
+ private User user;
+
+ @BeforeEach
+ public void setupAuthService() {
+ mockAuthDAO = mock(UserAuthDAO.class);
+ mockUserService = mock(UserService.class);
+ authService = new AuthService(mockAuthDAO, mockUserService);
+
+ username = "Fish";
+ password = "sticks";
+ key = UserAuth.generate(username).getKey();
+ user = User.create(username, password);
+
+ }
+
+ @Test
+ public void testAuthenticate() throws IOException {
+ // Mock
+ when(mockAuthDAO.getUserAuth(key)).thenReturn(new UserAuth(key, username, null));
+ when(mockUserService.getUser(username)).thenReturn(user);
+
+ // Analyze
+ assertDoesNotThrow(() -> authService.authenticate(username, key));
+
+ }
+
+// @Test
+// public void testAuthenticateMismatchName() throws IOException {
+// // Mock
+// when(mockAuthDAO.getUserAuth(key)).thenReturn(new UserAuth(key, "EvilFish", null));
+// when(mockUserService.getUser("EvilFish")).thenReturn(user);
+//
+// // Analyze
+// assertThrows(IllegalAccessException.class, () -> authService.authenticate(username, key));
+//
+// }
+
+ @Test
+ public void testAuthenticateMissingUserAuth() throws IOException {
+ // Mock
+ when(mockAuthDAO.getUserAuth(key)).thenReturn(null);
+
+ // Analyze
+ assertThrows(IllegalAccessException.class, () -> authService.authenticate(username, key));
+
+ }
+
+ @Test
+ public void testLogin() throws IOException, DuplicateKeyException, IllegalAccessException {
+ // Mock
+ when(mockUserService.getUser(username)).thenReturn(user);
+
+
+ // Analyze
+ assertDoesNotThrow(() -> authService.login(username, password));
+ }
+
+ @Test
+ public void testLoginNullUser() throws IOException, DuplicateKeyException, IllegalAccessException {
+ // Mock
+ when(mockUserService.getUser(username)).thenReturn(null);
+
+ // Analyze
+ assertThrows(IllegalAccessException.class, () -> authService.login(username, password));
+ }
+
+ @Test
+ public void testLoginMismatchPasswords() throws IOException, DuplicateKeyException, IllegalAccessException {
+ // Mock
+ when(mockUserService.getUser(username)).thenReturn(User.create(username, "fries"));
+
+ // Analyze
+ assertThrows(IllegalAccessException.class, () -> authService.login(username, password));
+ }
+
+ @Test
+ public void testLogout() throws IOException, DuplicateKeyException, IllegalAccessException {
+ // Analyze
+ assertDoesNotThrow(() -> authService.logout(key));
+
+ }
+
+}