Esempio n. 1
0
        public void ChangePasswordForNonRootUser(String ipAddress, String username, String password, String newPassword)
        {
            var linuxPasswordChanger = new LinuxPasswordChanger();

            Assert.DoesNotThrow(() => linuxPasswordChanger.ChangePassword(ipAddress, username, password, newPassword));
            Assert.DoesNotThrow(() => linuxPasswordChanger.ChangePassword(ipAddress, username, newPassword, password));
        }
Esempio n. 2
0
        public void ChangePasswordForNonRootUserThrowsException(String ipAddress, String username, String password, String newPassword, String expectedExceptionMessage)
        {
            var linuxPasswordChanger = new LinuxPasswordChanger();
            var exception            = Assert.Throws <Exception>(() => linuxPasswordChanger.ChangePassword(ipAddress, username, password, newPassword));

            Assert.That(exception.Message, Is.EqualTo(expectedExceptionMessage));
        }
        private ToolStripMenuItem createChangePasswordMenuItem(HostPwEntry hostPwEntry)
        {
            IPasswordChanger pwChanger = null;
            var hostTypeMapper         = new HostTypeMapper(new HostTypeSafeConverter());
            var hostType = hostTypeMapper.Get(hostPwEntry);

            if (hostType == HostType.ESXi && QuickConnectUtils.IsVSpherePowerCLIInstalled())
            {
                pwChanger = new ESXiPasswordChanger();
            }
            else if (hostType == HostType.Windows &&
                     !String.IsNullOrEmpty(this.Settings.PsPasswdPath) &&
                     File.Exists(this.Settings.PsPasswdPath) &&
                     PsPasswdWrapper.IsPsPasswdUtility(this.Settings.PsPasswdPath) &&
                     PsPasswdWrapper.IsSupportedVersion(this.Settings.PsPasswdPath)
                     )
            {
                pwChanger = new WindowsPasswordChanger(new PsPasswdWrapper(this.Settings.PsPasswdPath));
            }
            else if (hostType == HostType.Linux)
            {
                PuttyOptions puttyOptions = null;
                bool         success      = PuttyOptionsParser.TryParse(hostPwEntry.AdditionalOptions, out puttyOptions);
                // Disable change password menu item if authentication is done using SSH key file.
                if (!success || (success && !puttyOptions.HasKeyFile()))
                {
                    int?sshPort = null;
                    if (success)
                    {
                        sshPort = puttyOptions.Port;
                    }
                    pwChanger = new LinuxPasswordChanger()
                    {
                        SshPort = sshPort
                    };
                }
            }
            var menuItem = new ToolStripMenuItem()
            {
                Text    = ChangePasswordMenuItemText,
                Enabled = hostPwEntry.HasIPAddress && pwChanger != null
            };

            menuItem.Click += new EventHandler(
                delegate(object obj, EventArgs ev) {
                try {
                    var pwDatabase       = new PasswordDatabase(this.pluginHost.Database);
                    var pwChangerService = new PasswordChangerServiceWrapper(pwDatabase, pwChanger);
                    using (var formPasswordChange = new FormPasswordChanger(hostPwEntry, pwChangerService)) {
                        formPasswordChange.ShowDialog();
                    }
                }
                catch (Exception ex) {
                    log(ex);
                }
            }
                );
            return(menuItem);
        }