feat(mobile-api): admin guard on /api/admin/** (admin token, session state, module grants)
Ported from babyboo: @AdminModule, AdminModuleAccess, AdminSessionGuard and the admin branch of AppAccessAspect. Adds the BO area, and services-auth findUserByToken now returns no user for a logged-out token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
72b724f468
commit
0a990cbcaf
16 files changed
+850
-8
No files matched your search
+43
@@ -0,0 +1,43 @@
|
||||
package com.solvway.mobile.api.service;
|
||||
|
||||
import com.solvway.core.model.User;
|
||||
import com.solvway.mobile.api.util.RestTemplateCustomUtil;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
class AdminAuthenticationServiceTest {
|
||||
|
||||
private RestTemplateCustomUtil rest;
|
||||
private AdminAuthenticationService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
rest = mock(RestTemplateCustomUtil.class);
|
||||
service = new AdminAuthenticationService(rest);
|
||||
when(rest.getURLforApiService(any())).thenReturn("http://auth/findUserByToken/{area}/{token}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void liveToken_loadsUserInBoArea() {
|
||||
User u = new User();
|
||||
when(rest.getForEntity(any(String.class), eq(User.class), eq("BO"), eq("tok")))
|
||||
.thenReturn(ResponseEntity.ok(u));
|
||||
assertThat(service.loadUserByToken("tok")).isSameAs(u);
|
||||
}
|
||||
|
||||
@Test
|
||||
void non200_returnsNull() {
|
||||
when(rest.getForEntity(any(String.class), eq(User.class), eq("BO"), eq("tok")))
|
||||
.thenReturn(new ResponseEntity<>(HttpStatus.NO_CONTENT));
|
||||
assertThat(service.loadUserByToken("tok")).isNull();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user