public SafeTokenHandle DoLogon(IActivityIOPath path) { var lpszUsername = OperationsHelper.ExtractUserName(path); var lpszDomain = OperationsHelper.ExtractDomain(path); var lpszPassword = path.Password; var lpszPath = path.Path; try { var loggedOn = _loginApi.LogonUser(lpszUsername, lpszDomain, lpszPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out SafeTokenHandle safeToken); if (loggedOn) { return(safeToken); } loggedOn = _loginApi.LogonUser(lpszUsername, lpszDomain, lpszPassword, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_WINNT50, out SafeTokenHandle safeTokenHandle); if (loggedOn) { return(safeTokenHandle); } } catch (Exception ex) { Dev2Logger.Error(ex.Message, ex, GlobalConstants.WarewolfError); } finally { var ex = Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); Dev2Logger.Info(ex.Message, GlobalConstants.Warewolf); } throw new Exception(string.Format(ErrorResource.FailedToAuthenticateUser, lpszUsername, lpszPath)); }
public void OperationsHelper_ExtractUserName_With_Domain1() { const string userName = "******"; const string expectedUserName = "******"; var mockPathAuth = new Mock <IPathAuth>(); mockPathAuth.Setup(pathAuth => pathAuth.Username).Returns(userName); var operationsHelper = OperationsHelper.ExtractUserName(mockPathAuth.Object); Assert.AreEqual(expectedUserName, operationsHelper); }
public void OperationsHelper_ExtractUserName_ExpectedException() { OperationsHelper.ExtractUserName(null); }