@Test public void testGetPrincipalNamesFromKeytabWithPattern() throws IOException { createKeyTab(testKeytab, testPrincipals); // read the keytab file // look for principals with HTTP as the first part Pattern httpPattern = Pattern.compile("HTTP/.*"); String[] httpPrincipals = KerberosUtil.getPrincipalNames(testKeytab, httpPattern); Assert.assertNotNull("principals cannot be null", httpPrincipals); int expectedSize = 0; List<String> httpPrincipalList = Arrays.asList(httpPrincipals); for (String principal : testPrincipals) { if (httpPattern.matcher(principal).matches()) { Assert.assertTrue("missing principal "+principal, httpPrincipalList.contains(principal)); expectedSize++; } } Assert.assertEquals(expectedSize, httpPrincipals.length); }
@Test public void testGetPrincipalNamesFromKeytabWithPattern() throws IOException { createKeyTab(testKeytab, testPrincipals); // read the keytab file // look for principals with HTTP as the first part Pattern httpPattern = Pattern.compile("HTTP/.*"); String[] httpPrincipals = KerberosUtil.getPrincipalNames(testKeytab, httpPattern); Assert.assertNotNull("principals cannot be null", httpPrincipals); int expectedSize = 0; List<String> httpPrincipalList = Arrays.asList(httpPrincipals); for (String principal : testPrincipals) { if (httpPattern.matcher(principal).matches()) { Assert.assertTrue("missing principal "+principal, httpPrincipalList.contains(principal)); expectedSize++; } } Assert.assertEquals(expectedSize, httpPrincipals.length); }
@Test public void testGetPrincipalNamesMissingPattern() throws IOException { createKeyTab(testKeytab, new String[]{"test/testhost@testRealm"}); try { KerberosUtil.getPrincipalNames(testKeytab, null); Assert.fail("Exception should have been thrown"); } catch (Exception e) { //expects exception } }
@Test public void testGetPrincipalNamesMissingPattern() throws IOException { createKeyTab(testKeytab, new String[]{"test/testhost@testRealm"}); try { KerberosUtil.getPrincipalNames(testKeytab, null); Assert.fail("Exception should have been thrown"); } catch (Exception e) { //expects exception } }
@Test public void testGetPrincipalNamesFromKeytabWithPattern() throws IOException { createKeyTab(testKeytab, testPrincipals); // read the keytab file // look for principals with HTTP as the first part Pattern httpPattern = Pattern.compile("HTTP/.*"); String[] httpPrincipals = KerberosUtil.getPrincipalNames(testKeytab, httpPattern); Assert.assertNotNull("principals cannot be null", httpPrincipals); int expectedSize = 0; List<String> httpPrincipalList = Arrays.asList(httpPrincipals); for (String principal : testPrincipals) { if (httpPattern.matcher(principal).matches()) { Assert.assertTrue("missing principal "+principal, httpPrincipalList.contains(principal)); expectedSize++; } } Assert.assertEquals(expectedSize, httpPrincipals.length); }
@Test public void testGetPrincipalNamesMissingPattern() throws IOException { createKeyTab(testKeytab, new String[]{"test/testhost@testRealm"}); try { KerberosUtil.getPrincipalNames(testKeytab, null); Assert.fail("Exception should have been thrown"); } catch (Exception e) { //expects exception } }
@Test public void testGetPrincipalNamesFromKeytab() throws IOException { createKeyTab(testKeytab, testPrincipals); // read all principals in the keytab file String[] principals = KerberosUtil.getPrincipalNames(testKeytab); Assert.assertNotNull("principals cannot be null", principals); int expectedSize = 0; List<String> principalList = Arrays.asList(principals); for (String principal : testPrincipals) { Assert.assertTrue("missing principal "+principal, principalList.contains(principal)); expectedSize++; } Assert.assertEquals(expectedSize, principals.length); }
@Test public void testGetPrincipalNamesFromKeytab() throws IOException { createKeyTab(testKeytab, testPrincipals); // read all principals in the keytab file String[] principals = KerberosUtil.getPrincipalNames(testKeytab); Assert.assertNotNull("principals cannot be null", principals); int expectedSize = 0; List<String> principalList = Arrays.asList(principals); for (String principal : testPrincipals) { Assert.assertTrue("missing principal "+principal, principalList.contains(principal)); expectedSize++; } Assert.assertEquals(expectedSize, principals.length); }
@Test public void testGetPrincipalNamesFromKeytab() throws IOException { createKeyTab(testKeytab, testPrincipals); // read all principals in the keytab file String[] principals = KerberosUtil.getPrincipalNames(testKeytab); Assert.assertNotNull("principals cannot be null", principals); int expectedSize = 0; List<String> principalList = Arrays.asList(principals); for (String principal : testPrincipals) { Assert.assertTrue("missing principal "+principal, principalList.contains(principal)); expectedSize++; } Assert.assertEquals(expectedSize, principals.length); }