public virtual void TestGetServerPrincipal() { string service = "TestKerberosUtil"; string localHostname = KerberosUtil.GetLocalHostName(); string testHost = "FooBar"; // send null hostname Assert.Equal("When no hostname is sent", service + "/" + localHostname .ToLower(Extensions.GetEnglishCulture()), KerberosUtil.GetServicePrincipal (service, null)); // send empty hostname Assert.Equal("When empty hostname is sent", service + "/" + localHostname .ToLower(Extensions.GetEnglishCulture()), KerberosUtil.GetServicePrincipal (service, string.Empty)); // send 0.0.0.0 hostname Assert.Equal("When 0.0.0.0 hostname is sent", service + "/" + localHostname.ToLower(Extensions.GetEnglishCulture()), KerberosUtil.GetServicePrincipal (service, "0.0.0.0")); // send uppercase hostname Assert.Equal("When uppercase hostname is sent", service + "/" + testHost.ToLower(Extensions.GetEnglishCulture()), KerberosUtil.GetServicePrincipal (service, testHost)); // send lowercase hostname Assert.Equal("When lowercase hostname is sent", service + "/" + testHost.ToLower(Extensions.GetEnglishCulture()), KerberosUtil.GetServicePrincipal (service, testHost.ToLower(Extensions.GetEnglishCulture()))); }
public virtual void TestGetPrincipalNamesMissingKeytab() { try { KerberosUtil.GetPrincipalNames(testKeytab); NUnit.Framework.Assert.Fail("Exception should have been thrown"); } catch (IOException) { } }
public virtual void TestGetPrincipalNamesMissingPattern() { CreateKeyTab(testKeytab, new string[] { "test/testhost@testRealm" }); try { KerberosUtil.GetPrincipalNames(testKeytab, null); NUnit.Framework.Assert.Fail("Exception should have been thrown"); } catch (Exception) { } }
static KerberosName() { try { defaultRealm = KerberosUtil.GetDefaultRealm(); } catch (Exception) { Log.Debug("Kerberos krb5 configuration not found, setting default realm to empty" ); defaultRealm = string.Empty; } }
public virtual void TestGetPrincipalNamesFromKeytab() { CreateKeyTab(testKeytab, testPrincipals); // read all principals in the keytab file string[] principals = KerberosUtil.GetPrincipalNames(testKeytab); NUnit.Framework.Assert.IsNotNull("principals cannot be null", principals); int expectedSize = 0; IList <string> principalList = Arrays.AsList(principals); foreach (string principal in testPrincipals) { Assert.True("missing principal " + principal, principalList.Contains (principal)); expectedSize++; } Assert.Equal(expectedSize, principals.Length); }
public virtual void TestGetPrincipalNamesFromKeytabWithPattern() { 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); NUnit.Framework.Assert.IsNotNull("principals cannot be null", httpPrincipals); int expectedSize = 0; IList <string> httpPrincipalList = Arrays.AsList(httpPrincipals); foreach (string principal in testPrincipals) { if (httpPattern.Matcher(principal).Matches()) { Assert.True("missing principal " + principal, httpPrincipalList .Contains(principal)); expectedSize++; } } Assert.Equal(expectedSize, httpPrincipals.Length); }