public async Task PasswordList() { ExecuteResponse result; using (var testManager = new KubeTestManager()) { using (var runner = new ProgramRunner()) { // Verify that [help] works: result = await runner.ExecuteAsync(Program.Main, "help", "tool", "password", "list"); Assert.Equal(0, result.ExitCode); Assert.Contains("Lists passwords.", result.OutputText); // Add a few passwords: result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "one", "tool", "password", "set", "pwd-1", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "two", "tool", "password", "set", "pwd-2", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "three", "tool", "password", "set", "pwd-3", "-"); Assert.Equal(0, result.ExitCode); // Verify that we can list via: list result = await runner.ExecuteAsync(Program.Main, "tool", "password", "list"); Assert.Equal(0, result.ExitCode); TestHelper.AssertEqualLines( @"pwd-1 pwd-2 pwd-3 ", result.OutputText); // Verify that we can list via: ls result = await runner.ExecuteAsync(Program.Main, "tool", "password", "ls"); Assert.Equal(0, result.ExitCode); TestHelper.AssertEqualLines( @"pwd-1 pwd-2 pwd-3 ", result.OutputText); } } }
public async Task PasswordImportExport() { const string zipPassword = "******"; ExecuteResponse result; using (var testManager = new KubeTestManager()) { using (var runner = new ProgramRunner()) { // Verify that [help] works: result = await runner.ExecuteAsync(Program.Main, "help", "tool", "password", "import"); Assert.Equal(0, result.ExitCode); Assert.Contains("Imports passwords from an encrypted ZIP file.", result.OutputText); // Verify that [import] checks the PATH argument. result = await runner.ExecuteAsync(Program.Main, "tool", "password", "import"); Assert.NotEqual(0, result.ExitCode); Assert.Contains("PATH argument is required.", result.ErrorText); // Verify that [help] works: result = await runner.ExecuteAsync(Program.Main, "help", "tool", "password", "export"); Assert.Equal(0, result.ExitCode); Assert.Contains("Exports selected passwords to an encrypted ZIP file.", result.OutputText); // Verify that [export] checks the PATH argument. result = await runner.ExecuteAsync(Program.Main, "tool", "password", "export"); Assert.NotEqual(0, result.ExitCode); Assert.Contains("PATH argument is required.", result.ErrorText); // Verify that [export] checks the NAME argument. result = await runner.ExecuteAsync(Program.Main, "tool", "password", "export", "test.zip"); Assert.NotEqual(0, result.ExitCode); Assert.Contains("At least one NAME argument is required.", result.ErrorText); // Add a few passwords: result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "one", "tool", "password", "set", "pwd-1", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "two", "tool", "password", "set", "pwd-2", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "three", "tool", "password", "set", "pwd-3", "-"); Assert.Equal(0, result.ExitCode); // Export all passwords to a ZIP file: var zipPath = Path.Combine(testManager.TestFolder, "passwords.zip"); result = await runner.ExecuteWithInputAsync(Program.Main, zipPassword, "tool", "password", "export", "--stdin", zipPath, "*"); Assert.Equal(0, result.ExitCode); Assert.True(File.Exists(zipPath)); // Remove all passwords, import the passwords using a zip password file, and verify. result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, zipPassword, "tool", "password", "import", "--stdin", zipPath); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-1"); Assert.Equal(0, result.ExitCode); Assert.Equal("one", result.OutputText.Trim()); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-2"); Assert.Equal(0, result.ExitCode); Assert.Equal("two", result.OutputText.Trim()); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-3"); Assert.Equal(0, result.ExitCode); Assert.Equal("three", result.OutputText.Trim()); // Export two of the three passwords to a ZIP file: result = await runner.ExecuteWithInputAsync(Program.Main, zipPassword, "tool", "password", "export", "--stdin", zipPath, "pwd-1", "pwd-2"); Assert.Equal(0, result.ExitCode); Assert.True(File.Exists(zipPath)); // Remove all passwords, import the passwords using a zip password file, and verify. result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, zipPassword, "tool", "password", "import", "--stdin", zipPath); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-1"); Assert.Equal(0, result.ExitCode); Assert.Equal("one", result.OutputText.Trim()); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-2"); Assert.Equal(0, result.ExitCode); Assert.Equal("two", result.OutputText.Trim()); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-3"); Assert.NotEqual(0, result.ExitCode); // This one wasn't exported. } } }
public async Task PasswordSet() { ExecuteResponse result; using (var testManager = new KubeTestManager()) { using (var runner = new ProgramRunner()) { // Verify that [help] works: result = await runner.ExecuteAsync(Program.Main, "help", "tool", "password", "set"); Assert.Equal(0, result.ExitCode); Assert.Contains("Creates or modifies a named password.", result.OutputText); // Add a few passwords via files and verify: File.WriteAllText(Path.Combine(testManager.TestFolder, "pwd-1"), "one"); File.WriteAllText(Path.Combine(testManager.TestFolder, "pwd-2"), "two"); File.WriteAllText(Path.Combine(testManager.TestFolder, "pwd-3"), "three"); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "set", "pwd-1", Path.Combine(testManager.TestFolder, "pwd-1")); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "set", "pwd-2", Path.Combine(testManager.TestFolder, "pwd-2")); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "set", "pwd-3", Path.Combine(testManager.TestFolder, "pwd-3")); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-1"); Assert.Equal(0, result.ExitCode); Assert.Equal("one", result.OutputText.Trim()); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-2"); Assert.Equal(0, result.ExitCode); Assert.Equal("two", result.OutputText.Trim()); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-3"); Assert.Equal(0, result.ExitCode); Assert.Equal("three", result.OutputText.Trim()); // Verify that we can set a password from STDIN: result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "one", "tool", "password", "set", "pwd-1", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "two", "tool", "password", "set", "pwd-2", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "three", "tool", "password", "set", "pwd-3", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-1"); Assert.Equal(0, result.ExitCode); Assert.Equal("one", result.OutputText.Trim()); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-2"); Assert.Equal(0, result.ExitCode); Assert.Equal("two", result.OutputText.Trim()); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-3"); Assert.Equal(0, result.ExitCode); Assert.Equal("three", result.OutputText.Trim()); // Verify that we can update a password. result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "one", "tool", "password", "set", "pwd-1", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-1"); Assert.Equal(0, result.ExitCode); Assert.Equal("one", result.OutputText.Trim()); result = await runner.ExecuteWithInputAsync(Program.Main, "1", "tool", "password", "set", "pwd-1", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "pwd-1"); Assert.Equal(0, result.ExitCode); Assert.Equal("1", result.OutputText.Trim()); // Verify that password names with all possible character classes works: result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "password", "tool", "password", "set", "a.1_2-3", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "a.1_2-3"); Assert.Equal(0, result.ExitCode); Assert.Equal("password", result.OutputText.Trim()); // Verify that a 20 character password is generated when no PATH argument is passed: result = await runner.ExecuteWithInputAsync(Program.Main, "password", "tool", "password", "set", "abc"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteAsync(Program.Main, "tool", "password", "get", "abc"); Assert.Equal(0, result.ExitCode); Assert.Equal(20, result.OutputText.Trim().Length); // Verify that we see errors for missing arguments: result = await runner.ExecuteWithInputAsync(Program.Main, "password", "tool", "password", "set"); Assert.NotEqual(0, result.ExitCode); Assert.Contains("NAME argument is required.", result.ErrorText); // Verify that password name error checking works: result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "", "tool", "password", "set", "pwd@1", "-"); Assert.NotEqual(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "", "tool", "password", "set", $"{new string('a', 101)}", "-"); Assert.NotEqual(0, result.ExitCode); // Verify that password length error checking works: result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "", "tool", "password", "set", "pwd-1", "-"); Assert.NotEqual(0, result.ExitCode); } } }