Ejemplo n.º 1
0
        public virtual void TestStaticMapping()
        {
            Assume.AssumeTrue(!Shell.Windows);
            IDictionary <int, int> uidStaticMap = new ShellBasedIdMapping.PassThroughMap <int>(
                );
            IDictionary <int, int> gidStaticMap = new ShellBasedIdMapping.PassThroughMap <int>(
                );

            uidStaticMap[11501] = 10;
            gidStaticMap[497]   = 200;
            // Maps for id to name map
            BiMap <int, string> uMap = HashBiMap.Create();
            BiMap <int, string> gMap = HashBiMap.Create();
            string GetAllUsersCmd    = "echo \"atm:x:1000:1000:Aaron T. Myers,,,:/home/atm:/bin/bash\n"
                                       + "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\"" + " | cut -d: -f1,3";
            string GetAllGroupsCmd = "echo \"hdfs:*:11501:hrt_hdfs\n" + "mapred:x:497\n" + "mapred2:x:498\""
                                     + " | cut -d: -f1,3";

            ShellBasedIdMapping.UpdateMapInternal(uMap, "user", GetAllUsersCmd, ":", uidStaticMap
                                                  );
            ShellBasedIdMapping.UpdateMapInternal(gMap, "group", GetAllGroupsCmd, ":", gidStaticMap
                                                  );
            Assert.Equal("hdfs", uMap[10]);
            Assert.Equal(10, (int)uMap.Inverse()["hdfs"]);
            Assert.Equal("atm", uMap[1000]);
            Assert.Equal(1000, (int)uMap.Inverse()["atm"]);
            Assert.Equal("hdfs", gMap[11501]);
            Assert.Equal(11501, (int)gMap.Inverse()["hdfs"]);
            Assert.Equal("mapred", gMap[200]);
            Assert.Equal(200, (int)gMap.Inverse()["mapred"]);
            Assert.Equal("mapred2", gMap[498]);
            Assert.Equal(498, (int)gMap.Inverse()["mapred2"]);
        }
Ejemplo n.º 2
0
        public virtual void TestDuplicates()
        {
            Assume.AssumeTrue(!Shell.Windows);
            string GetAllUsersCmd = "echo \"root:x:0:0:root:/root:/bin/bash\n" + "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\n"
                                    + "hdfs:x:11502:10788:Grid Distributed File System:/home/hdfs:/bin/bash\n" + "hdfs1:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\n"
                                    + "hdfs2:x:11502:10787:Grid Distributed File System:/home/hdfs:/bin/bash\n" + "bin:x:2:2:bin:/bin:/bin/sh\n"
                                    + "bin:x:1:1:bin:/bin:/sbin/nologin\n" + "daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n"
                                    + "daemon:x:2:2:daemon:/sbin:/sbin/nologin\"" + " | cut -d: -f1,3";
            string GetAllGroupsCmd = "echo \"hdfs:*:11501:hrt_hdfs\n" + "mapred:x:497\n" + "mapred2:x:497\n"
                                     + "mapred:x:498\n" + "mapred3:x:498\"" + " | cut -d: -f1,3";
            // Maps for id to name map
            BiMap <int, string> uMap = HashBiMap.Create();
            BiMap <int, string> gMap = HashBiMap.Create();

            ShellBasedIdMapping.UpdateMapInternal(uMap, "user", GetAllUsersCmd, ":", EmptyPassThroughMap
                                                  );
            Assert.Equal(5, uMap.Count);
            Assert.Equal("root", uMap[0]);
            Assert.Equal("hdfs", uMap[11501]);
            Assert.Equal("hdfs2", uMap[11502]);
            Assert.Equal("bin", uMap[2]);
            Assert.Equal("daemon", uMap[1]);
            ShellBasedIdMapping.UpdateMapInternal(gMap, "group", GetAllGroupsCmd, ":", EmptyPassThroughMap
                                                  );
            Assert.True(gMap.Count == 3);
            Assert.Equal("hdfs", gMap[11501]);
            Assert.Equal("mapred", gMap[497]);
            Assert.Equal("mapred3", gMap[498]);
        }
Ejemplo n.º 3
0
        public virtual void TestIdOutOfIntegerRange()
        {
            Assume.AssumeTrue(!Shell.Windows);
            string GetAllUsersCmd = "echo \"" + "nfsnobody:x:4294967294:4294967294:Anonymous NFS User:/var/lib/nfs:/sbin/nologin\n"
                                    + "nfsnobody1:x:4294967295:4294967295:Anonymous NFS User:/var/lib/nfs1:/sbin/nologin\n"
                                    + "maxint:x:2147483647:2147483647:Grid Distributed File System:/home/maxint:/bin/bash\n"
                                    + "minint:x:2147483648:2147483648:Grid Distributed File System:/home/minint:/bin/bash\n"
                                    + "archivebackup:*:1031:4294967294:Archive Backup:/home/users/archivebackup:/bin/sh\n"
                                    + "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\n" + "daemon:x:2:2:daemon:/sbin:/sbin/nologin\""
                                    + " | cut -d: -f1,3";
            string GetAllGroupsCmd = "echo \"" + "hdfs:*:11501:hrt_hdfs\n" + "rpcuser:*:29:\n"
                                     + "nfsnobody:*:4294967294:\n" + "nfsnobody1:*:4294967295:\n" + "maxint:*:2147483647:\n"
                                     + "minint:*:2147483648:\n" + "mapred3:x:498\"" + " | cut -d: -f1,3";
            // Maps for id to name map
            BiMap <int, string> uMap = HashBiMap.Create();
            BiMap <int, string> gMap = HashBiMap.Create();

            ShellBasedIdMapping.UpdateMapInternal(uMap, "user", GetAllUsersCmd, ":", EmptyPassThroughMap
                                                  );
            Assert.True(uMap.Count == 7);
            Assert.Equal("nfsnobody", uMap[-2]);
            Assert.Equal("nfsnobody1", uMap[-1]);
            Assert.Equal("maxint", uMap[2147483647]);
            Assert.Equal("minint", uMap[-2147483648]);
            Assert.Equal("archivebackup", uMap[1031]);
            Assert.Equal("hdfs", uMap[11501]);
            Assert.Equal("daemon", uMap[2]);
            ShellBasedIdMapping.UpdateMapInternal(gMap, "group", GetAllGroupsCmd, ":", EmptyPassThroughMap
                                                  );
            Assert.True(gMap.Count == 7);
            Assert.Equal("hdfs", gMap[11501]);
            Assert.Equal("rpcuser", gMap[29]);
            Assert.Equal("nfsnobody", gMap[-2]);
            Assert.Equal("nfsnobody1", gMap[-1]);
            Assert.Equal("maxint", gMap[2147483647]);
            Assert.Equal("minint", gMap[-2147483648]);
            Assert.Equal("mapred3", gMap[498]);
        }