13 lines
665 B
Java
13 lines
665 B
Java
package com.baiyue.lastleg.security;
|
|||
|
|
import org.junit.jupiter.api.Test;
|
||
|
|
import org.springframework.web.server.ResponseStatusException;
|
||
|
|
import static org.junit.jupiter.api.Assertions.*;
|
||
|
|
class InternalServiceTokenGuardTest {
|
||
|
|
@Test void acceptsOnlyConfiguredToken() {
|
||
|
|
InternalServiceTokenGuard guard=new InternalServiceTokenGuard("secret-token");
|
||
|
|
assertDoesNotThrow(()->guard.verify("secret-token"));
|
||
|
|
assertEquals(401,assertThrows(ResponseStatusException.class,()->guard.verify("wrong")).getStatusCode().value());
|
||
|
|
assertEquals(401,assertThrows(ResponseStatusException.class,()->guard.verify(null)).getStatusCode().value());
|
||
|
|
}
|
||
|
|
}
|