ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess.cs 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections.Generic;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Moq;
  4. namespace Renci.SshNet.Tests.Classes
  5. {
  6. [TestClass]
  7. public class ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess : ClientAuthenticationTestBase
  8. {
  9. private int _partialSuccessLimit;
  10. private ClientAuthentication _clientAuthentication;
  11. protected override void SetupData()
  12. {
  13. _partialSuccessLimit = 1;
  14. }
  15. protected override void SetupMocks()
  16. {
  17. var seq = new MockSequence();
  18. SessionMock.InSequence(seq).Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_FAILURE"));
  19. SessionMock.InSequence(seq).Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS"));
  20. SessionMock.InSequence(seq).Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_BANNER"));
  21. ConnectionInfoMock.InSequence(seq).Setup(p => p.CreateNoneAuthenticationMethod())
  22. .Returns(NoneAuthenticationMethodMock.Object);
  23. NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object))
  24. .Returns(AuthenticationResult.Failure);
  25. ConnectionInfoMock.InSequence(seq).Setup(p => p.AuthenticationMethods)
  26. .Returns(new List<IAuthenticationMethod>
  27. {
  28. PasswordAuthenticationMethodMock.Object,
  29. PublicKeyAuthenticationMethodMock.Object,
  30. KeyboardInteractiveAuthenticationMethodMock.Object,
  31. });
  32. NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications).Returns(new[] { "password", "publickey" });
  33. PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password");
  34. PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey");
  35. KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive");
  36. PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object))
  37. .Returns(AuthenticationResult.PartialSuccess);
  38. PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications)
  39. .Returns(new[] {"password", "publickey"});
  40. PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password");
  41. PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey");
  42. KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive");
  43. PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)).Returns(AuthenticationResult.PartialSuccess);
  44. PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications)
  45. .Returns(new[] { "password", "publickey", "keyboard-interactive" });
  46. PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password");
  47. PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey");
  48. KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive");
  49. KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object))
  50. .Returns(AuthenticationResult.Success);
  51. SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_FAILURE"));
  52. SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_SUCCESS"));
  53. SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_BANNER"));
  54. }
  55. protected override void Arrange()
  56. {
  57. base.Arrange();
  58. _clientAuthentication = new ClientAuthentication(_partialSuccessLimit);
  59. }
  60. protected override void Act()
  61. {
  62. _clientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object);
  63. }
  64. }
  65. }