fix(gateway): let the public QR registration reach its backend calls
A visitor has no user token, so the gateway refused every call the public page makes. Open only the exact method and path pairs it needs, and replace the full user lookup with a yes/no activeAdminOf endpoint so no user record is exposed. 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
1a7c542f5e
commit
eff4899c0d
8 files changed
+329
-10
No files matched your search
+69
@@ -0,0 +1,69 @@
|
||||
package com.solvway.services.system.controller;
|
||||
|
||||
import com.solvway.core.enums.UserEnum.UserType;
|
||||
import com.solvway.services.system.model.User;
|
||||
import com.solvway.services.system.service.UserService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class UserControllerActiveAdminOfTest {
|
||||
|
||||
@Mock private UserService userService;
|
||||
@InjectMocks private UserController controller;
|
||||
|
||||
private void stored(UserType type, Long companyId, boolean enabled) {
|
||||
User u = new User();
|
||||
u.setType(type);
|
||||
u.setCompanyId(companyId);
|
||||
u.setEnabled(enabled);
|
||||
when(userService.findById(7L)).thenReturn(Optional.of(u));
|
||||
}
|
||||
|
||||
@Test
|
||||
void enabledAdminOfTheCompany_isTrue() {
|
||||
stored(UserType.A, 2L, true);
|
||||
assertThat(controller.activeAdminOf(7L, 2L)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void otherCompany_isFalse() {
|
||||
stored(UserType.A, 3L, true);
|
||||
assertThat(controller.activeAdminOf(7L, 2L)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void companylessAdmin_isFalse() {
|
||||
stored(UserType.A, null, true);
|
||||
assertThat(controller.activeAdminOf(7L, 2L)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void disabled_isFalse() {
|
||||
stored(UserType.A, 2L, false);
|
||||
assertThat(controller.activeAdminOf(7L, 2L)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonAdminType_isFalse() {
|
||||
stored(UserType.D, 2L, true);
|
||||
assertThat(controller.activeAdminOf(7L, 2L)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownUser_isFalse() {
|
||||
when(userService.findById(8L)).thenReturn(Optional.empty());
|
||||
assertThat(controller.activeAdminOf(8L, 2L)).isFalse();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user