|
@ -3,6 +3,8 @@ package de.fd.fh.server.access.web; |
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
import de.fd.fh.server.access.AccessService; |
|
|
import de.fd.fh.server.access.AccessService; |
|
|
import de.fd.fh.server.access.AccessToken; |
|
|
import de.fd.fh.server.access.AccessToken; |
|
|
|
|
|
import de.fd.fh.server.access.Role; |
|
|
|
|
|
import de.fd.fh.server.user.UserId; |
|
|
import de.fd.fh.shared.network.messages.LoginRequest; |
|
|
import de.fd.fh.shared.network.messages.LoginRequest; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
@ -14,6 +16,7 @@ import spark.Response; |
|
|
import spark.Session; |
|
|
import spark.Session; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
@ -197,4 +200,26 @@ class AccessControllerTest |
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
assertEquals(Integer.valueOf(400), statusCaptor.getValue(), "Should return Status code 400."); |
|
|
assertEquals(Integer.valueOf(400), statusCaptor.getValue(), "Should return Status code 400."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void testBefore() |
|
|
|
|
|
{ |
|
|
|
|
|
final AccessToken dummy = new AccessToken("TestToken", LocalDateTime.now(), Role.USER, UserId.random()); |
|
|
|
|
|
|
|
|
|
|
|
when(request.pathInfo()).thenReturn("/test/path"); |
|
|
|
|
|
when(request.headers(any())).thenReturn("TestAuthHeader"); |
|
|
|
|
|
when(request.session()).thenReturn(session); |
|
|
|
|
|
when(service.before(any(), any())) |
|
|
|
|
|
.thenReturn(dummy); |
|
|
|
|
|
|
|
|
|
|
|
final ArgumentCaptor<AccessToken> captor = ArgumentCaptor.forClass(AccessToken.class); |
|
|
|
|
|
|
|
|
|
|
|
new AccessController(service).before(request); |
|
|
|
|
|
|
|
|
|
|
|
verify(session).attribute(any(), captor.capture()); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(dummy, captor.getValue(), "Should store Token in Session"); |
|
|
|
|
|
then(service).should().before(any(), any()); |
|
|
|
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |