public virtual void TestInternalGetAclStatus()
        {
            UserGroupInformation currentUser = UserGroupInformation.GetCurrentUser();
            AclStatus            aclStatus   = fsView.GetAclStatus(new Path("/internalDir"));

            Assert.Equal(aclStatus.GetOwner(), currentUser.GetUserName());
            Assert.Equal(aclStatus.GetGroup(), currentUser.GetGroupNames()
                         [0]);
            Assert.Equal(aclStatus.GetEntries(), AclUtil.GetMinimalAcl(Constants
                                                                       .Permission555));
            NUnit.Framework.Assert.IsFalse(aclStatus.IsStickyBit());
        }
Example #2
0
 /// <summary>Runs assertions testing that two AclStatus objects contain the same info
 ///     </summary>
 /// <param name="a">First AclStatus</param>
 /// <param name="b">Second AclStatus</param>
 /// <exception cref="System.Exception"/>
 private void AssertSameAcls(AclStatus a, AclStatus b)
 {
     NUnit.Framework.Assert.IsTrue(a.GetOwner().Equals(b.GetOwner()));
     NUnit.Framework.Assert.IsTrue(a.GetGroup().Equals(b.GetGroup()));
     NUnit.Framework.Assert.IsTrue(a.IsStickyBit() == b.IsStickyBit());
     NUnit.Framework.Assert.IsTrue(a.GetEntries().Count == b.GetEntries().Count);
     foreach (AclEntry e in a.GetEntries())
     {
         NUnit.Framework.Assert.IsTrue(b.GetEntries().Contains(e));
     }
     foreach (AclEntry e_1 in b.GetEntries())
     {
         NUnit.Framework.Assert.IsTrue(a.GetEntries().Contains(e_1));
     }
 }
Example #3
0
        /// <summary>Convert a AclStatus object to a Json string.</summary>
        public static string ToJsonString(AclStatus status)
        {
            if (status == null)
            {
                return(null);
            }
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["owner"]     = status.GetOwner();
            m["group"]     = status.GetGroup();
            m["stickyBit"] = status.IsStickyBit();
            IList <string> stringEntries = new AList <string>();

            foreach (AclEntry entry in status.GetEntries())
            {
                stringEntries.AddItem(entry.ToString());
            }
            m["entries"] = stringEntries;
            FsPermission perm = status.GetPermission();

            if (perm != null)
            {
                m["permission"] = ToString(perm);
                if (perm.GetAclBit())
                {
                    m["aclBit"] = true;
                }
                if (perm.GetEncryptedBit())
                {
                    m["encBit"] = true;
                }
            }
            IDictionary <string, IDictionary <string, object> > finalMap = new SortedDictionary <
                string, IDictionary <string, object> >();

            finalMap[typeof(AclStatus).Name] = m;
            ObjectMapper mapper = new ObjectMapper();

            try
            {
                return(mapper.WriteValueAsString(finalMap));
            }
            catch (IOException)
            {
            }
            return(null);
        }
Example #4
0
        /// <summary>Converts an <code>AclStatus</code> object into a JSON object.</summary>
        /// <param name="aclStatus">AclStatus object</param>
        /// <returns>The JSON representation of the ACLs for the file</returns>
        private static IDictionary <string, object> AclStatusToJSON(AclStatus aclStatus)
        {
            IDictionary <string, object> json  = new LinkedHashMap <string, object>();
            IDictionary <string, object> inner = new LinkedHashMap <string, object>();
            JSONArray entriesArray             = new JSONArray();

            inner[HttpFSFileSystem.OwnerJson]        = aclStatus.GetOwner();
            inner[HttpFSFileSystem.GroupJson]        = aclStatus.GetGroup();
            inner[HttpFSFileSystem.AclStickyBitJson] = aclStatus.IsStickyBit();
            foreach (AclEntry e in aclStatus.GetEntries())
            {
                entriesArray.AddItem(e.ToString());
            }
            inner[HttpFSFileSystem.AclEntriesJson] = entriesArray;
            json[HttpFSFileSystem.AclStatusJson]   = inner;
            return(json);
        }