public void RootDirectoryDoesNotHaveParentDirectory()
        {
            var state = new FileSystemState();
            var root  = state.GetRootDirectory();

            Assert.IsNull(root.ParentDirectory);
        }
Esempio n. 2
0
        public void CreateOperation_Access_ReadAccessDenied()
        {
            var fileSystemState = new FileSystemState();
            var readAccessList  = new List <Path>()
            {
                new Path("C:/WorkingDir/ReadAccess/")
            };
            var writeAccessList = new List <Path>()
            {
                new Path("C:/WorkingDir/WriteAccess/")
            };
            var uut = new OperationGraphGenerator(fileSystemState, readAccessList, writeAccessList);

            Assert.Throws <InvalidOperationException>(
                () =>
            {
                uut.CreateOperation(
                    "Do Stuff",
                    new Path("DoStuff.exe"),
                    "do stuff",
                    new Path("C:/WorkingDir/"),
                    new List <Path>()
                {
                    new Path("ReadFile.txt"),
                },
                    new List <Path>());
            });
        }
Esempio n. 3
0
        public void NewStateHasHomeDirectory()
        {
            var state = new FileSystemState();
            var home  = state.GetHomeDirectory();

            Assert.IsNotNull(home);
        }
Esempio n. 4
0
        public void CreateOperation_NoInputOrOutput()
        {
            // Register the test listener
            var testListener = new TestTraceListener();

            using var scopedTraceListener = new ScopedTraceListenerRegister(testListener);

            var fileSystemState = new FileSystemState();
            var readAccessList  = new List <Path>();
            var writeAccessList = new List <Path>();
            var uut             = new OperationGraphGenerator(fileSystemState, readAccessList, writeAccessList);

            uut.CreateOperation(
                "Do Stuff",
                new Path("DoStuff.exe"),
                "do stuff",
                new Path("C:/WorkingDir/"),
                new List <Path>(),
                new List <Path>());

            // Verify expected logs
            Assert.Equal(
                new List <string>()
            {
                "DIAG: Create Operation: Do Stuff",
                "DIAG: Read Access Subset:",
                "DIAG: Write Access Subset:",
            },
                testListener.GetMessages());
        }
    public void RoundTripVersionReset_Deletion_Test()
    {
        string currentDir = Utility.GetRandomDirectory();
        string fileName   = Path.GetRandomFileName();
        string fullName   = Path.Combine(currentDir, fileName);

        using (var file = File.Create(fullName)) { }

        FileSystemState state = new FileSystemState(currentDir);

        state.LoadState();

        FileSystemState state2 = new FileSystemState(currentDir);

        RoundTrip(state, state2);
        File.Delete(fullName);

        try
        {
            Assert.Single(state.GetChanges());
            Assert.Single(state2.GetChanges());
        }
        finally
        {
            Directory.Delete(currentDir, true);
        }
    }
        public async Task TestAddRemoveKnownWatchedFolder()
        {
            using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt")))
            {
                KnownFolder knownFolder = New <IKnownFoldersDiscovery>().Discover().First();
                FakeDataStore.AddFolder(knownFolder.My.FullName);

                await state.AddWatchedFolderAsync(new WatchedFolder(knownFolder.My.FullName, IdentityPublicTag.Empty));

                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1));
                Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1));

                await state.RemoveAndDecryptWatchedFolder(knownFolder.My);

                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0));
                Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1));

                await state.AddWatchedFolderAsync(new WatchedFolder(knownFolder.My.FullName, IdentityPublicTag.Empty));

                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1));
                Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1));

                await state.RemoveAndDecryptWatchedFolder(knownFolder.My);

                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0));
                Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1));
            }
        }
        public void NewStateHasRootDirectory()
        {
            var state = new FileSystemState();
            var root  = state.GetRootDirectory();

            Assert.IsNotNull(root);
        }
Esempio n. 8
0
        public static void TestWatchedFolders()
        {
            using (FileSystemState state = new FileSystemState())
            {
                IRuntimeFileInfo stateInfo = OS.Current.FileInfo(_mystateXmlPath);
                state.Load(stateInfo);

                Assert.That(state.WatchedFolders, Is.Not.Null, "There should be a Watched Folders instance.");
                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should be no Watched folders.");

                state.AddWatchedFolder(new WatchedFolder(_rootPath));
                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder.");

                state.AddWatchedFolder(new WatchedFolder(_rootPath));
                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still only be one Watched Folder.");

                state.Save();
            }

            using (FileSystemState state = new FileSystemState())
            {
                IRuntimeFileInfo stateInfo = OS.Current.FileInfo(_mystateXmlPath);
                state.Load(stateInfo);

                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder.");

                Assert.That(state.WatchedFolders.First(), Is.EqualTo(new WatchedFolder(_rootPath)), "The Watched Folder should be equal to this.");

                state.RemoveWatchedFolder(new WatchedFolder(_mystateXmlPath));
                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still be one Watched folders.");

                state.RemoveWatchedFolder(new WatchedFolder(_rootPath));
                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should still be no Watched folders now.");
            }
        }
        public async Task TestForEach()
        {
            using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt")))
            {
                ActiveFile activeFile;
                activeFile = new ActiveFile(New <IDataStore>(_encrypted1AxxPath), New <IDataStore>(_decrypted1TxtPath), new LogOnIdentity("passphrase1"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId);
                state.Add(activeFile);
                activeFile = new ActiveFile(New <IDataStore>(_encrypted2AxxPath), New <IDataStore>(_decrypted2TxtPath), new LogOnIdentity("passphrase2"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId);
                state.Add(activeFile);
                activeFile = new ActiveFile(New <IDataStore>(_encrypted3AxxPath), New <IDataStore>(_decrypted3TxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId);
                state.Add(activeFile);

                Assert.That(state.ActiveFiles.Count(), Is.EqualTo(3), "There should be three.");
                int i = 0;
                await state.ForEach((ActiveFile activeFileArgument) =>
                {
                    ++i;
                    return(Task.FromResult(activeFileArgument));
                });

                Assert.That(i, Is.EqualTo(3), "The iteration should have visited three active files.");

                i = 0;
                await state.ForEach((ActiveFile activeFileArgument) =>
                {
                    ++i;
                    return(Task.FromResult(new ActiveFile(activeFileArgument, activeFile.Status | ActiveFileStatus.Error)));
                });

                Assert.That(i, Is.EqualTo(3), "The iteration should have visited three active files.");
            }
        }
Esempio n. 10
0
        public void Setup()
        {
            SetupAssembly.AssemblySetup();
            SetupAssembly.AssemblySetupCrypto(_cryptoImplementation);

            TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(New <IDataStore>(_fileSystemStateFilePath)));
        }
Esempio n. 11
0
        public static void Setup()
        {
            SetupAssembly.AssemblySetup();

            _fileSystemState = new FileSystemState();
            _fileSystemState.Load(OS.Current.FileInfo(_fileSystemStateFilePath));
        }
Esempio n. 12
0
        public static void TestDecryptedActiveFiles()
        {
            using (FileSystemState state = new FileSystemState())
            {
                state.Load(OS.Current.FileInfo(_mystateXmlPath));

                ActiveFile decryptedFile1 = new ActiveFile(OS.Current.FileInfo(_encryptedAxxPath), OS.Current.FileInfo(_decryptedTxtPath), new AesKey(), ActiveFileStatus.AssumedOpenAndDecrypted, null);
                state.Add(decryptedFile1);

                ActiveFile decryptedFile2 = new ActiveFile(OS.Current.FileInfo(_encrypted2AxxPath), OS.Current.FileInfo(_decrypted2TxtPath), new AesKey(), ActiveFileStatus.DecryptedIsPendingDelete, null);
                state.Add(decryptedFile2);

                ActiveFile notDecryptedFile = new ActiveFile(OS.Current.FileInfo(_encrypted3AxxPath), OS.Current.FileInfo(_decrypted3TxtPath), new AesKey(), ActiveFileStatus.NotDecrypted, null);
                state.Add(notDecryptedFile);

                ActiveFile errorFile = new ActiveFile(OS.Current.FileInfo(_encrypted4AxxPath), OS.Current.FileInfo(_decrypted4TxtPath), new AesKey(), ActiveFileStatus.Error, null);
                state.Add(errorFile);

                IList <ActiveFile> decryptedFiles = state.DecryptedActiveFiles;
                Assert.That(decryptedFiles.Count, Is.EqualTo(2), "There should be two decrypted files.");
                Assert.That(decryptedFiles.Contains(decryptedFile1), "A file marked as AssumedOpenAndDecrypted should be found.");
                Assert.That(decryptedFiles.Contains(decryptedFile2), "A file marked as DecryptedIsPendingDelete should be found.");
                Assert.That(decryptedFiles.Contains(notDecryptedFile), Is.Not.True, "A file marked as NotDecrypted should not be found.");
            }
        }
Esempio n. 13
0
        public static void Teardown()
        {
            _fileSystemState.Dispose();
            _fileSystemState = null;

            SetupAssembly.AssemblyTeardown();
        }
Esempio n. 14
0
    public static void FileSystemWatcher_Deleted_File()
    {
        string currentDir = Utility.GetRandomDirectory();
        string fileName   = Path.GetRandomFileName();
        string fullName   = Path.Combine(currentDir, fileName);

        FileSystemState watcher = new FileSystemState(currentDir);

        using (FileStream file = File.Create(fullName)) { }
        watcher.LoadState();
        File.Delete(fullName);
        var changes = watcher.GetChanges();

        try
        {
            Assert.Single(changes);
            FileChange change = changes[0];
            Assert.Equal(WatcherChangeTypes.Deleted, change.ChangeType);
            Assert.Equal(fileName, change.Name);
            Assert.Equal(currentDir, change.Directory);
        }
        finally
        {
            Directory.Delete(currentDir, true);
        }
    }
Esempio n. 15
0
        public async Task LoadProjectAsync(Path recipeFilePath)
        {
            var loadResult = await RecipeExtensions.TryLoadRecipeFromFileAsync(recipeFilePath);

            if (loadResult.IsSuccess)
            {
                var packageDirectory = recipeFilePath.GetParent();
                var targetPath       = await GetTargetPathAsync(packageDirectory);

                var soupTargetDirectory = targetPath + new Path(".soup/");

                var evaluateGraphFile = soupTargetDirectory + BuildConstants.GenerateEvaluateOperationGraphFileName;
                var fileSystemState   = new FileSystemState();
                if (!OperationGraphManager.TryLoadState(evaluateGraphFile, fileSystemState, out var evaluateGraph))
                {
                    NotifyError($"Failed to load Operation Graph: {evaluateGraphFile}");
                    return;
                }

                Graph = BuildGraph(fileSystemState, evaluateGraph);
            }
            else
            {
                NotifyError($"Failed to load Recipe file: {recipeFilePath}");
            }
        }
        public void SetUp()
        {
            IDataStore knownPublicKeysStore = new FakeInMemoryDataStoreItem("knownpublickeys.txt");

            TypeMap.Register.Singleton <IAsymmetricFactory>(() => new BouncyCastleAsymmetricFactory());
            TypeMap.Register.Singleton <IEmailParser>(() => new EmailParser());
            TypeMap.Register.Singleton <AxCryptOnlineState>(() => new AxCryptOnlineState());
            TypeMap.Register.Singleton <FileLocker>(() => new FileLocker());
            TypeMap.Register.Singleton <IPortableFactory>(() => new PortableFactory());
            TypeMap.Register.Singleton <INow>(() => new FakeNow());
            TypeMap.Register.Singleton <UserPublicKeyUpdateStatus>(() => new UserPublicKeyUpdateStatus());
            TypeMap.Register.Singleton <KnownIdentities>(() => new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify));
            TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("FileSystemState.txt")));
            TypeMap.Register.Singleton <WorkFolder>(() => new WorkFolder(Path.GetPathRoot(Environment.CurrentDirectory) + @"WorkFolder\"));
            TypeMap.Register.Singleton <SessionNotify>(() => new SessionNotify());
            TypeMap.Register.Singleton <UserSettingsVersion>(() => new UserSettingsVersion());
            TypeMap.Register.Singleton <ISettingsStore>(() => new SettingsStore(null));
            TypeMap.Register.Singleton <UserSettings>(() => (new FakeUserSettings(new IterationCalculator())).Initialize());

            TypeMap.Register.New <IStringSerializer>(() => new StringSerializer(New <IAsymmetricFactory>().GetSerializers()));
            TypeMap.Register.New <KnownPublicKeys>(() => KnownPublicKeys.Load(knownPublicKeysStore, Resolve.Serializer));
            TypeMap.Register.New <ILogging>(() => new Logging());
            TypeMap.Register.New <string, IDataStore>((path) => new FakeDataStore(path));
            TypeMap.Register.New <Sha256>(() => PortableFactory.SHA256Managed());
            TypeMap.Register.New <string, IDataContainer>((path) => new FakeDataContainer(path));

            New <AxCryptOnlineState>().IsOnline = true;
        }
Esempio n. 17
0
    public static void FileSystemWatcher_Recursive()
    {
        string currentDir   = Utility.GetRandomDirectory();
        string fileName     = Path.GetRandomFileName();
        string subDirectory = new DirectoryInfo(currentDir).CreateSubdirectory("sub").FullName;
        string fullName     = Path.Combine(subDirectory, fileName);

        FileSystemState watcher = new FileSystemState(currentDir, options: new EnumerationOptions {
            RecurseSubdirectories = true
        });

        watcher.LoadState();
        using (FileStream file = File.Create(fullName)) { }
        var changes = watcher.GetChanges();

        try
        {
            Assert.Single(changes);
            FileChange change = changes[0];
            Assert.Equal(WatcherChangeTypes.Created, change.ChangeType);
            Assert.Equal(fileName, change.Name);
            Assert.Equal(subDirectory, change.Directory);
        }
        finally
        {
            Directory.Delete(currentDir, true);
        }
    }
        public void NewStateHasCurrentDirectory()
        {
            var state = new FileSystemState();
            var current = state.GetCurrentDirectory();

            Assert.IsNotNull(current);
        }
        public async Task TestWatchedFolders()
        {
            using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt")))
            {
                Assert.That(state.WatchedFolders, Is.Not.Null, "There should be a Watched Folders instance.");
                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should be no Watched folders.");

                FakeDataStore.AddFolder(_rootPath);
                await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty));

                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder.");

                await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty));

                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still only be one Watched Folder.");

                await state.Save();
            }

            using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt")))
            {
                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder.");

                Assert.That(state.WatchedFolders.First().Matches(_rootPath), "The Watched Folder should be equal to this.");

                await state.RemoveAndDecryptWatchedFolder(Resolve.WorkFolder.FileInfo.FolderItemInfo("mystate.txt"));

                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still be one Watched folders.");

                await state.RemoveAndDecryptWatchedFolder(New <IDataContainer>(_rootPath));

                Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should be no Watched folders now.");
            }
        }
Esempio n. 20
0
        public void CannotDeleteFileThatDoesNotExist()
        {
            var state = new FileSystemState();
            var root  = state.GetRootDirectory();
            var isDeleteFileSuccess = _fileController.TryDeleteFile("Test", FileExtension.None, root);

            Assert.IsFalse(isDeleteFileSuccess);
        }
Esempio n. 21
0
        public void FilesInDirectoryDoNotExistUntilCreated()
        {
            var state = new FileSystemState();
            var root  = state.GetRootDirectory();

            Assert.IsNotNull(root.FilesInDirectory);
            Assert.IsEmpty(root.FilesInDirectory);
        }
Esempio n. 22
0
 public static void Initialize()
 {
     fileSystemState = new FileSystemState();
     fileSystemState.Load(FileSystemState.DefaultPathInfo);
     OS.Current.KeyWrapIterations       = fileSystemState.KeyWrapIterations;
     OS.Current.ThumbprintSalt          = fileSystemState.ThumbprintSalt;
     fileSystemState.KnownKeys.Changed += delegate { OS.Current.NotifyWorkFolderStateChanged(); };
 }
        public void CannotDeleteDirectoryThatDoesNotExist()
        {
            var state = new FileSystemState();
            var root  = state.GetRootDirectory();
            var isDeleteDirectorySuccess = _directoryController.TryDeleteDirectory("Test", root);

            Assert.IsFalse(isDeleteDirectorySuccess);
        }
Esempio n. 24
0
        public static void TestDoubleDispose()
        {
            FileSystemState state = new FileSystemState();

            state.Dispose();

            Assert.DoesNotThrow(() => { state.Dispose(); });
        }
        public void CurrentDirectoryStartsWithNoFiles()
        {
            var state = new FileSystemState();
            var current = state.GetCurrentDirectory();

            Assert.IsNotNull(current.FilesInDirectory);
            Assert.IsEmpty(current.FilesInDirectory);
        }
Esempio n. 26
0
        public void CurrentDirectoryDoesNotHaveWriteAccess()
        {
            var state         = new FileSystemState();
            var current       = state.GetCurrentDirectory();
            var currentAccess = _permissionController.GetPermissions(current);

            Assert.IsFalse(currentAccess.Write);
        }
Esempio n. 27
0
        public void RootDirectoryHasExecuteAccess()
        {
            var state      = new FileSystemState();
            var root       = state.GetRootDirectory();
            var rootAccess = _permissionController.GetPermissions(root);

            Assert.IsTrue(rootAccess.Execute);
        }
Esempio n. 28
0
        public void RootDirectoryDoesNotHaveWriteAccess()
        {
            var state      = new FileSystemState();
            var root       = state.GetRootDirectory();
            var rootAccess = _permissionController.GetPermissions(root);

            Assert.IsFalse(rootAccess.Write);
        }
Esempio n. 29
0
        public void CurrentDirectoryHasExecuteAccess()
        {
            var state         = new FileSystemState();
            var current       = state.GetCurrentDirectory();
            var currentAccess = _permissionController.GetPermissions(current);

            Assert.IsTrue(currentAccess.Execute);
        }
Esempio n. 30
0
 public void EndInit()
 {
     if (DesignMode)
     {
         return;
     }
     Current = new FileSystemState();
 }