ClientAuthenticationTest_Success_MultiList_PostponePartialAccessAuthenticationMethod.cs 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_PostponePartialAccessAuthenticationMethod : ClientAuthenticationTestBase
  8. {
  9. private int _partialSuccessLimit;
  10. private ClientAuthentication _clientAuthentication;
  11. protected override void SetupData()
  12. {
  13. _partialSuccessLimit = 3;
  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)
  24. .Setup(p => p.Authenticate(SessionMock.Object))
  25. .Returns(AuthenticationResult.Failure);
  26. ConnectionInfoMock.InSequence(seq)
  27. .Setup(p => p.AuthenticationMethods)
  28. .Returns(new List<IAuthenticationMethod>
  29. {
  30. KeyboardInteractiveAuthenticationMethodMock.Object,
  31. PasswordAuthenticationMethodMock.Object,
  32. PublicKeyAuthenticationMethodMock.Object
  33. });
  34. NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications).Returns(new[] { "password" });
  35. KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive");
  36. PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password");
  37. PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey");
  38. PasswordAuthenticationMethodMock.InSequence(seq)
  39. .Setup(p => p.Authenticate(SessionMock.Object))
  40. .Returns(AuthenticationResult.PartialSuccess);
  41. PasswordAuthenticationMethodMock.InSequence(seq)
  42. .Setup(p => p.AllowedAuthentications)
  43. .Returns(new[] {"password", "publickey"});
  44. KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive");
  45. PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password");
  46. PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey");
  47. PublicKeyAuthenticationMethodMock.InSequence(seq)
  48. .Setup(p => p.Authenticate(SessionMock.Object))
  49. .Returns(AuthenticationResult.Failure);
  50. PublicKeyAuthenticationMethodMock.InSequence(seq)
  51. .Setup(p => p.Name)
  52. .Returns("publickey");
  53. PasswordAuthenticationMethodMock.InSequence(seq)
  54. .Setup(p => p.Authenticate(SessionMock.Object))
  55. .Returns(AuthenticationResult.Success);
  56. SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_FAILURE"));
  57. SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_SUCCESS"));
  58. SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_BANNER"));
  59. }
  60. protected override void Arrange()
  61. {
  62. base.Arrange();
  63. _clientAuthentication = new ClientAuthentication(_partialSuccessLimit);
  64. }
  65. protected override void Act()
  66. {
  67. _clientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object);
  68. }
  69. }
  70. }