Esempio n. 1
0
        private void AuthenticateSpecificMechanism(NetworkCredential credential)
        {
            using (var server = new PopPseudoServer()) {
            server.Start();

            var prof = new Profile(new NetworkCredential("pop-user", (string)null), "pop", server.HostPort);

            prof.UsingSaslMechanisms = new[] {"LOGIN", "PLAIN", "ANONYMOUS", "DIGEST-MD5", "CRAM-MD5"};
            prof.AllowInsecureLogin = true;

            // greeting
            server.EnqueueResponse("+OK ready\r\n");
            // CAPABILITY response
            server.EnqueueResponse("+OK\r\n" +
                               ".\r\n");
            // AUTH X-PSEUDO-MECHANISM response
            server.EnqueueResponse("+\r\n");
            server.EnqueueResponse("+OK\r\n");

            using (var authMechanism = new SaslPseudoMechanism(false, 1)) {
              authMechanism.Credential = credential;

              using (var session = PopSessionCreator.CreateSession(prof, authMechanism, null)) {
            Assert.AreEqual(PopSessionState.Transaction, session.State);

            if (credential == null)
              Assert.AreEqual(new Uri(string.Format("pop://AUTH=X-PSEUDO-MECHANISM@{0}/", server.HostPort)),
                              session.Authority);
            else
              Assert.AreEqual(new Uri(string.Format("pop://sasl-user;AUTH=X-PSEUDO-MECHANISM@{0}/", server.HostPort)),
                              session.Authority);
              }

              Assert.AreSame(credential,
                         authMechanism.Credential,
                         "credential must be kept");

              Assert.AreEqual(Smdn.Security.Authentication.Sasl.SaslExchangeStatus.Succeeded,
                          authMechanism.ExchangeStatus);
            }

            server.DequeueRequest(); // CAPABILITY
            StringAssert.Contains("AUTH X-PSEUDO-MECHANISM", server.DequeueRequest());
              }
        }
 public void TestAuthSpecificMechanismWithNoCredential()
 {
     using (var authMechanism = new SaslPseudoMechanism(false, 2)) {
     AuthSpecificMechanism(authMechanism);
       }
 }
        public void TestAuthSpecificMechanismAlreadyExchanged()
        {
            using (var authMechanism = new SaslPseudoMechanism(false, 2)) {
            byte[] clientResponse;

            authMechanism.Exchange(null, out clientResponse);

            Assert.AreNotEqual(SaslExchangeStatus.None,
                           authMechanism.ExchangeStatus);

            AuthSpecificMechanism(authMechanism);
              }
        }
        public void TestAuthSpecificMechanismClientFirst()
        {
            using (var authMechanism = new SaslPseudoMechanism(true, 2)) {
            authMechanism.Credential = new NetworkCredential("user", (string)null);

            AuthSpecificMechanism(authMechanism);
              }
        }
Esempio n. 5
0
        public void TestConnectWithSpecifiedSaslMechanism()
        {
            using (var server = new PopPseudoServer()) {
            server.Start();

            using (var client = new PopClient(server.Host, server.Port)) {
              // greeting
              server.EnqueueResponse("+OK\r\n");
              // CAPA
              server.EnqueueResponse("+OK\r\n" +
                                 ".\r\n");
              // AUTH X-PSEUDO-MECHANISM
              server.EnqueueResponse("+ \r\n");
              server.EnqueueResponse("+OK\r\n");

              using (var authMechanism = new SaslPseudoMechanism(false, 1)) {
            client.Connect(authMechanism);

            Assert.AreEqual(Smdn.Security.Authentication.Sasl.SaslExchangeStatus.Succeeded,
                            authMechanism.ExchangeStatus);
              }

              Assert.IsTrue(client.IsConnected);
              Assert.IsFalse(client.IsSecureSession);
              Assert.IsNotNull(client.ServerCapabilities);
              Assert.IsNull((client.Profile as IPopSessionProfile).Credentials);
            }
              }
        }