diff options
Diffstat (limited to 'dotnet/Qpid.Sasl.Tests/Mechanisms')
5 files changed, 570 insertions, 570 deletions
diff --git a/dotnet/Qpid.Sasl.Tests/Mechanisms/AnonymousSaslClientTests.cs b/dotnet/Qpid.Sasl.Tests/Mechanisms/AnonymousSaslClientTests.cs index 09260736f0..5839f310e1 100644 --- a/dotnet/Qpid.Sasl.Tests/Mechanisms/AnonymousSaslClientTests.cs +++ b/dotnet/Qpid.Sasl.Tests/Mechanisms/AnonymousSaslClientTests.cs @@ -1,72 +1,72 @@ -/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-using System;
-using System.Collections;
-using System.Text;
-
-using NUnit.Framework;
-using Apache.Qpid.Sasl;
-using Apache.Qpid.Sasl.Mechanisms;
-
-namespace Apache.Qpid.Sasl.Tests.Mechanisms
-{
- [TestFixture]
- public class AnonymousSaslClientTests : ISaslCallbackHandler
- {
- private const string AUTHID = "nobody@nowhere.com";
-
- [Test]
- public void ReturnsRightMechanismName()
- {
- ISaslClient client = new AnonymousSaslClient(AUTHID, new Hashtable(), this);
-
- Assert.AreEqual("ANONYMOUS", client.MechanismName);
- }
-
- [Test]
- public void HasInitialResponseReturnsTrue()
- {
- ISaslClient client = new AnonymousSaslClient(AUTHID, new Hashtable(), this);
-
- Assert.IsTrue(client.HasInitialResponse);
- }
-
- [Test]
- public void CanEvaluateChallenge()
- {
- Hashtable props = new Hashtable();
- ISaslClient client = new AnonymousSaslClient(AUTHID, props, this);
-
- Assert.IsFalse(client.IsComplete);
- byte[] response = client.EvaluateChallenge(new byte[0]);
- Assert.AreEqual(AUTHID, Encoding.UTF8.GetString(response));
-
- Assert.IsTrue(client.IsComplete);
- }
-
- void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks)
- {
- }
-
- } // class AnonymousSaslClientTests
-
-} // namespace Apache.Qpid.Sasl.Tests.Mechanisms
+/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Collections; +using System.Text; + +using NUnit.Framework; +using Apache.Qpid.Sasl; +using Apache.Qpid.Sasl.Mechanisms; + +namespace Apache.Qpid.Sasl.Tests.Mechanisms +{ + [TestFixture] + public class AnonymousSaslClientTests : ISaslCallbackHandler + { + private const string AUTHID = "nobody@nowhere.com"; + + [Test] + public void ReturnsRightMechanismName() + { + ISaslClient client = new AnonymousSaslClient(AUTHID, new Hashtable(), this); + + Assert.AreEqual("ANONYMOUS", client.MechanismName); + } + + [Test] + public void HasInitialResponseReturnsTrue() + { + ISaslClient client = new AnonymousSaslClient(AUTHID, new Hashtable(), this); + + Assert.IsTrue(client.HasInitialResponse); + } + + [Test] + public void CanEvaluateChallenge() + { + Hashtable props = new Hashtable(); + ISaslClient client = new AnonymousSaslClient(AUTHID, props, this); + + Assert.IsFalse(client.IsComplete); + byte[] response = client.EvaluateChallenge(new byte[0]); + Assert.AreEqual(AUTHID, Encoding.UTF8.GetString(response)); + + Assert.IsTrue(client.IsComplete); + } + + void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks) + { + } + + } // class AnonymousSaslClientTests + +} // namespace Apache.Qpid.Sasl.Tests.Mechanisms diff --git a/dotnet/Qpid.Sasl.Tests/Mechanisms/CramMD5SaslClientTests.cs b/dotnet/Qpid.Sasl.Tests/Mechanisms/CramMD5SaslClientTests.cs index e8b0ae5468..baeeafb2d2 100644 --- a/dotnet/Qpid.Sasl.Tests/Mechanisms/CramMD5SaslClientTests.cs +++ b/dotnet/Qpid.Sasl.Tests/Mechanisms/CramMD5SaslClientTests.cs @@ -1,90 +1,90 @@ -/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-using System;
-using System.Collections;
-using System.Text;
-
-using NUnit.Framework;
-using Apache.Qpid.Sasl;
-using Apache.Qpid.Sasl.Mechanisms;
-
-namespace Apache.Qpid.Sasl.Tests.Mechanisms
-{
- [TestFixture]
- public class CramMD5SaslClientTests : ISaslCallbackHandler
- {
- private const string USERNAME = "testuser";
- private const string PASSWORD = "tanstaaftanstaaf";
- private const string AUTHID = "test";
-
- [Test]
- public void ReturnsRightMechanismName()
- {
- ISaslClient client = new CramMD5SaslClient(AUTHID, new Hashtable(), this);
-
- Assert.AreEqual("CRAM-MD5", client.MechanismName);
- }
-
- [Test]
- public void HasInitialResponseReturnsFalse()
- {
- ISaslClient client = new CramMD5SaslClient(AUTHID, new Hashtable(), this);
-
- Assert.IsFalse(client.HasInitialResponse);
- }
-
- [Test]
- public void CanEvaluateChallenge()
- {
- Hashtable props = new Hashtable();
-
- ISaslClient client = new CramMD5SaslClient(AUTHID, props, this);
-
- Assert.IsFalse(client.IsComplete);
-
- byte[] challenge =
- Encoding.UTF8.GetBytes("<1896.697170952@postoffice.reston.mci.net>");
- byte[] response = client.EvaluateChallenge(challenge);
- string[] parts = Encoding.UTF8.GetString(response).Split(' ');
-
- Assert.AreEqual(2, parts.Length);
- Assert.AreEqual(USERNAME, parts[0]);
- Assert.AreEqual("b913a602c7eda7a495b4e6e7334d3890", parts[1]);
- Assert.IsTrue(client.IsComplete);
- }
-
- void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks)
- {
- foreach ( ISaslCallback cb in callbacks )
- {
- if ( cb is NameCallback )
- {
- ((NameCallback)cb).Text = USERNAME;
- } else if ( cb is PasswordCallback )
- {
- ((PasswordCallback)cb).Text = PASSWORD;
- }
- }
- }
- } // class CramMD5SaslClientTests
-
-} // namespace Apache.Qpid.Sasl.Tests.Mechanisms
+/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Collections; +using System.Text; + +using NUnit.Framework; +using Apache.Qpid.Sasl; +using Apache.Qpid.Sasl.Mechanisms; + +namespace Apache.Qpid.Sasl.Tests.Mechanisms +{ + [TestFixture] + public class CramMD5SaslClientTests : ISaslCallbackHandler + { + private const string USERNAME = "testuser"; + private const string PASSWORD = "tanstaaftanstaaf"; + private const string AUTHID = "test"; + + [Test] + public void ReturnsRightMechanismName() + { + ISaslClient client = new CramMD5SaslClient(AUTHID, new Hashtable(), this); + + Assert.AreEqual("CRAM-MD5", client.MechanismName); + } + + [Test] + public void HasInitialResponseReturnsFalse() + { + ISaslClient client = new CramMD5SaslClient(AUTHID, new Hashtable(), this); + + Assert.IsFalse(client.HasInitialResponse); + } + + [Test] + public void CanEvaluateChallenge() + { + Hashtable props = new Hashtable(); + + ISaslClient client = new CramMD5SaslClient(AUTHID, props, this); + + Assert.IsFalse(client.IsComplete); + + byte[] challenge = + Encoding.UTF8.GetBytes("<1896.697170952@postoffice.reston.mci.net>"); + byte[] response = client.EvaluateChallenge(challenge); + string[] parts = Encoding.UTF8.GetString(response).Split(' '); + + Assert.AreEqual(2, parts.Length); + Assert.AreEqual(USERNAME, parts[0]); + Assert.AreEqual("b913a602c7eda7a495b4e6e7334d3890", parts[1]); + Assert.IsTrue(client.IsComplete); + } + + void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks) + { + foreach ( ISaslCallback cb in callbacks ) + { + if ( cb is NameCallback ) + { + ((NameCallback)cb).Text = USERNAME; + } else if ( cb is PasswordCallback ) + { + ((PasswordCallback)cb).Text = PASSWORD; + } + } + } + } // class CramMD5SaslClientTests + +} // namespace Apache.Qpid.Sasl.Tests.Mechanisms diff --git a/dotnet/Qpid.Sasl.Tests/Mechanisms/DigestSaslClientTests.cs b/dotnet/Qpid.Sasl.Tests/Mechanisms/DigestSaslClientTests.cs index eb7e7ebbd5..5a18ebaefd 100644 --- a/dotnet/Qpid.Sasl.Tests/Mechanisms/DigestSaslClientTests.cs +++ b/dotnet/Qpid.Sasl.Tests/Mechanisms/DigestSaslClientTests.cs @@ -1,249 +1,249 @@ -/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-using System;
-using System.Collections;
-using System.Collections.Specialized;
-using System.Text;
-
-using NUnit.Framework;
-using Apache.Qpid.Sasl;
-using Apache.Qpid.Sasl.Mechanisms;
-
-namespace Apache.Qpid.Sasl.Tests.Mechanisms
-{
- [TestFixture]
- public class DigestSaslClientTests : ISaslCallbackHandler
- {
- private const string USERNAME = "chris";
- private const string PASSWORD = "secret";
- private const string AUTHID = null;
- private const string PROTOCOL = "IMAP";
- private const string SERVERNAME = "elwood.innosoft.com";
-
- #region Digest Challenge Parsing Tests
- //
- // Digest Challenge Parsing Tests
- //
-
- [Test]
- public void CanParseSimpleString()
- {
- string challenge = "realm=\"elwood.innosoft.com\", algorithm=md5-sess";
- StringDictionary values = DigestChallenge.ParseParameters(challenge);
- Assert.AreEqual(2, values.Count);
- Assert.AreEqual("elwood.innosoft.com", values["realm"]);
- Assert.AreEqual("md5-sess", values["algorithm"]);
- }
-
- [Test]
- public void CanParseEscapedQuotes()
- {
- string challenge = "realm=\"elwood\\\".innosoft.com\", algorithm=md5-sess";
- StringDictionary values = DigestChallenge.ParseParameters(challenge);
- Assert.AreEqual(2, values.Count);
- Assert.AreEqual("elwood\\\".innosoft.com", values["realm"]);
- Assert.AreEqual("md5-sess", values["algorithm"]);
- }
-
- [Test]
- public void CanParseEmbeddedDelimiter()
- {
- string challenge = "realm=\"elwood,innosoft.com\", algorithm=md5-sess";
- StringDictionary values = DigestChallenge.ParseParameters(challenge);
- Assert.AreEqual(2, values.Count);
- Assert.AreEqual("elwood,innosoft.com", values["realm"]);
- Assert.AreEqual("md5-sess", values["algorithm"]);
- }
-
- [Test]
- public void CanParse1()
- {
- string challenge = "realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",algorithm=md5-sess,charset=utf-8";
- DigestChallenge parsed = DigestChallenge.Parse(challenge);
-
- Assert.AreEqual("elwood.innosoft.com", parsed.Realm);
- Assert.AreEqual("OA6MG9tEQGm2hh", parsed.Nonce);
- Assert.Contains("auth", parsed.QopOptions);
- Assert.AreEqual("md5-sess", parsed.Algorithm);
- Assert.AreEqual("utf-8", parsed.Charset);
- }
-
- #endregion // Digest Challenge Parsing Tests
-
-
- #region Digest Response Tests
- //
- // Digest Response Tests
- //
-
- [Test]
- public void CanWriteResponse()
- {
- DigestResponse resp = new DigestResponse();
- resp.Username = "user";
- resp.Realm = "nowhere.com";
- resp.Nonce = "OA9BSXrbuRhWay";
- resp.Cnonce = "OA9BSuZWMSpW8m";
- resp.NonceCount = 16;
- resp.DigestUri = "acap/elwood.innosoft.com";
- resp.Response = "6084c6db3fede7352c551284490fd0fc";
- resp.Qop = "auth";
- resp.MaxBuffer = 65536;
- resp.Cipher = "3des";
- resp.Authzid = "user2";
- resp.AuthParam = "ap";
- resp.Charset = "utf-8";
-
- string expected = "username=\"user\",realm=\"nowhere.com\",nonce=\"OA9BSXrbuRhWay\",cnonce=\"OA9BSuZWMSpW8m\",nc=00000010,qop=auth,digest-uri=\"acap/elwood.innosoft.com\",response=\"6084c6db3fede7352c551284490fd0fc\",maxbuf=65536,charset=utf-8,cipher=3des,authzid=\"user2\",auth-param=\"ap\"";
- Assert.AreEqual(expected, resp.ToString());
- }
-
- [Test]
- public void CanWriteEscapedSecuence()
- {
- DigestResponse resp = new DigestResponse();
- resp.Username = "us\"er";
-
- string expected = "username=\"us\\\"er\",nc=00000000,maxbuf=0";
- Assert.AreEqual(expected, resp.ToString());
- }
-
- #endregion // Digest Response Tests
-
-
- #region Authentication Tests
- //
- // Authentication Tests
- //
-
- [Test]
- public void ReturnsRightMechanismName()
- {
- ISaslClient client = CreateClient();
-
- Assert.AreEqual("DIGEST-MD5", client.MechanismName);
- }
-
- [Test]
- public void HasInitialResponseReturnsFalse()
- {
- ISaslClient client = CreateClient();
-
- Assert.IsFalse(client.HasInitialResponse);
- }
-
- [Test]
- public void CanAuthenticate()
- {
- string challenge = "realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",algorithm=md5-sess,charset=utf-8";
- DigestSaslClient client = CreateClient();
- client.Cnonce = "OA6MHXh6VqTrRk";
-
- byte[] bresp = client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge));
- string response = Encoding.UTF8.GetString(bresp);
- string expectedResp = "username=\"chris\",realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",cnonce=\"" +
- client.Cnonce + "\",nc=00000001,qop=auth,digest-uri=\"imap/elwood.innosoft.com\",response=\"d388dad90d4bbd760a152321f2143af7\",maxbuf=65536,charset=utf-8";
-
- Assert.AreEqual(expectedResp, response);
- Assert.IsFalse(client.IsComplete);
-
- string challenge2 = "rspauth=ea40f60335c427b5527b84dbabcdfffd";
- bresp = client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge2));
- // client responds with zero-length array
- Assert.AreEqual(0, bresp.Length);
- Assert.IsTrue(client.IsComplete);
- }
-
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void ThrowsExceptionWhenChallengeIsMissing()
- {
- DigestSaslClient client = CreateClient();
- client.EvaluateChallenge(null);
- }
-
-
- [Test]
- [ExpectedException(typeof(SaslException))]
- public void ThrowsExceptionWhenNonceMissing()
- {
- string challenge = "realm=\"elwood.innosoft.com\"";
- DigestSaslClient client = CreateClient();
-
- client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge));
- }
-
- [Test]
- [ExpectedException(typeof(SaslException))]
- public void ThrowsExceptionWhenAlgorithmMissing()
- {
- string challenge = "realm=\"elwood.innosoft.com\",nonce=\"asdasadsad\"";
- DigestSaslClient client = CreateClient();
-
- client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge));
- }
-
- [Test]
- [ExpectedException(typeof(SaslException))]
- public void ThrowsExceptionWhenSecondChallengeInvalid()
- {
- string challenge = "realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",algorithm=md5-sess,charset=utf-8";
- DigestSaslClient client = CreateClient();
-
- byte[] bresp = client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge));
- Encoding.UTF8.GetString(bresp);
-
- // repeat challenge 1, which is incorrect
- client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge));
- }
-
- private DigestSaslClient CreateClient()
- {
- return new DigestSaslClient(
- AUTHID, SERVERNAME, PROTOCOL,
- new Hashtable(), this
- );
- }
-
- void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks)
- {
- foreach ( ISaslCallback cb in callbacks )
- {
- if ( cb is NameCallback )
- {
- ((NameCallback)cb).Text = USERNAME;
- } else if ( cb is PasswordCallback )
- {
- ((PasswordCallback)cb).Text = PASSWORD;
- } else if ( cb is RealmCallback )
- {
- ((RealmCallback)cb).Text = SERVERNAME;
- }
- }
- }
-
- #endregion // Authentication Tests
-
-
- } // class DigestSaslClientTests
-
-} // namespace Apache.Qpid.Sasl.Tests.Mechanisms
+/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Collections; +using System.Collections.Specialized; +using System.Text; + +using NUnit.Framework; +using Apache.Qpid.Sasl; +using Apache.Qpid.Sasl.Mechanisms; + +namespace Apache.Qpid.Sasl.Tests.Mechanisms +{ + [TestFixture] + public class DigestSaslClientTests : ISaslCallbackHandler + { + private const string USERNAME = "chris"; + private const string PASSWORD = "secret"; + private const string AUTHID = null; + private const string PROTOCOL = "IMAP"; + private const string SERVERNAME = "elwood.innosoft.com"; + + #region Digest Challenge Parsing Tests + // + // Digest Challenge Parsing Tests + // + + [Test] + public void CanParseSimpleString() + { + string challenge = "realm=\"elwood.innosoft.com\", algorithm=md5-sess"; + StringDictionary values = DigestChallenge.ParseParameters(challenge); + Assert.AreEqual(2, values.Count); + Assert.AreEqual("elwood.innosoft.com", values["realm"]); + Assert.AreEqual("md5-sess", values["algorithm"]); + } + + [Test] + public void CanParseEscapedQuotes() + { + string challenge = "realm=\"elwood\\\".innosoft.com\", algorithm=md5-sess"; + StringDictionary values = DigestChallenge.ParseParameters(challenge); + Assert.AreEqual(2, values.Count); + Assert.AreEqual("elwood\\\".innosoft.com", values["realm"]); + Assert.AreEqual("md5-sess", values["algorithm"]); + } + + [Test] + public void CanParseEmbeddedDelimiter() + { + string challenge = "realm=\"elwood,innosoft.com\", algorithm=md5-sess"; + StringDictionary values = DigestChallenge.ParseParameters(challenge); + Assert.AreEqual(2, values.Count); + Assert.AreEqual("elwood,innosoft.com", values["realm"]); + Assert.AreEqual("md5-sess", values["algorithm"]); + } + + [Test] + public void CanParse1() + { + string challenge = "realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",algorithm=md5-sess,charset=utf-8"; + DigestChallenge parsed = DigestChallenge.Parse(challenge); + + Assert.AreEqual("elwood.innosoft.com", parsed.Realm); + Assert.AreEqual("OA6MG9tEQGm2hh", parsed.Nonce); + Assert.Contains("auth", parsed.QopOptions); + Assert.AreEqual("md5-sess", parsed.Algorithm); + Assert.AreEqual("utf-8", parsed.Charset); + } + + #endregion // Digest Challenge Parsing Tests + + + #region Digest Response Tests + // + // Digest Response Tests + // + + [Test] + public void CanWriteResponse() + { + DigestResponse resp = new DigestResponse(); + resp.Username = "user"; + resp.Realm = "nowhere.com"; + resp.Nonce = "OA9BSXrbuRhWay"; + resp.Cnonce = "OA9BSuZWMSpW8m"; + resp.NonceCount = 16; + resp.DigestUri = "acap/elwood.innosoft.com"; + resp.Response = "6084c6db3fede7352c551284490fd0fc"; + resp.Qop = "auth"; + resp.MaxBuffer = 65536; + resp.Cipher = "3des"; + resp.Authzid = "user2"; + resp.AuthParam = "ap"; + resp.Charset = "utf-8"; + + string expected = "username=\"user\",realm=\"nowhere.com\",nonce=\"OA9BSXrbuRhWay\",cnonce=\"OA9BSuZWMSpW8m\",nc=00000010,qop=auth,digest-uri=\"acap/elwood.innosoft.com\",response=\"6084c6db3fede7352c551284490fd0fc\",maxbuf=65536,charset=utf-8,cipher=3des,authzid=\"user2\",auth-param=\"ap\""; + Assert.AreEqual(expected, resp.ToString()); + } + + [Test] + public void CanWriteEscapedSecuence() + { + DigestResponse resp = new DigestResponse(); + resp.Username = "us\"er"; + + string expected = "username=\"us\\\"er\",nc=00000000,maxbuf=0"; + Assert.AreEqual(expected, resp.ToString()); + } + + #endregion // Digest Response Tests + + + #region Authentication Tests + // + // Authentication Tests + // + + [Test] + public void ReturnsRightMechanismName() + { + ISaslClient client = CreateClient(); + + Assert.AreEqual("DIGEST-MD5", client.MechanismName); + } + + [Test] + public void HasInitialResponseReturnsFalse() + { + ISaslClient client = CreateClient(); + + Assert.IsFalse(client.HasInitialResponse); + } + + [Test] + public void CanAuthenticate() + { + string challenge = "realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",algorithm=md5-sess,charset=utf-8"; + DigestSaslClient client = CreateClient(); + client.Cnonce = "OA6MHXh6VqTrRk"; + + byte[] bresp = client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge)); + string response = Encoding.UTF8.GetString(bresp); + string expectedResp = "username=\"chris\",realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",cnonce=\"" + + client.Cnonce + "\",nc=00000001,qop=auth,digest-uri=\"imap/elwood.innosoft.com\",response=\"d388dad90d4bbd760a152321f2143af7\",maxbuf=65536,charset=utf-8"; + + Assert.AreEqual(expectedResp, response); + Assert.IsFalse(client.IsComplete); + + string challenge2 = "rspauth=ea40f60335c427b5527b84dbabcdfffd"; + bresp = client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge2)); + // client responds with zero-length array + Assert.AreEqual(0, bresp.Length); + Assert.IsTrue(client.IsComplete); + } + + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void ThrowsExceptionWhenChallengeIsMissing() + { + DigestSaslClient client = CreateClient(); + client.EvaluateChallenge(null); + } + + + [Test] + [ExpectedException(typeof(SaslException))] + public void ThrowsExceptionWhenNonceMissing() + { + string challenge = "realm=\"elwood.innosoft.com\""; + DigestSaslClient client = CreateClient(); + + client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge)); + } + + [Test] + [ExpectedException(typeof(SaslException))] + public void ThrowsExceptionWhenAlgorithmMissing() + { + string challenge = "realm=\"elwood.innosoft.com\",nonce=\"asdasadsad\""; + DigestSaslClient client = CreateClient(); + + client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge)); + } + + [Test] + [ExpectedException(typeof(SaslException))] + public void ThrowsExceptionWhenSecondChallengeInvalid() + { + string challenge = "realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",algorithm=md5-sess,charset=utf-8"; + DigestSaslClient client = CreateClient(); + + byte[] bresp = client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge)); + Encoding.UTF8.GetString(bresp); + + // repeat challenge 1, which is incorrect + client.EvaluateChallenge(Encoding.UTF8.GetBytes(challenge)); + } + + private DigestSaslClient CreateClient() + { + return new DigestSaslClient( + AUTHID, SERVERNAME, PROTOCOL, + new Hashtable(), this + ); + } + + void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks) + { + foreach ( ISaslCallback cb in callbacks ) + { + if ( cb is NameCallback ) + { + ((NameCallback)cb).Text = USERNAME; + } else if ( cb is PasswordCallback ) + { + ((PasswordCallback)cb).Text = PASSWORD; + } else if ( cb is RealmCallback ) + { + ((RealmCallback)cb).Text = SERVERNAME; + } + } + } + + #endregion // Authentication Tests + + + } // class DigestSaslClientTests + +} // namespace Apache.Qpid.Sasl.Tests.Mechanisms diff --git a/dotnet/Qpid.Sasl.Tests/Mechanisms/ExternalSaslClientTests.cs b/dotnet/Qpid.Sasl.Tests/Mechanisms/ExternalSaslClientTests.cs index 1864a6c957..57efcf7614 100644 --- a/dotnet/Qpid.Sasl.Tests/Mechanisms/ExternalSaslClientTests.cs +++ b/dotnet/Qpid.Sasl.Tests/Mechanisms/ExternalSaslClientTests.cs @@ -1,71 +1,71 @@ -/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-using System;
-using System.Collections;
-using System.Text;
-
-using NUnit.Framework;
-using Apache.Qpid.Sasl;
-using Apache.Qpid.Sasl.Mechanisms;
-
-namespace Apache.Qpid.Sasl.Tests.Mechanisms
-{
- [TestFixture]
- public class ExternalSaslClientTests : ISaslCallbackHandler
- {
- private const string AUTHID = "nobody@nowhere.com";
-
- [Test]
- public void ReturnsRightMechanismName()
- {
- ISaslClient client = new ExternalSaslClient(AUTHID, new Hashtable(), this);
-
- Assert.AreEqual("EXTERNAL", client.MechanismName);
- }
-
- [Test]
- public void HasInitialResponseReturnsTrue()
- {
- ISaslClient client = new ExternalSaslClient(AUTHID, new Hashtable(), this);
-
- Assert.IsTrue(client.HasInitialResponse);
- }
-
- [Test]
- public void CanEvaluateChallenge()
- {
- ISaslClient client = new ExternalSaslClient(AUTHID, new Hashtable(), this);
-
- Assert.IsFalse(client.IsComplete);
- byte[] response = client.EvaluateChallenge(new byte[0]);
- Assert.AreEqual(AUTHID, Encoding.UTF8.GetString(response));
-
- Assert.IsTrue(client.IsComplete);
- }
-
- void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks)
- {
- }
-
- } // class AnonymousSaslClientTests
-
-} // namespace Apache.Qpid.Sasl.Tests.Mechanisms
+/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Collections; +using System.Text; + +using NUnit.Framework; +using Apache.Qpid.Sasl; +using Apache.Qpid.Sasl.Mechanisms; + +namespace Apache.Qpid.Sasl.Tests.Mechanisms +{ + [TestFixture] + public class ExternalSaslClientTests : ISaslCallbackHandler + { + private const string AUTHID = "nobody@nowhere.com"; + + [Test] + public void ReturnsRightMechanismName() + { + ISaslClient client = new ExternalSaslClient(AUTHID, new Hashtable(), this); + + Assert.AreEqual("EXTERNAL", client.MechanismName); + } + + [Test] + public void HasInitialResponseReturnsTrue() + { + ISaslClient client = new ExternalSaslClient(AUTHID, new Hashtable(), this); + + Assert.IsTrue(client.HasInitialResponse); + } + + [Test] + public void CanEvaluateChallenge() + { + ISaslClient client = new ExternalSaslClient(AUTHID, new Hashtable(), this); + + Assert.IsFalse(client.IsComplete); + byte[] response = client.EvaluateChallenge(new byte[0]); + Assert.AreEqual(AUTHID, Encoding.UTF8.GetString(response)); + + Assert.IsTrue(client.IsComplete); + } + + void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks) + { + } + + } // class AnonymousSaslClientTests + +} // namespace Apache.Qpid.Sasl.Tests.Mechanisms diff --git a/dotnet/Qpid.Sasl.Tests/Mechanisms/PlainSaslClientTests.cs b/dotnet/Qpid.Sasl.Tests/Mechanisms/PlainSaslClientTests.cs index 4c82f7b126..f4fc00e038 100644 --- a/dotnet/Qpid.Sasl.Tests/Mechanisms/PlainSaslClientTests.cs +++ b/dotnet/Qpid.Sasl.Tests/Mechanisms/PlainSaslClientTests.cs @@ -1,88 +1,88 @@ -/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-using System;
-using System.Collections;
-using System.Text;
-
-using NUnit.Framework;
-using Apache.Qpid.Sasl;
-using Apache.Qpid.Sasl.Mechanisms;
-
-namespace Apache.Qpid.Sasl.Tests.Mechanisms
-{
- [TestFixture]
- public class PlainSaslClientTests : ISaslCallbackHandler
- {
- private const string USERNAME = "testuser";
- private const string PASSWORD = "thepasswd";
- private const string AUTHID = "theauth";
-
- [Test]
- public void ReturnsRightMechanismName()
- {
- ISaslClient client = new PlainSaslClient(AUTHID, new Hashtable(), this);
-
- Assert.AreEqual("PLAIN", client.MechanismName);
- }
-
- [Test]
- public void HasInitialResponseReturnsTrue()
- {
- ISaslClient client = new PlainSaslClient(AUTHID, new Hashtable(), this);
-
- Assert.IsTrue(client.HasInitialResponse);
- }
-
- [Test]
- public void CanEvaluateChallenge()
- {
- Hashtable props = new Hashtable();
- ISaslClient client = new PlainSaslClient(AUTHID, props, this);
-
- Assert.IsFalse(client.IsComplete);
- byte[] response = client.EvaluateChallenge(new byte[0]);
- string[] parts = Encoding.UTF8.GetString(response).Split('\0');
-
- Assert.AreEqual(3, parts.Length);
- Assert.AreEqual(AUTHID, parts[0]);
- Assert.AreEqual(USERNAME, parts[1]);
- Assert.AreEqual(PASSWORD, parts[2]);
- Assert.IsTrue(client.IsComplete);
- }
-
- void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks)
- {
- foreach ( ISaslCallback cb in callbacks )
- {
- if ( cb is NameCallback )
- {
- ((NameCallback)cb).Text = USERNAME;
- } else if ( cb is PasswordCallback )
- {
- ((PasswordCallback)cb).Text = PASSWORD;
- }
- }
- }
-
- } // class PlainSaslClientTests
-
-} // namespace Apache.Qpid.Sasl.Tests.Mechanisms
+/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Collections; +using System.Text; + +using NUnit.Framework; +using Apache.Qpid.Sasl; +using Apache.Qpid.Sasl.Mechanisms; + +namespace Apache.Qpid.Sasl.Tests.Mechanisms +{ + [TestFixture] + public class PlainSaslClientTests : ISaslCallbackHandler + { + private const string USERNAME = "testuser"; + private const string PASSWORD = "thepasswd"; + private const string AUTHID = "theauth"; + + [Test] + public void ReturnsRightMechanismName() + { + ISaslClient client = new PlainSaslClient(AUTHID, new Hashtable(), this); + + Assert.AreEqual("PLAIN", client.MechanismName); + } + + [Test] + public void HasInitialResponseReturnsTrue() + { + ISaslClient client = new PlainSaslClient(AUTHID, new Hashtable(), this); + + Assert.IsTrue(client.HasInitialResponse); + } + + [Test] + public void CanEvaluateChallenge() + { + Hashtable props = new Hashtable(); + ISaslClient client = new PlainSaslClient(AUTHID, props, this); + + Assert.IsFalse(client.IsComplete); + byte[] response = client.EvaluateChallenge(new byte[0]); + string[] parts = Encoding.UTF8.GetString(response).Split('\0'); + + Assert.AreEqual(3, parts.Length); + Assert.AreEqual(AUTHID, parts[0]); + Assert.AreEqual(USERNAME, parts[1]); + Assert.AreEqual(PASSWORD, parts[2]); + Assert.IsTrue(client.IsComplete); + } + + void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks) + { + foreach ( ISaslCallback cb in callbacks ) + { + if ( cb is NameCallback ) + { + ((NameCallback)cb).Text = USERNAME; + } else if ( cb is PasswordCallback ) + { + ((PasswordCallback)cb).Text = PASSWORD; + } + } + } + + } // class PlainSaslClientTests + +} // namespace Apache.Qpid.Sasl.Tests.Mechanisms |