@Test
public void testAuthorizeWritePublicBucketWithUnauthorizedProxyChain() {

    final RequestAction action = RequestAction.WRITE;
    // first request will be to authorize the proxy
    final AuthorizationRequest expectedProxyAuthorizationRequest = getProxyAuthorizationRequest(action, USER_WITH_PROXY_CHAIN.getChain());
    when(authorizer.authorize(argThat(new AuthorizationRequestMatcher(expectedProxyAuthorizationRequest))))
            .thenReturn(AuthorizationResult.denied());
    // the authorization of the proxy chain should throw UntrustedProxyException
    final Authorizable bucketAuthorizable = authorizableLookup.getBucketAuthorizable(bucketPublic.getIdentifier());
    try {
        bucketAuthorizable.authorize(authorizer, action, USER_WITH_PROXY_CHAIN);
        Assert.fail("Should have thrown exception");
    } catch (UntrustedProxyException e) {
        // Should call authorizer once for /proxy and then throw exception
        verify(authorizer, times(1)).authorize(any(AuthorizationRequest.class));
    }
}