暂存提交

This commit is contained in:
2026-08-19 16:24:02 +08:00
parent f5c4bf130a
commit 6acb6178da
354 changed files with 25000 additions and 198 deletions
@@ -0,0 +1,32 @@
package com.baiyue.warehouse.security;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class InternalServiceTokenGuardTest {
private final InternalServiceTokenGuard guard =
new InternalServiceTokenGuard("phase1-local-internal-token-at-least-32-bytes");
@Test
void acceptsConfiguredToken() {
assertThatCode(() -> guard.verify("phase1-local-internal-token-at-least-32-bytes"))
.doesNotThrowAnyException();
}
@Test
void rejectsMissingOrWrongToken() {
assertUnauthorized(null);
assertUnauthorized("wrong");
}
private void assertUnauthorized(String token) {
assertThatThrownBy(() -> guard.verify(token))
.isInstanceOfSatisfying(ResponseStatusException.class,
error -> assertThat(error.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED));
}
}