Example #1
0
        private ReportedFileAccess CreateViolation(RequestedAccess access, AbsolutePath path)
        {
            var process = new ReportedProcess(1, ReportedExecutablePath);

            return(ReportedFileAccess.Create(
                       ReportedFileOperation.CreateFile,
                       process,
                       access,
                       FileAccessStatus.Denied,
                       explicitlyReported: false,
                       error: 0,
                       usn: ReportedFileAccess.NoUsn,
                       desiredAccess: DesiredAccess.GENERIC_READ,
                       shareMode: ShareMode.FILE_SHARE_NONE,
                       creationDisposition: CreationDisposition.OPEN_ALWAYS,
                       flagsAndAttributes: FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                       path: path));
        }
Example #2
0
        public void ReportedFileAccessEquality()
        {
            var          pathTable = new PathTable();
            AbsolutePath file1     = AbsolutePath.Create(pathTable, A("t", "file1.txt"));
            AbsolutePath file2     = AbsolutePath.Create(pathTable, A("t", "file2.txt"));

            var process = new ReportedProcess(0, string.Empty);

            Test.BuildXL.TestUtilities.Xunit.StructTester.TestEquality(
                baseValue:
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    file1),
                equalValue:
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    file1),
                notEqualValues: new[]
            {
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Denied,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    file1),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    file2),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("u", "file3.txt")),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Denied,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("u", "file4.txt")),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    false,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    file1),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Write,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    file1)
            },
                eq: (left, right) => left == right,
                neq: (left, right) => left != right,
                skipHashCodeForNotEqualValues: true);

            Test.BuildXL.TestUtilities.Xunit.StructTester.TestEquality(
                baseValue:
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("x", "file5.txt")),
                equalValue:
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("x", "file5.txt")),
                notEqualValues: new[]
            {
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Denied,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("x", "file5.txt")),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    new Usn(0),
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("x", "file5.txt")),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    file1),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Denied,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    file2),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("u", "file3.txt")),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("u", "file4.txt")),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Read,
                    FileAccessStatus.Allowed,
                    false,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("x", "file5.txt")),
                ReportedFileAccess.Create(
                    ReportedFileOperation.CreateFile,
                    process,
                    RequestedAccess.Write,
                    FileAccessStatus.Allowed,
                    true,
                    0,
                    ReportedFileAccess.NoUsn,
                    DesiredAccess.GENERIC_READ,
                    ShareMode.FILE_SHARE_NONE,
                    CreationDisposition.OPEN_ALWAYS,
                    FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                    pathTable,
                    A("x", "file5.txt"))
            },
                eq: (left, right) => left == right,
                neq: (left, right) => left != right,
                skipHashCodeForNotEqualValues: true);
        }
Example #3
0
        public void ReportedFileAccessCreate()
        {
            var          pathTable = new PathTable();
            AbsolutePath file1     = AbsolutePath.Create(pathTable, A("t", "file1.txt"));

            var process = new ReportedProcess(0, string.Empty);

            ReportedFileAccess rfa1 = ReportedFileAccess.Create(
                ReportedFileOperation.CreateFile,
                process,
                RequestedAccess.Read,
                FileAccessStatus.Allowed,
                true,
                0,
                ReportedFileAccess.NoUsn,
                DesiredAccess.GENERIC_READ,
                ShareMode.FILE_SHARE_NONE,
                CreationDisposition.OPEN_ALWAYS,
                FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                file1);

            XAssert.AreEqual(rfa1.Status, FileAccessStatus.Allowed);
            XAssert.AreEqual(rfa1.ManifestPath, file1);
            XAssert.AreEqual(rfa1.Path, null);
            XAssert.AreEqual(A("t", "file1.txt"), rfa1.GetPath(pathTable));

            ReportedFileAccess rfa2 = ReportedFileAccess.Create(
                ReportedFileOperation.CreateFile,
                process,
                RequestedAccess.Read,
                FileAccessStatus.CannotDeterminePolicy,
                true,
                0,
                new Usn(0),
                DesiredAccess.GENERIC_READ,
                ShareMode.FILE_SHARE_NONE,
                CreationDisposition.OPEN_ALWAYS,
                FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                pathTable,
                A("t", "file1.txt"));

            XAssert.AreEqual(rfa2.Status, FileAccessStatus.CannotDeterminePolicy);
            XAssert.AreEqual(rfa2.ManifestPath, file1);
            XAssert.AreEqual(rfa2.Path, null);
            XAssert.AreEqual(A("t", "file1.txt"), rfa2.GetPath(pathTable));

            ReportedFileAccess rfa3 = ReportedFileAccess.Create(
                ReportedFileOperation.CreateFile,
                process,
                RequestedAccess.Read,
                FileAccessStatus.Denied,
                true,
                0,
                ReportedFileAccess.NoUsn,
                DesiredAccess.GENERIC_READ,
                ShareMode.FILE_SHARE_NONE,
                CreationDisposition.OPEN_ALWAYS,
                FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
                pathTable,
                A("t", "file2.txt"));

            XAssert.AreEqual(rfa3.Status, FileAccessStatus.Denied);
            XAssert.AreEqual(rfa3.ManifestPath, AbsolutePath.Invalid);
            XAssert.AreEqual(rfa3.Path, A("t", "file2.txt"));
            XAssert.AreEqual(A("t", "file2.txt"), rfa3.GetPath(pathTable));
        }