public virtual void TestAnonymousAllowed() { AuthenticatorTestCase auth = new AuthenticatorTestCase(); AuthenticatorTestCase.SetAuthenticationHandlerConfig(GetAuthenticationHandlerConfiguration (true)); auth.Start(); try { Uri url = new Uri(auth.GetBaseURL()); HttpURLConnection conn = (HttpURLConnection)url.OpenConnection(); conn.Connect(); Assert.Equal(HttpURLConnection.HttpOk, conn.GetResponseCode()); } finally { auth.Stop(); } }
/// <exception cref="System.Exception"/> public virtual void TestNotAuthenticated() { AuthenticatorTestCase auth = new AuthenticatorTestCase(useTomcat); AuthenticatorTestCase.SetAuthenticationHandlerConfig(GetAuthenticationHandlerConfiguration ()); auth.Start(); try { Uri url = new Uri(auth.GetBaseURL()); HttpURLConnection conn = (HttpURLConnection)url.OpenConnection(); conn.Connect(); Assert.Equal(HttpURLConnection.HttpUnauthorized, conn.GetResponseCode ()); Assert.True(conn.GetHeaderField(KerberosAuthenticator.WwwAuthenticate ) != null); } finally { auth.Stop(); } }
public virtual void TestAnonymousDisallowed() { AuthenticatorTestCase auth = new AuthenticatorTestCase(); AuthenticatorTestCase.SetAuthenticationHandlerConfig(GetAuthenticationHandlerConfiguration (false)); auth.Start(); try { Uri url = new Uri(auth.GetBaseURL()); HttpURLConnection conn = (HttpURLConnection)url.OpenConnection(); conn.Connect(); Assert.Equal(HttpURLConnection.HttpUnauthorized, conn.GetResponseCode ()); Assert.True(conn.GetHeaderFields().Contains("WWW-Authenticate") ); Assert.Equal("Authentication required", conn.GetResponseMessage ()); } finally { auth.Stop(); } }