Ejemplo n.º 1
0
    public void CanSetContents()
    {
        FileSystem fs = new FileSystem();

        Assert.IsNotNull(fs);

        EditableFile f = fs.createFile("test.txt");

        Assert.AreEqual(f.getContents(), "");
        f.setContents("hello world");
        Assert.AreEqual(f.getContents(), "hello world");
    }
Ejemplo n.º 2
0
    public void CanNonadminUsersModifyRightPermissions()
    {
        FileSystem   fs = new FileSystem();
        EditableFile fi = fs.createFile("hello.txt");

        fs.setPermissions(fi, 000);

        // Make a nonadmin user
        fs.addUser("meow", "pass", SECURITY_LEVEL.NONADMIN);
        Assert.AreEqual(2, fs.allUsers.Count);
        fs.changeUser("meow", "pass");

        // Can't read
        Assert.Throws(typeof(InvalidUserException), delegate {
            fi.getContents();
        });

        // Can't write
        Assert.Throws(typeof(InvalidUserException), delegate {
            fi.setContents("hello world!");
        });

        // Can't set root permissions
        Assert.Throws(typeof(InvalidUserException), delegate {
            fs.setPermissions(fi, 700);
        });

        // Can't set admin permissions
        Assert.Throws(typeof(InvalidUserException), delegate {
            fs.setPermissions(fi, 070);
        });

        // Can set nonadmin permissions
        fs.setPermissions(fi, 007);

        fi.setContents("meowmeow");
        Assert.AreEqual("meowmeow", fi.getContents());
    }
Ejemplo n.º 3
0
    public void CanRootUsersModifyRightPermissions()
    {
        FileSystem fs = new FileSystem();

        // We are root user, so we can change all permissions.
        // Try making something we can't read or write to.
        EditableFile fi = fs.createFile("hello.txt");

        fs.setPermissions(fi, 000);
        Assert.AreEqual(000, fi.getPermissions());

        // Can't read
        Assert.Throws(typeof(InvalidUserException), delegate {
            fi.getContents();
        });

        // Can't write
        Assert.Throws(typeof(InvalidUserException), delegate {
            fi.setContents("hello world!");
        });

        // Can set any permissions
        fs.setPermissions(fi, 700);
        Assert.AreEqual(700, fi.getPermissions());
        fs.setPermissions(fi, 770);
        Assert.AreEqual(770, fi.getPermissions());
        fs.setPermissions(fi, 777);
        Assert.AreEqual(777, fi.getPermissions());
        fs.setPermissions(fi, 700);
        Assert.AreEqual(700, fi.getPermissions());

        // Can read + write now
        Assert.AreEqual("", fi.getContents());
        fi.setContents("hello!");
        Assert.AreEqual("hello!", fi.getContents());
    }