Esempio n. 1
0
        /// <summary>
        /// Ensure that when manually specifying permission modes we get
        /// the expected values back out for all combinations
        /// </summary>
        public virtual void TestConvertingPermissions()
        {
            for (short s = 0; s <= 0x3ff; s++)
            {
                Assert.Equal(s, new FsPermission(s).ToShort());
            }
            short s_1 = 0;

            foreach (bool sb in new bool[] { false, true })
            {
                foreach (FsAction u in FsAction.Values())
                {
                    foreach (FsAction g in FsAction.Values())
                    {
                        foreach (FsAction o in FsAction.Values())
                        {
                            // Cover constructor with sticky bit.
                            FsPermission f = new FsPermission(u, g, o, sb);
                            Assert.Equal(s_1, f.ToShort());
                            FsPermission f2 = new FsPermission(f);
                            Assert.Equal(s_1, f2.ToShort());
                            s_1++;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Apply permission against specified file and determine what the
        /// new mode would be
        /// </summary>
        /// <param name="file">File against which to apply mode</param>
        /// <returns>File's new mode if applied.</returns>
        public virtual short ApplyNewPermission(FileStatus file)
        {
            FsPermission perms    = file.GetPermission();
            int          existing = perms.ToShort();
            bool         exeOk    = file.IsDirectory() || (existing & 0x49) != 0;

            return((short)CombineModes(existing, exeOk));
        }
Esempio n. 3
0
        // Ensure that when the deprecated decimal umask key is used, it is correctly
        // parsed as such and converted correctly to an FsPermission value
        public virtual void TestDeprecatedUmask()
        {
            Configuration conf = new Configuration();

            conf.Set(FsPermission.DeprecatedUmaskLabel, "302");
            // 302 = 0456
            FsPermission umask = FsPermission.GetUMask(conf);

            Assert.Equal(0x12e, umask.ToShort());
        }
Esempio n. 4
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestUMaskParser()
        {
            Configuration conf = new Configuration();

            // Ensure that we get the right octal values back for all legal values
            foreach (FsAction u in FsAction.Values())
            {
                foreach (FsAction g in FsAction.Values())
                {
                    foreach (FsAction o in FsAction.Values())
                    {
                        FsPermission f       = new FsPermission(u, g, o);
                        string       asOctal = string.Format("%1$03o", f.ToShort());
                        conf.Set(FsPermission.UmaskLabel, asOctal);
                        FsPermission fromConf = FsPermission.GetUMask(conf);
                        Assert.Equal(f, fromConf);
                    }
                }
            }
        }