Example #1
0
        public virtual void TestEmptyArgList()
        {
            CredentialShell shell = new CredentialShell();

            shell.SetConf(new Configuration());
            Assert.Equal(1, shell.Init(new string[0]));
        }
Example #2
0
        public virtual void TestCredentialSuccessfulLifecycle()
        {
            outContent.Reset();
            string[] args1 = new string[] { "create", "credential1", "-value", "p@ssw0rd", "-provider"
                                            , jceksProvider };
            int             rc = 0;
            CredentialShell cs = new CredentialShell();

            cs.SetConf(new Configuration());
            rc = cs.Run(args1);
            Assert.Equal(outContent.ToString(), 0, rc);
            Assert.True(outContent.ToString().Contains("credential1 has been successfully "
                                                       + "created."));
            outContent.Reset();
            string[] args2 = new string[] { "list", "-provider", jceksProvider };
            rc = cs.Run(args2);
            Assert.Equal(0, rc);
            Assert.True(outContent.ToString().Contains("credential1"));
            outContent.Reset();
            string[] args4 = new string[] { "delete", "credential1", "-f", "-provider", jceksProvider };
            rc = cs.Run(args4);
            Assert.Equal(0, rc);
            Assert.True(outContent.ToString().Contains("credential1 has been successfully "
                                                       + "deleted."));
            outContent.Reset();
            string[] args5 = new string[] { "list", "-provider", jceksProvider };
            rc = cs.Run(args5);
            Assert.Equal(0, rc);
            NUnit.Framework.Assert.IsFalse(outContent.ToString(), outContent.ToString().Contains
                                               ("credential1"));
        }
Example #3
0
 public virtual void TestCommandHelpExitsNormally()
 {
     foreach (string cmd in Arrays.AsList("create", "list", "delete"))
     {
         CredentialShell shell = new CredentialShell();
         shell.SetConf(new Configuration());
         Assert.Equal("Expected help argument on " + cmd + " to return 0"
                      , 0, shell.Init(new string[] { cmd, "-help" }));
     }
 }
Example #4
0
        public virtual void TestInvalidProvider()
        {
            string[] args1 = new string[] { "create", "credential1", "-value", "p@ssw0rd", "-provider"
                                            , "sdff://file/tmp/credstore.jceks" };
            int             rc = 0;
            CredentialShell cs = new CredentialShell();

            cs.SetConf(new Configuration());
            rc = cs.Run(args1);
            Assert.Equal(1, rc);
            Assert.True(outContent.ToString().Contains("There are no valid "
                                                       + "CredentialProviders configured."));
        }
Example #5
0
        public virtual void TestEmptyArgForCommands()
        {
            CredentialShell shell = new CredentialShell();

            string[] command = new string[] { "list", "-provider" };
            Assert.Equal("Expected empty argument on " + command + " to return 1"
                         , 1, shell.Init(command));
            foreach (string cmd in Arrays.AsList("create", "delete"))
            {
                shell.SetConf(new Configuration());
                Assert.Equal("Expected empty argument on " + cmd + " to return 1"
                             , 1, shell.Init(new string[] { cmd }));
            }
        }
Example #6
0
        public virtual void TestTransientProviderOnlyConfig()
        {
            string[]        args1  = new string[] { "create", "credential1" };
            int             rc     = 0;
            CredentialShell cs     = new CredentialShell();
            Configuration   config = new Configuration();

            config.Set(CredentialProviderFactory.CredentialProviderPath, "user:///");
            cs.SetConf(config);
            rc = cs.Run(args1);
            Assert.Equal(1, rc);
            Assert.True(outContent.ToString().Contains("There are no valid "
                                                       + "CredentialProviders configured."));
        }
Example #7
0
        public virtual void TestPromptForCredentialWithEmptyPasswd()
        {
            string[]       args1     = new string[] { "create", "credential1", "-provider", jceksProvider };
            AList <string> passwords = new AList <string>();

            passwords.AddItem(null);
            passwords.AddItem("p@ssw0rd");
            int             rc    = 0;
            CredentialShell shell = new CredentialShell();

            shell.SetConf(new Configuration());
            shell.SetPasswordReader(new TestCredShell.MockPasswordReader(this, passwords));
            rc = shell.Run(args1);
            Assert.Equal(outContent.ToString(), 1, rc);
            Assert.True(outContent.ToString().Contains("Passwords don't match"
                                                       ));
        }
Example #8
0
        public virtual void TestTransientProviderWarning()
        {
            string[] args1 = new string[] { "create", "credential1", "-value", "p@ssw0rd", "-provider"
                                            , "user:///" };
            int             rc = 0;
            CredentialShell cs = new CredentialShell();

            cs.SetConf(new Configuration());
            rc = cs.Run(args1);
            Assert.Equal(outContent.ToString(), 0, rc);
            Assert.True(outContent.ToString().Contains("WARNING: you are modifying a "
                                                       + "transient provider."));
            string[] args2 = new string[] { "delete", "credential1", "-f", "-provider", "user:///" };
            rc = cs.Run(args2);
            Assert.Equal(outContent.ToString(), 0, rc);
            Assert.True(outContent.ToString().Contains("credential1 has been successfully "
                                                       + "deleted."));
        }
Example #9
0
        public virtual void TestPromptForCredential()
        {
            string[]       args1     = new string[] { "create", "credential1", "-provider", jceksProvider };
            AList <string> passwords = new AList <string>();

            passwords.AddItem("p@ssw0rd");
            passwords.AddItem("p@ssw0rd");
            int             rc    = 0;
            CredentialShell shell = new CredentialShell();

            shell.SetConf(new Configuration());
            shell.SetPasswordReader(new TestCredShell.MockPasswordReader(this, passwords));
            rc = shell.Run(args1);
            Assert.Equal(0, rc);
            Assert.True(outContent.ToString().Contains("credential1 has been successfully "
                                                       + "created."));
            string[] args2 = new string[] { "delete", "credential1", "-f", "-provider", jceksProvider };
            rc = shell.Run(args2);
            Assert.Equal(0, rc);
            Assert.True(outContent.ToString().Contains("credential1 has been successfully "
                                                       + "deleted."));
        }
Example #10
0
 public CreateCommand(CredentialShell _enclosing, string alias)
     : base(_enclosing)
 {
     this._enclosing = _enclosing;
     this.alias      = alias;
 }
Example #11
0
 internal ListCommand(CredentialShell _enclosing)
     : base(_enclosing)
 {
     this._enclosing = _enclosing;
 }
Example #12
0
 internal Command(CredentialShell _enclosing)
 {
     this._enclosing = _enclosing;
 }