### Question:
SecurityUtil { static String getKeytabURIforPrincipal(String principal, CConfiguration cConf) throws IOException { String confPath = cConf.getRaw(Constants.Security.KEYTAB_PATH); Preconditions.checkNotNull(confPath, String.format("Failed to get a valid keytab path. " + "Please ensure that you have specified %s in cdap-site.xml", Constants.Security.KEYTAB_PATH)); String name = new KerberosName(principal).getShortName(); return confPath.replace(Constants.USER_NAME_SPECIFIER, name); } private  SecurityUtil(); static void enableKerberosLogin(CConfiguration cConf); @Nullable static String expandPrincipal(@Nullable String principal); static boolean isKerberosEnabled(CConfiguration cConf); static String getMasterPrincipal(CConfiguration cConf); static String getMasterKeytabURI(CConfiguration cConf); static void loginForMasterService(CConfiguration cConf); static KerberosName getKerberosName(KerberosPrincipalId principalId); static void validateKerberosPrincipal(KerberosPrincipalId principalId); static void validateKerberosPrincipal(String principal); static ImpersonationInfo createImpersonationInfo(OwnerAdmin ownerAdmin, CConfiguration cConf,
                                                          NamespacedEntityId entityId); static void verifyOwnerPrincipal(NamespacedEntityId existingEntity,
                                          @Nullable String specifiedOwnerPrincipal,
                                          OwnerAdmin ownerAdmin); @Nullable static KerberosPrincipalId getEffectiveOwner(OwnerAdmin ownerAdmin, NamespaceId namespaceId,
                                                      @Nullable String ownerPrincipal);  }### Answer:
@Test public void testGetKeytabURIforUser() throws IOException { String user = "alice"; String confPath = "/dir1/dir2/${name}/${name}.keytab"; String expectedPath = "/dir1/dir2/alice/alice.keytab"; CConfiguration cConf = CConfiguration.create(); cConf.set(Constants.Security.KEYTAB_PATH, confPath); cConf.set("user", "blah blah"); String path = SecurityUtil.getKeytabURIforPrincipal(user, cConf); Assert.assertEquals(expectedPath, path); }
@Test public void testNoKeytabPath() throws IOException { String user = "alice"; CConfiguration cConf = CConfiguration.create(); try { SecurityUtil.getKeytabURIforPrincipal(user, cConf); Assert.fail(); } catch (NullPointerException e) { Assert.assertTrue(e.getMessage().contains(Constants.Security.KEYTAB_PATH)); } }