コード例 #1
0
        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())));
        }
コード例 #2
0
 public virtual void TestGetPrincipalNamesMissingKeytab()
 {
     try
     {
         KerberosUtil.GetPrincipalNames(testKeytab);
         NUnit.Framework.Assert.Fail("Exception should have been thrown");
     }
     catch (IOException)
     {
     }
 }
コード例 #3
0
 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)
     {
     }
 }
コード例 #4
0
 static KerberosName()
 {
     try
     {
         defaultRealm = KerberosUtil.GetDefaultRealm();
     }
     catch (Exception)
     {
         Log.Debug("Kerberos krb5 configuration not found, setting default realm to empty"
                   );
         defaultRealm = string.Empty;
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }