暂存提交
This commit is contained in:
+32
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user