fix(gateway): let admin forgot-password reach services-system without a user token
Found in the browser check: forgot-password always failed with 401 at the gateway, so no temporary password was ever sent. 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
b2e0a17790
commit
ad4713094a
2 files changed
+68
No files matched your search
@@ -131,6 +131,8 @@ public class JWTAuthFilter implements GlobalFilter, Ordered {
|
||||
|| url.contains("/actuator/") || url.contains("/message/")
|
||||
|| url.contains("/appInitialize/") || url.contains("/blockLoginPeriod/")
|
||||
|| url.contains("/member/forgetPassword")
|
||||
// Co-Lite admin forgot password (public; answers the same whether or not details match)
|
||||
|| url.equals("/user/resetAdminPassword")
|
||||
|| url.contains("/geoLocationHierarchy/findByFirstLevelLocation")
|
||||
|| url.contains("/geoLocationHierarchy/findAllByParentId")
|
||||
// public content - no JWT required
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.solvway.gateway.filter;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.solvway.gateway.model.AuthAppKey;
|
||||
import com.solvway.gateway.model.AuthAppKeyMap;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.mock.web.server.MockServerWebExchange;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/** Admin forgot-password reaches services-system without a user token; other user endpoints still need one. */
|
||||
class JWTAuthFilterPublicPathTest {
|
||||
|
||||
private static final String KEY = "gateway-test-key";
|
||||
|
||||
private JWTAuthFilter filter;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
// Built the way AuthAppKeyConfig loads appkeys.json (the constructor is not public).
|
||||
AuthAppKey key = new ObjectMapper().readValue(
|
||||
"{\"key\":\"" + KEY + "\",\"type\":\"BO\",\"ipList\":[\"0.0.0.0/0\"],\"allowList\":[\"/\"]}",
|
||||
AuthAppKey.class);
|
||||
AuthAppKeyMap map = new AuthAppKeyMap();
|
||||
map.add(KEY, key);
|
||||
filter = new JWTAuthFilter();
|
||||
ReflectionTestUtils.setField(filter, "authAppKeyMap", map);
|
||||
}
|
||||
|
||||
private MockServerWebExchange post(String path) {
|
||||
return MockServerWebExchange.from(MockServerHttpRequest.post(path)
|
||||
.header("api-key", KEY)
|
||||
.remoteAddress(new InetSocketAddress("127.0.0.1", 40000)));
|
||||
}
|
||||
|
||||
private boolean passes(MockServerWebExchange exchange) {
|
||||
AtomicBoolean called = new AtomicBoolean(false);
|
||||
GatewayFilterChain chain = ex -> {
|
||||
called.set(true);
|
||||
return Mono.empty();
|
||||
};
|
||||
filter.filter(exchange, chain).block();
|
||||
return called.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAdminPasswordNeedsNoUserToken() {
|
||||
assertThat(passes(post("/user/resetAdminPassword"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void otherUserEndpointsStillNeedAToken() {
|
||||
MockServerWebExchange exchange = post("/user/save");
|
||||
assertThat(passes(exchange)).isFalse();
|
||||
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user