public virtual void TestTokenFetchFail()
 {
     try
     {
         DelegationTokenFetcher.Main(new string[] { "-webservice=" + serviceUrl, tokenFile });
         NUnit.Framework.Assert.Fail("Token fetcher shouldn't start in absense of NN");
     }
     catch (IOException)
     {
     }
 }
Esempio n. 2
0
 private static void ExpectDelegationTokenFetcherExit(string[] args)
 {
     try
     {
         DelegationTokenFetcher.Main(args);
         NUnit.Framework.Assert.Fail("should call exit");
     }
     catch (ExitUtil.ExitException)
     {
         ExitUtil.ResetFirstExitException();
     }
     catch (Exception ex)
     {
         NUnit.Framework.Assert.Fail("expectDelegationTokenFetcherExit ex error " + ex);
     }
 }
        public virtual void ExpectedTokenIsRetrievedFromHttp()
        {
            bootstrap = StartHttpServer(httpPort, testToken, serviceUrl);
            DelegationTokenFetcher.Main(new string[] { "-webservice=" + serviceUrl, tokenFile });
            Path        p     = new Path(fileSys.GetWorkingDirectory(), tokenFile);
            Credentials creds = Credentials.ReadTokenStorageFile(p, conf);
            IEnumerator <Org.Apache.Hadoop.Security.Token.Token <object> > itr = creds.GetAllTokens
                                                                                     ().GetEnumerator();

            NUnit.Framework.Assert.IsTrue("token not exist error", itr.HasNext());
            Org.Apache.Hadoop.Security.Token.Token <object> fetchedToken = itr.Next();
            Assert.AssertArrayEquals("token wrong identifier error", testToken.GetIdentifier(
                                         ), fetchedToken.GetIdentifier());
            Assert.AssertArrayEquals("token wrong password error", testToken.GetPassword(), fetchedToken
                                     .GetPassword());
            if (assertionError != null)
            {
                throw assertionError;
            }
        }
Esempio n. 4
0
        public virtual void ExpectedTokenIsRetrievedFromDFS()
        {
            byte[] ident = new DelegationTokenIdentifier(new Text("owner"), new Text("renewer"
                                                                                     ), new Text("realuser")).GetBytes();
            byte[] pw      = new byte[] { 42 };
            Text   service = new Text(uri.ToString());

            // Create a token for the fetcher to fetch, wire NN to return it when asked
            // for this particular user.
            Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> t = new Org.Apache.Hadoop.Security.Token.Token
                                                                                   <DelegationTokenIdentifier>(ident, pw, FakeRenewer.Kind, service);
            Org.Mockito.Mockito.When(dfs.AddDelegationTokens(Matchers.Eq((string)null), Matchers.Any
                                                             <Credentials>())).ThenAnswer(new _Answer_77(service, t));
            Org.Mockito.Mockito.When(dfs.GetUri()).ThenReturn(uri);
            FakeRenewer.Reset();
            FileSystem fileSys = FileSystem.GetLocal(conf);

            try
            {
                DelegationTokenFetcher.Main(new string[] { "-fs", uri.ToString(), tokenFile });
                Path        p     = new Path(fileSys.GetWorkingDirectory(), tokenFile);
                Credentials creds = Credentials.ReadTokenStorageFile(p, conf);
                IEnumerator <Org.Apache.Hadoop.Security.Token.Token <object> > itr = creds.GetAllTokens
                                                                                         ().GetEnumerator();
                // make sure we got back exactly the 1 token we expected
                NUnit.Framework.Assert.IsTrue(itr.HasNext());
                NUnit.Framework.Assert.AreEqual(t, itr.Next());
                NUnit.Framework.Assert.IsTrue(!itr.HasNext());
                DelegationTokenFetcher.Main(new string[] { "--print", tokenFile });
                DelegationTokenFetcher.Main(new string[] { "--renew", tokenFile });
                NUnit.Framework.Assert.AreEqual(t, FakeRenewer.lastRenewed);
                FakeRenewer.Reset();
                DelegationTokenFetcher.Main(new string[] { "--cancel", tokenFile });
                NUnit.Framework.Assert.AreEqual(t, FakeRenewer.lastCanceled);
            }
            finally
            {
                fileSys.Delete(new Path(tokenFile), true);
            }
        }