< Summary

Information
Class: Renci.SshNet.NoneAuthenticationMethod
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\NoneAuthenticationMethod.cs
Line coverage
59%
Covered lines: 35
Uncovered lines: 24
Coverable lines: 59
Total lines: 133
Line coverage: 59.3%
Branch coverage
40%
Covered branches: 4
Total branches: 10
Branch coverage: 40%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Name()100%1100%
Authenticate(...)50%287.5%
Session_UserAuthenticationSuccessReceived(...)100%10%
Session_UserAuthenticationFailureReceived(...)50%272.72%
Dispose()100%10%
Dispose(...)33.33%626.66%
Finalize()100%1100%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\NoneAuthenticationMethod.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3
 4using Renci.SshNet.Messages;
 5using Renci.SshNet.Messages.Authentication;
 6
 7namespace Renci.SshNet
 8{
 9    /// <summary>
 10    /// Provides functionality for "none" authentication method.
 11    /// </summary>
 12    public class NoneAuthenticationMethod : AuthenticationMethod, IDisposable
 13    {
 163314        private AuthenticationResult _authenticationResult = AuthenticationResult.Failure;
 163315        private EventWaitHandle _authenticationCompleted = new AutoResetEvent(initialState: false);
 16        private bool _isDisposed;
 17
 18        /// <summary>
 19        /// Gets the name of the authentication method.
 20        /// </summary>
 21        public override string Name
 22        {
 923            get { return "none"; }
 24        }
 25
 26        /// <summary>
 27        /// Initializes a new instance of the <see cref="NoneAuthenticationMethod"/> class.
 28        /// </summary>
 29        /// <param name="username">The username.</param>
 30        /// <exception cref="ArgumentException"><paramref name="username"/> is whitespace or <see langword="null"/>.</ex
 31        public NoneAuthenticationMethod(string username)
 163332            : base(username)
 162733        {
 162734        }
 35
 36        /// <summary>
 37        /// Authenticates the specified session.
 38        /// </summary>
 39        /// <param name="session">The session.</param>
 40        /// <returns>
 41        /// Result of authentication  process.
 42        /// </returns>
 43        /// <exception cref="ArgumentNullException"><paramref name="session" /> is <see langword="null"/>.</exception>
 44        public override AuthenticationResult Authenticate(Session session)
 119845        {
 119846            if (session is null)
 047            {
 048                throw new ArgumentNullException(nameof(session));
 49            }
 50
 119851            session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived;
 119852            session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived;
 53
 54            try
 119855            {
 119856                session.SendMessage(new RequestMessageNone(ServiceName.Connection, Username));
 119857                session.WaitOnHandle(_authenticationCompleted);
 119758            }
 59            finally
 119860            {
 119861                session.UserAuthenticationSuccessReceived -= Session_UserAuthenticationSuccessReceived;
 119862                session.UserAuthenticationFailureReceived -= Session_UserAuthenticationFailureReceived;
 119863            }
 64
 119765            return _authenticationResult;
 119766        }
 67
 68        private void Session_UserAuthenticationSuccessReceived(object sender, MessageEventArgs<SuccessMessage> e)
 069        {
 070            _authenticationResult = AuthenticationResult.Success;
 71
 072            _ = _authenticationCompleted.Set();
 073        }
 74
 75        private void Session_UserAuthenticationFailureReceived(object sender, MessageEventArgs<FailureMessage> e)
 119776        {
 119777            if (e.Message.PartialSuccess)
 078            {
 079                _authenticationResult = AuthenticationResult.PartialSuccess;
 080            }
 81            else
 119782            {
 119783                _authenticationResult = AuthenticationResult.Failure;
 119784            }
 85
 86            // Copy allowed authentication methods
 119787            AllowedAuthentications = e.Message.AllowedAuthentications;
 88
 119789            _ = _authenticationCompleted.Set();
 119790        }
 91
 92        /// <summary>
 93        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 94        /// </summary>
 95        public void Dispose()
 096        {
 097            Dispose(disposing: true);
 098            GC.SuppressFinalize(this);
 099        }
 100
 101        /// <summary>
 102        /// Releases unmanaged and - optionally - managed resources.
 103        /// </summary>
 104        /// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langwor
 105        protected virtual void Dispose(bool disposing)
 1631106        {
 1631107            if (_isDisposed)
 0108            {
 0109                return;
 110            }
 111
 1631112            if (disposing)
 0113            {
 0114                var authenticationCompleted = _authenticationCompleted;
 0115                if (authenticationCompleted != null)
 0116                {
 0117                    authenticationCompleted.Dispose();
 0118                    _authenticationCompleted = null;
 0119                }
 120
 0121                _isDisposed = true;
 0122            }
 1631123        }
 124
 125        /// <summary>
 126        /// Finalizes an instance of the <see cref="NoneAuthenticationMethod"/> class.
 127        /// </summary>
 128        ~NoneAuthenticationMethod()
 3262129        {
 1631130            Dispose(disposing: false);
 3262131        }
 132    }
 133}