@Test
public void testCheckWritePublicBucketWithAuthorizedUserAndAuthorizedProxyChain() {

    final NiFiUser user = USER_WITH_PROXY_CHAIN;
    final RequestAction action = RequestAction.WRITE;
    // first request will be to authorize the proxy
    final AuthorizationRequest expectedProxyAuthorizationRequest = getProxyAuthorizationRequest(action, user.getChain());
    when(authorizer.authorize(argThat(new AuthorizationRequestMatcher(expectedProxyAuthorizationRequest))))
            .thenReturn(AuthorizationResult.approved());
    // second request will be to the specific bucket
    final AuthorizationRequest expectedBucketAuthorizationRequest = getBucketAuthorizationRequest(
            bucketPublic.getIdentifier(), action, user);
    when(authorizer.authorize(argThat(new AuthorizationRequestMatcher(expectedBucketAuthorizationRequest))))
            .thenReturn(AuthorizationResult.approved());
    // the authorization should all return approved
    final Authorizable bucketAuthorizable = authorizableLookup.getBucketAuthorizable(bucketPublic.getIdentifier());
    final AuthorizationResult result = bucketAuthorizable.checkAuthorization(authorizer, action, user);
    assertNotNull(result);
    assertEquals(AuthorizationResult.Result.Approved, result.getResult());
    // Should call authorizer two times for /proxy and /bucket/{id}
    verify(authorizer, times(2)).authorize(any(AuthorizationRequest.class));
}