コード例 #1
0
        public virtual void TestConfGetPassword()
        {
            FilePath testDir = new FilePath(Runtime.GetProperty("test.build.data", "target/test-dir"
                                                                ));
            Configuration conf    = new Configuration();
            Path          jksPath = new Path(testDir.ToString(), "test.jks");
            string        ourUrl  = JavaKeyStoreProvider.SchemeName + "://file" + jksPath.ToUri();
            FilePath      file    = new FilePath(testDir, "test.jks");

            file.Delete();
            conf.Set(CredentialProviderFactory.CredentialProviderPath, ourUrl);
            CredentialProvider provider = CredentialProviderFactory.GetProviders(conf)[0];

            char[] bindpass  = new char[] { 'b', 'i', 'n', 'd', 'p', 'a', 's', 's' };
            char[] storepass = new char[] { 's', 't', 'o', 'r', 'e', 'p', 'a', 's', 's' };
            // ensure that we get nulls when the key isn't there
            Assert.Equal(null, provider.GetCredentialEntry(LdapGroupsMapping
                                                           .BindPasswordKey));
            Assert.Equal(null, provider.GetCredentialEntry(LdapGroupsMapping
                                                           .LdapKeystorePasswordKey));
            // create new aliases
            try
            {
                provider.CreateCredentialEntry(LdapGroupsMapping.BindPasswordKey, bindpass);
                provider.CreateCredentialEntry(LdapGroupsMapping.LdapKeystorePasswordKey, storepass
                                               );
                provider.Flush();
            }
            catch (Exception e)
            {
                Runtime.PrintStackTrace(e);
                throw;
            }
            // make sure we get back the right key
            Assert.AssertArrayEquals(bindpass, provider.GetCredentialEntry(LdapGroupsMapping.
                                                                           BindPasswordKey).GetCredential());
            Assert.AssertArrayEquals(storepass, provider.GetCredentialEntry(LdapGroupsMapping
                                                                            .LdapKeystorePasswordKey).GetCredential());
            LdapGroupsMapping mapping = new LdapGroupsMapping();

            Assert.Equal("bindpass", mapping.GetPassword(conf, LdapGroupsMapping
                                                         .BindPasswordKey, string.Empty));
            Assert.Equal("storepass", mapping.GetPassword(conf, LdapGroupsMapping
                                                          .LdapKeystorePasswordKey, string.Empty));
            // let's make sure that a password that doesn't exist returns an
            // empty string as currently expected and used to trigger a call to
            // extract password
            Assert.Equal(string.Empty, mapping.GetPassword(conf, "invalid-alias"
                                                           , string.Empty));
        }
コード例 #2
0
        public virtual void TestExtractPassword()
        {
            FilePath testDir = new FilePath(Runtime.GetProperty("test.build.data", "target/test-dir"
                                                                ));

            testDir.Mkdirs();
            FilePath   secretFile = new FilePath(testDir, "secret.txt");
            TextWriter writer     = new FileWriter(secretFile);

            writer.Write("hadoop");
            writer.Close();
            LdapGroupsMapping mapping = new LdapGroupsMapping();

            Assert.Equal("hadoop", mapping.ExtractPassword(secretFile.GetPath
                                                               ()));
        }