mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
perf(core): parse the credential scope in the account filter only when needed (#7772)
AccountContextFilter runs on every request. It parsed the signing service from the Authorization header twice, but only a refusal or strict partition mode reads it. It also parsed the scope region once more just to look for a ':'. That region is part of the header or a published region, so a header without ':' cannot name one.
This commit is contained in:
1 parent
4e5c60cd58
commit
fd7cc8477e
2 files changed
+38
-18
No files matched your search
@@ -27,6 +27,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -48,7 +49,7 @@ class AccountContextFilterTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
accountResolver = new AccountResolver(DEFAULT_ACCOUNT);
|
||||
regionResolver = new RegionResolver(DEFAULT_REGION, DEFAULT_ACCOUNT);
|
||||
regionResolver = spy(new RegionResolver(DEFAULT_REGION, DEFAULT_ACCOUNT));
|
||||
requestContext = new RequestContext();
|
||||
sessionAccounts = new HashMap<>();
|
||||
allowUnknownRegions = false;
|
||||
@@ -156,6 +157,15 @@ class AccountContextFilterTest {
|
||||
assertEquals("us-west-2", requestContext.getRegion());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aHeaderWithoutAColonIsNotParsedForAnAmbiguousRegion() {
|
||||
filter.filter(mockContext(
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20261015/us-west-2/sqs/aws4_request, SignedHeaders=host, Signature=abc",
|
||||
null));
|
||||
assertEquals("us-west-2", requestContext.getRegion());
|
||||
verify(regionResolver, never()).resolveRegionFromAuthOrNull(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesFromPresignedCredentialWhenNoAuthHeader() {
|
||||
ContainerRequestContext ctx = mockContext(null,
|
||||
|
||||
Reference in new issue
Block a user