feat(tickets): public ticket request, order page and gateway paths

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-04 15:53:54 +08:00
1 parent a18ca0db71
commit d25641e139
8 files changed
+569 -2

No files matched your search

@@ -0,0 +1,84 @@
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.HttpMethod;
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;
/** add-event-ticket-orders: a ticket request, an order by its link token and the on-sale ticket types are open; staff ticket calls stay closed. */
class JWTAuthFilterTicketsPathTest {
private static final String KEY = "gateway-test-key";
private JWTAuthFilter filter;
@BeforeEach
void setUp() throws Exception {
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 call(HttpMethod method, String path) {
return MockServerWebExchange.from(MockServerHttpRequest.method(method, 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 publicTicketCallsNeedNoUserToken() {
for (String[] c : new String[][] {
{"POST", "/counter/ticketOrder/request"},
{"GET", "/counter/ticketOrder/byToken/abcdefghijklmnopqrstu_"},
{"GET", "/counter/ticketType/onSale/3312726793093644288"} }) {
assertThat(passes(call(HttpMethod.valueOf(c[0]), c[1]))).as(c[0] + " " + c[1]).isTrue();
}
}
@Test
void everythingElseAboutTicketsNeedsAUserToken() {
for (String[] c : new String[][] {
{"GET", "/counter/ticketOrder/request"},
{"POST", "/counter/ticketOrder/request/x"},
{"GET", "/counter/ticketOrder/byToken/short"},
{"GET", "/counter/ticketOrder/byToken/abcdefghijklmnopqrstuvw"},
{"POST", "/counter/ticketOrder/byToken/abcdefghijklmnopqrstu_"},
{"GET", "/counter/ticketType/onSale/x"},
{"GET", "/counter/ticketType/onSale/12345678901234567890"},
{"POST", "/counter/ticketType/list"},
{"POST", "/counter/ticketType/settings"},
{"POST", "/counter/ticketOrder/list"},
{"POST", "/counter/ticketOrder/markPaid"} }) {
MockServerWebExchange exchange = call(HttpMethod.valueOf(c[0]), c[1]);
assertThat(passes(exchange)).as(c[0] + " " + c[1]).isFalse();
assertThat(exchange.getResponse().getStatusCode()).as(c[0] + " " + c[1]).isEqualTo(HttpStatus.UNAUTHORIZED);
}
}
}