예제 #1
0
        public void PasswordList()
        {
            ExecuteResponse result;

            using (var manager = new KubeTestManager())
            {
                using (var runner = new ProgramRunner())
                {
                    // Verify that [--help] works:

                    result = runner.Execute(Program.Main, "password", "list", "--help");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Contains("Lists passwords.", result.OutputText);

                    // Add a few passwords:

                    result = runner.Execute(Program.Main, "password", "rm", "--force", "*");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "one", "password", "set", "pwd-1", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "two", "password", "set", "pwd-2", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "three", "password", "set", "pwd-3", "-");
                    Assert.Equal(0, result.ExitCode);

                    // Verify that we can list via: list

                    result = runner.Execute(Program.Main, "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 = runner.Execute(Program.Main, "password", "ls");
                    Assert.Equal(0, result.ExitCode);
                    TestHelper.AssertEqualLines(
                        @"pwd-1
pwd-2
pwd-3
",
                        result.OutputText);
                }
            }
        }
예제 #2
0
        public void PasswordImportExport()
        {
            const string zipPassword = "******";

            ExecuteResponse result;

            using (var manager = new KubeTestManager())
            {
                using (var runner = new ProgramRunner())
                {
                    // Verify that [import --help] works:

                    result = runner.Execute(Program.Main, "password", "import", "--help");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Contains("Imports passwords from an encrypted ZIP file.", result.OutputText);

                    // Verify that [import] checks the PATH argument.

                    result = runner.Execute(Program.Main, "password", "import");
                    Assert.NotEqual(0, result.ExitCode);
                    Assert.Contains("PATH argument is required.", result.ErrorText);

                    // Verify that [export --help] works:

                    result = runner.Execute(Program.Main, "password", "export", "--help");
                    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 = runner.Execute(Program.Main, "password", "export");
                    Assert.NotEqual(0, result.ExitCode);
                    Assert.Contains("PATH argument is required.", result.ErrorText);

                    // Verify that [export] checks the NAME argument.

                    result = runner.Execute(Program.Main, "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 = runner.Execute(Program.Main, "password", "rm", "--force", "*");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "one", "password", "set", "pwd-1", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "two", "password", "set", "pwd-2", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "three", "password", "set", "pwd-3", "-");
                    Assert.Equal(0, result.ExitCode);

                    // Export all passwords to a ZIP file:

                    var zipPath = Path.Combine(manager.TestFolder, "passwords.zip");

                    result = runner.ExecuteWithInput(Program.Main, zipPassword, "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 = runner.Execute(Program.Main, "password", "rm", "--force", "*");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, zipPassword, "password", "import", "--stdin", zipPath);
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, "password", "get", "pwd-1");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("one", result.OutputText.Trim());

                    result = runner.Execute(Program.Main, "password", "get", "pwd-2");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("two", result.OutputText.Trim());

                    result = runner.Execute(Program.Main, "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 = runner.ExecuteWithInput(Program.Main, zipPassword, "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 = runner.Execute(Program.Main, "password", "rm", "--force", "*");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, zipPassword, "password", "import", "--stdin", zipPath);
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, "password", "get", "pwd-1");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("one", result.OutputText.Trim());

                    result = runner.Execute(Program.Main, "password", "get", "pwd-2");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("two", result.OutputText.Trim());

                    result = runner.Execute(Program.Main, "password", "get", "pwd-3");
                    Assert.NotEqual(0, result.ExitCode);    // This one wasn't exported.
                }
            }
        }
예제 #3
0
        public async Task Query()
        {
            // Verify that the query commands work.

            var endpoint   = bucket.Configuration.GetEndPoint();
            var bucketName = bucket.Configuration.BucketName;

            // Insert a couple documents into the database.

            var jack = new Person()
            {
                Id   = 0,
                Name = "Jack",
                Age  = 10,
                Data = new byte[] { 0, 1, 2, 3, 4 }
            };

            var jill = new Person()
            {
                Id   = 1,
                Name = "Jill",
                Age  = 11,
                Data = new byte[] { 5, 6, 7, 8, 9 }
            };

            await bucket.InsertSafeAsync(jack, persistTo : PersistTo.One);

            await bucket.InsertSafeAsync(jill, persistTo : PersistTo.One);

            await bucket.WaitForIndexerAsync();

            bucket.Query <dynamic>($"select count(*) from `{bucket.Name}`;");

            using (var runner = new ProgramRunner())
            {
                // Query using the [http://...] target format and passing the query on the command line.

                var result = runner.Execute(Program.Main,
                                            "couchbase",
                                            "query",
                                            $"http://{endpoint.Address}:{endpoint.Port}@{username}:{password}:{bucketName}",
                                            $"select * from `{bucket.Name}`;");

                Assert.Equal(0, result.ExitCode);
                Assert.Contains("Jack", result.OutputText);
                Assert.Contains("Jill", result.OutputText);

                // Query again, but using the using the [couchbase://...] target format.

                result = runner.Execute(Program.Main,
                                        "couchbase",
                                        "query",
                                        $"couchbase://{endpoint.Address}:{endpoint.Port}@{username}:{password}:{bucketName}",
                                        $"select * from `{bucket.Name}`;");

                Assert.Equal(0, result.ExitCode);
                Assert.Contains("Jack", result.OutputText);
                Assert.Contains("Jill", result.OutputText);

                // Pass the query as a file.

                using (var tempFile = new TempFile())
                {
                    File.WriteAllText(tempFile.Path, $"select * from `{bucket.Name}`;");

                    result = runner.Execute(Program.Main,
                                            "couchbase",
                                            "query",
                                            $"couchbase://{endpoint.Address}:{endpoint.Port}@{username}:{password}:{bucketName}",
                                            $"@{tempFile.Path}");

                    Assert.Equal(0, result.ExitCode);
                    Assert.Contains("Jack", result.OutputText);
                    Assert.Contains("Jill", result.OutputText);
                }

                // Pass the query as STDIN.

                result = runner.ExecuteWithInput(Program.Main, $"select * from `{bucket.Name}`;",
                                                 "couchbase",
                                                 "query",
                                                 $"couchbase://{endpoint.Address}:{endpoint.Port}@{username}:{password}:{bucketName}",
                                                 "-");

                Assert.Equal(0, result.ExitCode);
                Assert.Contains("Jack", result.OutputText);
                Assert.Contains("Jill", result.OutputText);
            }
        }
예제 #4
0
        public void PasswordSet()
        {
            ExecuteResponse result;

            using (var manager = new KubeTestManager())
            {
                using (var runner = new ProgramRunner())
                {
                    // Verify that [--help] works:

                    result = runner.Execute(Program.Main, "password", "set", "--help");
                    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(manager.TestFolder, "pwd-1"), "one");
                    File.WriteAllText(Path.Combine(manager.TestFolder, "pwd-2"), "two");
                    File.WriteAllText(Path.Combine(manager.TestFolder, "pwd-3"), "three");

                    result = runner.Execute(Program.Main, $"password", "set", "pwd-1", Path.Combine(manager.TestFolder, "pwd-1"));
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, $"password", "set", "pwd-2", Path.Combine(manager.TestFolder, "pwd-2"));
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, $"password", "set", "pwd-3", Path.Combine(manager.TestFolder, "pwd-3"));
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, "password", "get", "pwd-1");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("one", result.OutputText.Trim());

                    result = runner.Execute(Program.Main, "password", "get", "pwd-2");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("two", result.OutputText.Trim());

                    result = runner.Execute(Program.Main, "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 = runner.Execute(Program.Main, "password", "rm", "--force", "*");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "one", "password", "set", "pwd-1", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "two", "password", "set", "pwd-2", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "three", "password", "set", "pwd-3", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, "password", "get", "pwd-1");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("one", result.OutputText.Trim());

                    result = runner.Execute(Program.Main, "password", "get", "pwd-2");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("two", result.OutputText.Trim());

                    result = runner.Execute(Program.Main, "password", "get", "pwd-3");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("three", result.OutputText.Trim());

                    // Verify that we can update a password.

                    result = runner.Execute(Program.Main, "password", "rm", "--force", "*");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "one", "password", "set", "pwd-1", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, "password", "get", "pwd-1");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal("one", result.OutputText.Trim());

                    result = runner.ExecuteWithInput(Program.Main, "1", "password", "set", "pwd-1", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, "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 = runner.Execute(Program.Main, "password", "rm", "--force", "*");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "password", "password", "set", "a.1_2-3", "-");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, "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 = runner.ExecuteWithInput(Program.Main, "password", "password", "set", "abc");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.Execute(Program.Main, "password", "get", "abc");
                    Assert.Equal(0, result.ExitCode);
                    Assert.Equal(20, result.OutputText.Trim().Length);

                    // Verify that we see errors for missing arguments:

                    result = runner.ExecuteWithInput(Program.Main, "password", "password", "set");
                    Assert.NotEqual(0, result.ExitCode);
                    Assert.Contains("NAME argument is required.", result.ErrorText);

                    // Verify that password name error checking works:

                    result = runner.Execute(Program.Main, "password", "rm", "--force", "*");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "", "password", "set", "pwd@1", "-");
                    Assert.NotEqual(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "", $"password", "set", $"{new string('a', 101)}", "-");
                    Assert.NotEqual(0, result.ExitCode);

                    // Verify that password length error checking works:

                    result = runner.Execute(Program.Main, "password", "rm", "--force", "*");
                    Assert.Equal(0, result.ExitCode);

                    result = runner.ExecuteWithInput(Program.Main, "", "password", "set", "pwd-1", "-");
                    Assert.NotEqual(0, result.ExitCode);
                }
            }
        }
예제 #5
0
        public async Task Upsert()
        {
            ExecuteResponse result;

            // $todo(jeff.lill):
            //
            // I'm not testing the document key generation features yet.

            // Verify that the query commands work.

            var endpoint   = bucket.Configuration.GetEndPoint();
            var bucketName = bucket.Configuration.BucketName;

            // Generate a string with a couple of JSON documents (one per line)
            // that we'll use for our tests.

            var jack = new Person()
            {
                Id   = 0,
                Name = "Jack",
                Age  = 10,
                Data = new byte[] { 0, 1, 2, 3, 4 }
            };

            var jill = new Person()
            {
                Id   = 1,
                Name = "Jill",
                Age  = 11,
                Data = new byte[] { 5, 6, 7, 8, 9 }
            };

            var sb = new StringBuilder();

            sb.AppendLine(jack.ToString(indented: false));
            sb.AppendLine(jill.ToString(indented: false));

            using (var runner = new ProgramRunner())
            {
                // Upsert using the [http://...] target format and passing the documents as a file.

                using (var tempFile = new TempFile())
                {
                    File.WriteAllText(tempFile.Path, sb.ToString());

                    result = runner.Execute(Program.Main,
                                            "couchbase",
                                            "upsert",
                                            $"http://{endpoint.Address}:{endpoint.Port}@{username}:{password}:{bucketName}",
                                            tempFile.Path);

                    Assert.Equal(0, result.ExitCode);

                    await bucket.WaitForIndexerAsync();

                    // Verify that the documents were written.

                    result = runner.ExecuteWithInput(Program.Main, $"select * from `{bucket.Name}`;",
                                                     "couchbase",
                                                     "query",
                                                     $"couchbase://{endpoint.Address}:{endpoint.Port}@{username}:{password}:{bucketName}",
                                                     "-");

                    Assert.Equal(0, result.ExitCode);
                    Assert.Contains("Jack", result.OutputText);
                    Assert.Contains("Jill", result.OutputText);
                }

                // Generate a couple more documents and test this again but this time passing the
                // JSON documents as STDIN.

                var howard = new Person()
                {
                    Id   = 2,
                    Name = "Howard",
                    Age  = 10,
                    Data = new byte[] { 0, 1, 2, 3, 4 }
                };

                var john = new Person()
                {
                    Id   = 3,
                    Name = "John",
                    Age  = 11,
                    Data = new byte[] { 5, 6, 7, 8, 9 }
                };

                sb.Clear();
                sb.AppendLine(howard.ToString(indented: false));
                sb.AppendLine(john.ToString(indented: false));

                result = runner.ExecuteWithInput(Program.Main, sb.ToString(),
                                                 "couchbase",
                                                 "upsert",
                                                 $"couchbase://{endpoint.Address}:{endpoint.Port}@{username}:{password}:{bucketName}",
                                                 "-");

                await bucket.WaitForIndexerAsync();

                Assert.Equal(0, result.ExitCode);

                // Verify that the documents were written.

                result = runner.ExecuteWithInput(Program.Main, $"select * from `{bucket.Name}`;",
                                                 "couchbase",
                                                 "query",
                                                 $"couchbase://{endpoint.Address}:{endpoint.Port}@{username}:{password}:{bucketName}",
                                                 "-");

                Assert.Equal(0, result.ExitCode);
                Assert.Contains("Howard", result.OutputText);
                Assert.Contains("John", result.OutputText);
            }
        }