### Question:
SecurityUtil { public static void tryProxy(Entity entity, final String doAsUser) throws IOException, FalconException { if (entity != null && entity.getACL() != null && SecurityUtil.isAuthorizationEnabled()) { final String aclOwner = entity.getACL().getOwner(); final String aclGroup = entity.getACL().getGroup(); if (StringUtils.isNotEmpty(doAsUser)) { if (!doAsUser.equalsIgnoreCase(aclOwner)) { LOG.warn("doAs user {} not same as acl owner {}. Ignoring acl owner.", doAsUser, aclOwner); throw new FalconException("doAs user and ACL owner mismatch. doAs user " + doAsUser + " should be same as ACL owner " + aclOwner); } return; } if (SecurityUtil.getAuthorizationProvider().shouldProxy( CurrentUser.getAuthenticatedUGI(), aclOwner, aclGroup)) { CurrentUser.proxy(aclOwner, aclGroup); } } } private  SecurityUtil(); static String getAuthenticationType(); static boolean isSecurityEnabled(); static String getLocalHostName(); static boolean isAuthorizationEnabled(); static boolean isCSRFFilterEnabled(); static AuthorizationProvider getAuthorizationProvider(); static void tryProxy(Entity entity, final String doAsUser); static final String AUTHENTICATION_TYPE; static final String NN_PRINCIPAL; static final String RM_PRINCIPAL; static final String HIVE_METASTORE_KERBEROS_PRINCIPAL; static final String METASTORE_USE_THRIFT_SASL; static final String METASTORE_PRINCIPAL; }### Answer:
@Test public void testTryProxy() throws IOException, FalconException { Process process = Mockito.mock(Process.class); StartupProperties.get().setProperty("falcon.security.authorization.enabled", "true"); final String currentUser = System.getProperty("user.name"); CurrentUser.authenticate(currentUser); SecurityUtil.tryProxy(process, ""); Assert.assertEquals(CurrentUser.getUser(), currentUser); ACL acl = new ACL(); acl.setOwner(FalconTestUtil.TEST_USER_2); acl.setGroup("users"); Mockito.when(process.getACL()).thenReturn(acl); SecurityUtil.tryProxy(process, ""); Assert.assertEquals(CurrentUser.getUser(), FalconTestUtil.TEST_USER_2); }
@Test (expectedExceptions = FalconException.class, expectedExceptionsMessageRegExp = "doAs user and ACL owner mismatch.*") public void testTryProxyWithDoAsUser() throws IOException, FalconException { Process process = Mockito.mock(Process.class); StartupProperties.get().setProperty("falcon.security.authorization.enabled", "true"); final String currentUser = "foo"; ACL acl = new ACL(); acl.setOwner(FalconTestUtil.TEST_USER_2); acl.setGroup("users"); Mockito.when(process.getACL()).thenReturn(acl); CurrentUser.authenticate(currentUser); CurrentUser.proxyDoAsUser("doAsUser", "localhost"); Assert.assertEquals(CurrentUser.getUser(), "doAsUser"); SecurityUtil.tryProxy(process, "doAsUser"); }