public TestHttpFSFWithSWebhdfsFileSystem(BaseTestHttpFSWith.Operation operation)
     : base(operation)
 {
     {
         Uri url = Sharpen.Thread.CurrentThread().GetContextClassLoader().GetResource("classutils.txt"
                                                                                      );
         classpathDir = url.ToExternalForm();
         if (classpathDir.StartsWith("file:"))
         {
             classpathDir = Sharpen.Runtime.Substring(classpathDir, "file:".Length);
             classpathDir = Sharpen.Runtime.Substring(classpathDir, 0, classpathDir.Length - "/classutils.txt"
                                                      .Length);
         }
         else
         {
             throw new RuntimeException("Cannot find test classes dir");
         }
         FilePath @base = new FilePath(Basedir);
         FileUtil.FullyDelete(@base);
         @base.Mkdirs();
         string keyStoreDir = new FilePath(Basedir).GetAbsolutePath();
         try
         {
             sslConf = new Configuration();
             KeyStoreTestUtil.SetupSSLConfig(keyStoreDir, classpathDir, sslConf, false);
         }
         catch (Exception ex)
         {
             throw new RuntimeException(ex);
         }
         jettyTestHelper = new TestJettyHelper("jks", keyStoreDir + "/serverKS.jks", "serverP"
                                               );
     }
 }
        /// <summary>General-purpose http PUT command to the httpfs server.</summary>
        /// <param name="filename">The file to operate upon</param>
        /// <param name="command">The command to perform (SETXATTR, etc)</param>
        /// <param name="params">Parameters</param>
        /// <exception cref="System.Exception"/>
        private void PutCmd(string filename, string command, string @params)
        {
            string user = HadoopUsersConfTestHelper.GetHadoopUsers()[0];

            // Remove leading / from filename
            if (filename[0] == '/')
            {
                filename = Sharpen.Runtime.Substring(filename, 1);
            }
            string pathOps = MessageFormat.Format("/webhdfs/v1/{0}?user.name={1}{2}{3}&op={4}"
                                                  , filename, user, (@params == null) ? string.Empty : "&", (@params == null) ? string.Empty
                                 : @params, command);
            Uri url = new Uri(TestJettyHelper.GetJettyURL(), pathOps);
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            conn.SetRequestMethod("PUT");
            conn.Connect();
            int resp = conn.GetResponseCode();

            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpInternalError, resp);
            BufferedReader reader;

            reader = new BufferedReader(new InputStreamReader(conn.GetErrorStream()));
            string err = reader.ReadLine();

            NUnit.Framework.Assert.IsTrue(err.Contains("RemoteException"));
            NUnit.Framework.Assert.IsTrue(err.Contains("XAttr"));
            NUnit.Framework.Assert.IsTrue(err.Contains("rejected"));
        }
Пример #3
0
        /// <summary>Talks to the http interface to create a file.</summary>
        /// <param name="filename">The file to create</param>
        /// <param name="perms">The permission field, if any (may be null)</param>
        /// <exception cref="System.Exception"/>
        private void CreateWithHttp(string filename, string perms)
        {
            string user = HadoopUsersConfTestHelper.GetHadoopUsers()[0];

            // Remove leading / from filename
            if (filename[0] == '/')
            {
                filename = Sharpen.Runtime.Substring(filename, 1);
            }
            string pathOps;

            if (perms == null)
            {
                pathOps = MessageFormat.Format("/webhdfs/v1/{0}?user.name={1}&op=CREATE", filename
                                               , user);
            }
            else
            {
                pathOps = MessageFormat.Format("/webhdfs/v1/{0}?user.name={1}&permission={2}&op=CREATE"
                                               , filename, user, perms);
            }
            Uri url = new Uri(TestJettyHelper.GetJettyURL(), pathOps);
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            conn.AddRequestProperty("Content-Type", "application/octet-stream");
            conn.SetRequestMethod("PUT");
            conn.Connect();
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpCreated, conn.GetResponseCode
                                                ());
        }
Пример #4
0
        public virtual void Instrumentation()
        {
            CreateHttpFSServer(false);
            Uri url = new Uri(TestJettyHelper.GetJettyURL(), MessageFormat.Format("/webhdfs/v1?user.name={0}&op=instrumentation"
                                                                                  , "nobody"));
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpUnauthorized
                                            );
            url = new Uri(TestJettyHelper.GetJettyURL(), MessageFormat.Format("/webhdfs/v1?user.name={0}&op=instrumentation"
                                                                              , HadoopUsersConfTestHelper.GetHadoopUsers()[0]));
            conn = (HttpURLConnection)url.OpenConnection();
            NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpOk);
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.GetInputStream
                                                                                 ()));
            string line = reader.ReadLine();

            reader.Close();
            NUnit.Framework.Assert.IsTrue(line.Contains("\"counters\":{"));
            url = new Uri(TestJettyHelper.GetJettyURL(), MessageFormat.Format("/webhdfs/v1/foo?user.name={0}&op=instrumentation"
                                                                              , HadoopUsersConfTestHelper.GetHadoopUsers()[0]));
            conn = (HttpURLConnection)url.OpenConnection();
            NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpBadRequest
                                            );
        }
        /// <summary>Create an HttpFS Server to talk to the MiniDFSCluster we created.</summary>
        /// <exception cref="System.Exception"/>
        private void CreateHttpFSServer()
        {
            FilePath homeDir = TestDirHelper.GetTestDir();

            NUnit.Framework.Assert.IsTrue(new FilePath(homeDir, "conf").Mkdir());
            NUnit.Framework.Assert.IsTrue(new FilePath(homeDir, "log").Mkdir());
            NUnit.Framework.Assert.IsTrue(new FilePath(homeDir, "temp").Mkdir());
            HttpFSServerWebApp.SetHomeDirForCurrentThread(homeDir.GetAbsolutePath());
            FilePath   secretFile = new FilePath(new FilePath(homeDir, "conf"), "secret");
            TextWriter w          = new FileWriter(secretFile);

            w.Write("secret");
            w.Close();
            // HDFS configuration
            FilePath hadoopConfDir = new FilePath(new FilePath(homeDir, "conf"), "hadoop-conf"
                                                  );

            if (!hadoopConfDir.Mkdirs())
            {
                throw new IOException();
            }
            string        fsDefaultName = nnConf.Get(CommonConfigurationKeysPublic.FsDefaultNameKey);
            Configuration conf          = new Configuration(false);

            conf.Set(CommonConfigurationKeysPublic.FsDefaultNameKey, fsDefaultName);
            // Explicitly turn off XAttr support
            conf.SetBoolean(DFSConfigKeys.DfsNamenodeXattrsEnabledKey, false);
            FilePath     hdfsSite = new FilePath(hadoopConfDir, "hdfs-site.xml");
            OutputStream os       = new FileOutputStream(hdfsSite);

            conf.WriteXml(os);
            os.Close();
            // HTTPFS configuration
            conf = new Configuration(false);
            conf.Set("httpfs.hadoop.config.dir", hadoopConfDir.ToString());
            conf.Set("httpfs.proxyuser." + HadoopUsersConfTestHelper.GetHadoopProxyUser() + ".groups"
                     , HadoopUsersConfTestHelper.GetHadoopProxyUserGroups());
            conf.Set("httpfs.proxyuser." + HadoopUsersConfTestHelper.GetHadoopProxyUser() + ".hosts"
                     , HadoopUsersConfTestHelper.GetHadoopProxyUserHosts());
            conf.Set("httpfs.authentication.signature.secret.file", secretFile.GetAbsolutePath
                         ());
            FilePath httpfsSite = new FilePath(new FilePath(homeDir, "conf"), "httpfs-site.xml"
                                               );

            os = new FileOutputStream(httpfsSite);
            conf.WriteXml(os);
            os.Close();
            ClassLoader cl  = Sharpen.Thread.CurrentThread().GetContextClassLoader();
            Uri         url = cl.GetResource("webapp");

            if (url == null)
            {
                throw new IOException();
            }
            WebAppContext context = new WebAppContext(url.AbsolutePath, "/webhdfs");

            Org.Mortbay.Jetty.Server server = TestJettyHelper.GetJettyServer();
            server.AddHandler(context);
            server.Start();
        }
Пример #6
0
        public virtual void TestInvalidadHttpFSAccess()
        {
            CreateHttpFSServer();
            Uri url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY"
                              );
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpUnauthorized
                                            );
        }
        /// <exception cref="System.Exception"/>
        protected internal override FileSystem GetHttpFSFileSystem()
        {
            Configuration conf = new Configuration(sslConf);

            conf.Set("fs.swebhdfs.impl", GetFileSystemClass().FullName);
            URI uri = new URI("swebhdfs://" + TestJettyHelper.GetJettyURL().ToURI().GetAuthority
                                  ());

            return(FileSystem.Get(uri, conf));
        }
Пример #8
0
        /// <exception cref="System.Exception"/>
        protected internal virtual FileSystem GetHttpFSFileSystem()
        {
            Configuration conf = new Configuration();

            conf.Set("fs.webhdfs.impl", GetFileSystemClass().FullName);
            URI uri = new URI(GetScheme() + "://" + TestJettyHelper.GetJettyURL().ToURI().GetAuthority
                                  ());

            return(FileSystem.Get(uri, conf));
        }
Пример #9
0
        /// <exception cref="System.Exception"/>
        protected internal virtual void TestGet()
        {
            FileSystem fs = GetHttpFSFileSystem();

            NUnit.Framework.Assert.IsNotNull(fs);
            URI uri = new URI(GetScheme() + "://" + TestJettyHelper.GetJettyURL().ToURI().GetAuthority
                                  ());

            NUnit.Framework.Assert.AreEqual(fs.GetUri(), uri);
            fs.Close();
        }
Пример #10
0
            /// <exception cref="System.Exception"/>
            public Void Call()
            {
                Uri url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY"
                                  );
                AuthenticatedURL aUrl = new AuthenticatedURL();

                AuthenticatedURL.Token aToken = new AuthenticatedURL.Token();
                HttpURLConnection      conn   = aUrl.OpenConnection(url, aToken);

                NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpOk);
                return(null);
            }
Пример #11
0
            /// <exception cref="System.Exception"/>
            public Void Call()
            {
                //get delegation token doing SPNEGO authentication
                Uri url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETDELEGATIONTOKEN"
                                  );
                AuthenticatedURL aUrl = new AuthenticatedURL();

                AuthenticatedURL.Token aToken = new AuthenticatedURL.Token();
                HttpURLConnection      conn   = aUrl.OpenConnection(url, aToken);

                NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpOk);
                JSONObject json = (JSONObject) new JSONParser().Parse(new InputStreamReader(conn.GetInputStream
                                                                                                ()));

                json = (JSONObject)json[DelegationTokenAuthenticator.DelegationTokenJson];
                string tokenStr = (string)json[DelegationTokenAuthenticator.DelegationTokenUrlStringJson
                                  ];

                //access httpfs using the delegation token
                url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY&delegation="
                              + tokenStr);
                conn = (HttpURLConnection)url.OpenConnection();
                NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpOk);
                //try to renew the delegation token without SPNEGO credentials
                url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token="
                              + tokenStr);
                conn = (HttpURLConnection)url.OpenConnection();
                conn.SetRequestMethod("PUT");
                NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpUnauthorized
                                                );
                //renew the delegation token with SPNEGO credentials
                url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token="
                              + tokenStr);
                conn = aUrl.OpenConnection(url, aToken);
                conn.SetRequestMethod("PUT");
                NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpOk);
                //cancel delegation token, no need for SPNEGO credentials
                url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=CANCELDELEGATIONTOKEN&token="
                              + tokenStr);
                conn = (HttpURLConnection)url.OpenConnection();
                conn.SetRequestMethod("PUT");
                NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpOk);
                //try to access httpfs with the canceled delegation token
                url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY&delegation="
                              + tokenStr);
                conn = (HttpURLConnection)url.OpenConnection();
                NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpUnauthorized
                                                );
                return(null);
            }
Пример #12
0
        public virtual void TestPutNoOperation()
        {
            CreateHttpFSServer(false);
            string user = HadoopUsersConfTestHelper.GetHadoopUsers()[0];
            Uri    url  = new Uri(TestJettyHelper.GetJettyURL(), MessageFormat.Format("/webhdfs/v1/foo?user.name={0}"
                                                                                      , user));
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            conn.SetDoInput(true);
            conn.SetDoOutput(true);
            conn.SetRequestMethod("PUT");
            NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpBadRequest
                                            );
        }
Пример #13
0
        /// <exception cref="System.Exception"/>
        private void CreateHttpFSServer()
        {
            FilePath homeDir = TestDirHelper.GetTestDir();

            NUnit.Framework.Assert.IsTrue(new FilePath(homeDir, "conf").Mkdir());
            NUnit.Framework.Assert.IsTrue(new FilePath(homeDir, "log").Mkdir());
            NUnit.Framework.Assert.IsTrue(new FilePath(homeDir, "temp").Mkdir());
            HttpFSServerWebApp.SetHomeDirForCurrentThread(homeDir.GetAbsolutePath());
            FilePath   secretFile = new FilePath(new FilePath(homeDir, "conf"), "secret");
            TextWriter w          = new FileWriter(secretFile);

            w.Write("secret");
            w.Close();
            //HDFS configuration
            FilePath hadoopConfDir = new FilePath(new FilePath(homeDir, "conf"), "hadoop-conf"
                                                  );

            hadoopConfDir.Mkdirs();
            string fsDefaultName = TestHdfsHelper.GetHdfsConf().Get(CommonConfigurationKeysPublic
                                                                    .FsDefaultNameKey);
            Configuration conf = new Configuration(false);

            conf.Set(CommonConfigurationKeysPublic.FsDefaultNameKey, fsDefaultName);
            FilePath     hdfsSite = new FilePath(hadoopConfDir, "hdfs-site.xml");
            OutputStream os       = new FileOutputStream(hdfsSite);

            conf.WriteXml(os);
            os.Close();
            conf = new Configuration(false);
            conf.Set("httpfs.proxyuser.client.hosts", "*");
            conf.Set("httpfs.proxyuser.client.groups", "*");
            conf.Set("httpfs.authentication.type", "kerberos");
            conf.Set("httpfs.authentication.signature.secret.file", secretFile.GetAbsolutePath
                         ());
            FilePath httpfsSite = new FilePath(new FilePath(homeDir, "conf"), "httpfs-site.xml"
                                               );

            os = new FileOutputStream(httpfsSite);
            conf.WriteXml(os);
            os.Close();
            ClassLoader   cl      = Sharpen.Thread.CurrentThread().GetContextClassLoader();
            Uri           url     = cl.GetResource("webapp");
            WebAppContext context = new WebAppContext(url.AbsolutePath, "/webhdfs");

            Org.Mortbay.Jetty.Server server = TestJettyHelper.GetJettyServer();
            server.AddHandler(context);
            server.Start();
            HttpFSServerWebApp.Get().SetAuthority(TestJettyHelper.GetAuthority());
        }
Пример #14
0
        public virtual void TestHdfsAccess()
        {
            CreateHttpFSServer(false);
            string user = HadoopUsersConfTestHelper.GetHadoopUsers()[0];
            Uri    url  = new Uri(TestJettyHelper.GetJettyURL(), MessageFormat.Format("/webhdfs/v1/?user.name={0}&op=liststatus"
                                                                                      , user));
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpOk);
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.GetInputStream
                                                                                 ()));

            reader.ReadLine();
            reader.Close();
        }
Пример #15
0
        public virtual void TestGlobFilter()
        {
            CreateHttpFSServer(false);
            FileSystem fs = FileSystem.Get(TestHdfsHelper.GetHdfsConf());

            fs.Mkdirs(new Path("/tmp"));
            fs.Create(new Path("/tmp/foo.txt")).Close();
            string user = HadoopUsersConfTestHelper.GetHadoopUsers()[0];
            Uri    url  = new Uri(TestJettyHelper.GetJettyURL(), MessageFormat.Format("/webhdfs/v1/tmp?user.name={0}&op=liststatus&filter=f*"
                                                                                      , user));
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            NUnit.Framework.Assert.AreEqual(conn.GetResponseCode(), HttpURLConnection.HttpOk);
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.GetInputStream
                                                                                 ()));

            reader.ReadLine();
            reader.Close();
        }
Пример #16
0
        /// <summary>General-purpose http PUT command to the httpfs server.</summary>
        /// <param name="filename">The file to operate upon</param>
        /// <param name="command">The command to perform (SETACL, etc)</param>
        /// <param name="params">Parameters, like "aclspec=..."</param>
        /// <exception cref="System.Exception"/>
        private void PutCmd(string filename, string command, string @params)
        {
            string user = HadoopUsersConfTestHelper.GetHadoopUsers()[0];

            // Remove leading / from filename
            if (filename[0] == '/')
            {
                filename = Sharpen.Runtime.Substring(filename, 1);
            }
            string pathOps = MessageFormat.Format("/webhdfs/v1/{0}?user.name={1}{2}{3}&op={4}"
                                                  , filename, user, (@params == null) ? string.Empty : "&", (@params == null) ? string.Empty
                                 : @params, command);
            Uri url = new Uri(TestJettyHelper.GetJettyURL(), pathOps);
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            conn.SetRequestMethod("PUT");
            conn.Connect();
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode());
        }
Пример #17
0
        /// <exception cref="System.Exception"/>
        private void TestDelegationTokenWithFS(Type fileSystemClass)
        {
            CreateHttpFSServer();
            Configuration conf = new Configuration();

            conf.Set("fs.webhdfs.impl", fileSystemClass.FullName);
            conf.Set("fs.hdfs.impl.disable.cache", "true");
            URI uri = new URI("webhdfs://" + TestJettyHelper.GetJettyURL().ToURI().GetAuthority
                                  ());
            FileSystem fs = FileSystem.Get(uri, conf);

            Org.Apache.Hadoop.Security.Token.Token <object>[] tokens = fs.AddDelegationTokens(
                "foo", null);
            fs.Close();
            NUnit.Framework.Assert.AreEqual(1, tokens.Length);
            fs = FileSystem.Get(uri, conf);
            ((DelegationTokenRenewer.Renewable)fs).SetDelegationToken(tokens[0]);
            fs.ListStatus(new Path("/"));
            fs.Close();
        }
Пример #18
0
        /// <summary>
        /// Talks to the http interface to get the json output of a *STATUS command
        /// on the given file.
        /// </summary>
        /// <param name="filename">The file to query.</param>
        /// <param name="command">Either GETFILESTATUS, LISTSTATUS, or ACLSTATUS</param>
        /// <returns>A string containing the JSON output describing the file.</returns>
        /// <exception cref="System.Exception"/>
        private string GetStatus(string filename, string command)
        {
            string user = HadoopUsersConfTestHelper.GetHadoopUsers()[0];

            // Remove leading / from filename
            if (filename[0] == '/')
            {
                filename = Sharpen.Runtime.Substring(filename, 1);
            }
            string pathOps = MessageFormat.Format("/webhdfs/v1/{0}?user.name={1}&op={2}", filename
                                                  , user, command);
            Uri url = new Uri(TestJettyHelper.GetJettyURL(), pathOps);
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            conn.Connect();
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode());
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.GetInputStream
                                                                                 ()));

            return(reader.ReadLine());
        }
Пример #19
0
        public virtual void TestOpenOffsetLength()
        {
            CreateHttpFSServer(false);
            byte[]     array = new byte[] { 0, 1, 2, 3 };
            FileSystem fs    = FileSystem.Get(TestHdfsHelper.GetHdfsConf());

            fs.Mkdirs(new Path("/tmp"));
            OutputStream os = fs.Create(new Path("/tmp/foo"));

            os.Write(array);
            os.Close();
            string user = HadoopUsersConfTestHelper.GetHadoopUsers()[0];
            Uri    url  = new Uri(TestJettyHelper.GetJettyURL(), MessageFormat.Format("/webhdfs/v1/tmp/foo?user.name={0}&op=open&offset=1&length=2"
                                                                                      , user));
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode());
            InputStream @is = conn.GetInputStream();

            NUnit.Framework.Assert.AreEqual(1, @is.Read());
            NUnit.Framework.Assert.AreEqual(2, @is.Read());
            NUnit.Framework.Assert.AreEqual(-1, @is.Read());
        }
Пример #20
0
        /// <summary>
        /// Talks to the http interface to get the json output of a *STATUS command
        /// on the given file.
        /// </summary>
        /// <param name="filename">The file to query.</param>
        /// <param name="command">Either GETFILESTATUS, LISTSTATUS, or ACLSTATUS</param>
        /// <param name="expectOK">Is this operation expected to succeed?</param>
        /// <exception cref="System.Exception"/>
        private void GetStatus(string filename, string command, bool expectOK)
        {
            string user = HadoopUsersConfTestHelper.GetHadoopUsers()[0];

            // Remove leading / from filename
            if (filename[0] == '/')
            {
                filename = Sharpen.Runtime.Substring(filename, 1);
            }
            string pathOps = MessageFormat.Format("/webhdfs/v1/{0}?user.name={1}&op={2}", filename
                                                  , user, command);
            Uri url = new Uri(TestJettyHelper.GetJettyURL(), pathOps);
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            conn.Connect();
            int            resp = conn.GetResponseCode();
            BufferedReader reader;

            if (expectOK)
            {
                NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, resp);
                reader = new BufferedReader(new InputStreamReader(conn.GetInputStream()));
                string res = reader.ReadLine();
                NUnit.Framework.Assert.IsTrue(!res.Contains("aclBit"));
                NUnit.Framework.Assert.IsTrue(res.Contains("owner"));
            }
            else
            {
                // basic sanity check
                NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpInternalError, resp);
                reader = new BufferedReader(new InputStreamReader(conn.GetErrorStream()));
                string res = reader.ReadLine();
                NUnit.Framework.Assert.IsTrue(res.Contains("AclException"));
                NUnit.Framework.Assert.IsTrue(res.Contains("Support for ACLs has been disabled"));
            }
        }
Пример #21
0
        public virtual void TestDelegationTokenOperations()
        {
            CreateHttpFSServer(true);
            Uri url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY"
                              );
            HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();

            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpUnauthorized, conn.GetResponseCode
                                                ());
            AuthenticationToken token = new AuthenticationToken("u", "p", new KerberosDelegationTokenAuthenticationHandler
                                                                    ().GetType());

            token.SetExpires(Runtime.CurrentTimeMillis() + 100000000);
            SignerSecretProvider secretProvider = StringSignerSecretProviderCreator.NewStringSignerSecretProvider
                                                      ();
            Properties secretProviderProps = new Properties();

            secretProviderProps.SetProperty(AuthenticationFilter.SignatureSecret, "secret");
            secretProvider.Init(secretProviderProps, null, -1);
            Signer signer      = new Signer(secretProvider);
            string tokenSigned = signer.Sign(token.ToString());

            url  = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY");
            conn = (HttpURLConnection)url.OpenConnection();
            conn.SetRequestProperty("Cookie", AuthenticatedURL.AuthCookie + "=" + tokenSigned
                                    );
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode());
            url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETDELEGATIONTOKEN"
                          );
            conn = (HttpURLConnection)url.OpenConnection();
            conn.SetRequestProperty("Cookie", AuthenticatedURL.AuthCookie + "=" + tokenSigned
                                    );
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode());
            JSONObject json = (JSONObject) new JSONParser().Parse(new InputStreamReader(conn.GetInputStream
                                                                                            ()));

            json = (JSONObject)json[DelegationTokenAuthenticator.DelegationTokenJson];
            string tokenStr = (string)json[DelegationTokenAuthenticator.DelegationTokenUrlStringJson
                              ];

            url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY&delegation="
                          + tokenStr);
            conn = (HttpURLConnection)url.OpenConnection();
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode());
            url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token="
                          + tokenStr);
            conn = (HttpURLConnection)url.OpenConnection();
            conn.SetRequestMethod("PUT");
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpUnauthorized, conn.GetResponseCode
                                                ());
            url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token="
                          + tokenStr);
            conn = (HttpURLConnection)url.OpenConnection();
            conn.SetRequestMethod("PUT");
            conn.SetRequestProperty("Cookie", AuthenticatedURL.AuthCookie + "=" + tokenSigned
                                    );
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode());
            url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=CANCELDELEGATIONTOKEN&token="
                          + tokenStr);
            conn = (HttpURLConnection)url.OpenConnection();
            conn.SetRequestMethod("PUT");
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode());
            url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY&delegation="
                          + tokenStr);
            conn = (HttpURLConnection)url.OpenConnection();
            NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpForbidden, conn.GetResponseCode
                                                ());
        }
Пример #22
0
        /// <exception cref="System.Exception"/>
        private void CreateHttpFSServer(bool addDelegationTokenAuthHandler)
        {
            FilePath homeDir = TestDirHelper.GetTestDir();

            NUnit.Framework.Assert.IsTrue(new FilePath(homeDir, "conf").Mkdir());
            NUnit.Framework.Assert.IsTrue(new FilePath(homeDir, "log").Mkdir());
            NUnit.Framework.Assert.IsTrue(new FilePath(homeDir, "temp").Mkdir());
            HttpFSServerWebApp.SetHomeDirForCurrentThread(homeDir.GetAbsolutePath());
            FilePath   secretFile = new FilePath(new FilePath(homeDir, "conf"), "secret");
            TextWriter w          = new FileWriter(secretFile);

            w.Write("secret");
            w.Close();
            //HDFS configuration
            FilePath hadoopConfDir = new FilePath(new FilePath(homeDir, "conf"), "hadoop-conf"
                                                  );

            hadoopConfDir.Mkdirs();
            string fsDefaultName = TestHdfsHelper.GetHdfsConf().Get(CommonConfigurationKeysPublic
                                                                    .FsDefaultNameKey);
            Configuration conf = new Configuration(false);

            conf.Set(CommonConfigurationKeysPublic.FsDefaultNameKey, fsDefaultName);
            conf.SetBoolean(DFSConfigKeys.DfsNamenodeAclsEnabledKey, true);
            conf.SetBoolean(DFSConfigKeys.DfsNamenodeXattrsEnabledKey, true);
            FilePath     hdfsSite = new FilePath(hadoopConfDir, "hdfs-site.xml");
            OutputStream os       = new FileOutputStream(hdfsSite);

            conf.WriteXml(os);
            os.Close();
            //HTTPFS configuration
            conf = new Configuration(false);
            if (addDelegationTokenAuthHandler)
            {
                conf.Set("httpfs.authentication.type", typeof(HttpFSKerberosAuthenticationHandlerForTesting
                                                              ).FullName);
            }
            conf.Set("httpfs.services.ext", typeof(TestHttpFSServer.MockGroups).FullName);
            conf.Set("httpfs.admin.group", HadoopUsersConfTestHelper.GetHadoopUserGroups(HadoopUsersConfTestHelper
                                                                                         .GetHadoopUsers()[0])[0]);
            conf.Set("httpfs.proxyuser." + HadoopUsersConfTestHelper.GetHadoopProxyUser() + ".groups"
                     , HadoopUsersConfTestHelper.GetHadoopProxyUserGroups());
            conf.Set("httpfs.proxyuser." + HadoopUsersConfTestHelper.GetHadoopProxyUser() + ".hosts"
                     , HadoopUsersConfTestHelper.GetHadoopProxyUserHosts());
            conf.Set("httpfs.authentication.signature.secret.file", secretFile.GetAbsolutePath
                         ());
            conf.Set("httpfs.hadoop.config.dir", hadoopConfDir.ToString());
            FilePath httpfsSite = new FilePath(new FilePath(homeDir, "conf"), "httpfs-site.xml"
                                               );

            os = new FileOutputStream(httpfsSite);
            conf.WriteXml(os);
            os.Close();
            ClassLoader   cl      = Sharpen.Thread.CurrentThread().GetContextClassLoader();
            Uri           url     = cl.GetResource("webapp");
            WebAppContext context = new WebAppContext(url.AbsolutePath, "/webhdfs");

            Org.Mortbay.Jetty.Server server = TestJettyHelper.GetJettyServer();
            server.AddHandler(context);
            server.Start();
            if (addDelegationTokenAuthHandler)
            {
                HttpFSServerWebApp.Get().SetAuthority(TestJettyHelper.GetAuthority());
            }
        }