public void WhenStagedFileDoesNotMatchPathSpecFileIsNotFiltered(string pathSpec, string fileExtension, int cleanCount, int smudgeCount)
        {
            const string filterName         = "rot13";
            const string decodedInput       = "This is a substitution cipher";
            string       attributeFileEntry = string.Format("{0} filter={1}", pathSpec, filterName);

            var filterForAttributes = new List <FilterAttributeEntry> {
                new FilterAttributeEntry(filterName)
            };
            var filter = new SubstitutionCipherFilter("cipher-filter", filterForAttributes);

            var filterRegistration = GlobalSettings.RegisterFilter(filter);

            string repoPath = InitNewRepository();
            string fileName = Guid.NewGuid() + fileExtension;

            using (var repo = new Repository(repoPath))
            {
                CreateConfigurationWithDummyUser(repo, Constants.Identity);
                CreateAttributesFile(repo, attributeFileEntry);

                CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);

                Assert.Equal(cleanCount, filter.CleanCalledCount);
                Assert.Equal(smudgeCount, filter.SmudgeCalledCount);
            }

            GlobalSettings.DeregisterFilter(filterRegistration);
        }
        public void SmudgeIsCalledIfAttributeEntryMatches(string filterAttribute, string attributeEntry, int smudgeCount)
        {
            const string decodedInput = "This is a substitution cipher";

            var filterForAttributes = new List <FilterAttributeEntry> {
                new FilterAttributeEntry(filterAttribute)
            };
            var filter = new SubstitutionCipherFilter("cipher-filter", filterForAttributes);

            var filterRegistration = GlobalSettings.RegisterFilter(filter);

            string repoPath = InitNewRepository();
            string fileName = Guid.NewGuid() + ".txt";

            using (var repo = new Repository(repoPath))
            {
                CreateConfigurationWithDummyUser(repo, Constants.Identity);
                CreateAttributesFile(repo, attributeEntry);

                CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);

                var branch = repo.CreateBranch("delete-files");
                repo.Checkout(branch.FriendlyName);

                DeleteFile(repo, fileName);

                repo.Checkout("master");

                Assert.Equal(smudgeCount, filter.SmudgeCalledCount);
            }

            GlobalSettings.DeregisterFilter(filterRegistration);
        }
Esempio n. 3
0
        public void CleanIsCalledIfAttributeEntryMatches(string filterAttribute, string attributeEntry, int cleanCount)
        {
            const string decodedInput = "This is a substitution cipher";

            var filterForAttributes = new List <FilterAttributeEntry> {
                new FilterAttributeEntry(filterAttribute)
            };
            var filter = new SubstitutionCipherFilter("cipher-filter", filterForAttributes);

            var filterRegistration = GlobalSettings.RegisterFilter(filter);

            string repoPath = InitNewRepository();
            string fileName = Guid.NewGuid() + ".txt";

            string configPath        = CreateConfigurationWithDummyUser(Constants.Identity);
            var    repositoryOptions = new RepositoryOptions {
                GlobalConfigurationLocation = configPath
            };

            using (var repo = new Repository(repoPath, repositoryOptions))
            {
                CreateAttributesFile(repo, attributeEntry);

                CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);

                Assert.Equal(cleanCount, filter.CleanCalledCount);
            }

            GlobalSettings.DeregisterFilter(filterRegistration);
        }
Esempio n. 4
0
        public void CorrectlyEncodesAndDecodesInput()
        {
            const string decodedInput = "This is a substitution cipher";
            const string encodedInput = "Guvf vf n fhofgvghgvba pvcure";

            var attributes = new List <FilterAttributeEntry> {
                new FilterAttributeEntry("rot13")
            };
            var filter             = new SubstitutionCipherFilter("cipher-filter", attributes);
            var filterRegistration = GlobalSettings.RegisterFilter(filter);

            string repoPath          = InitNewRepository();
            string fileName          = Guid.NewGuid() + ".rot13";
            string configPath        = CreateConfigurationWithDummyUser(Constants.Identity);
            var    repositoryOptions = new RepositoryOptions {
                GlobalConfigurationLocation = configPath
            };

            using (var repo = new Repository(repoPath, repositoryOptions))
            {
                CreateAttributesFile(repo, "*.rot13 filter=rot13");

                var blob         = CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);
                var textDetected = blob.GetContentText();

                Assert.Equal(encodedInput, textDetected);
                Assert.Equal(1, filter.CleanCalledCount);
                Assert.Equal(0, filter.SmudgeCalledCount);

                var branch = repo.CreateBranch("delete-files");
                repo.Checkout(branch.FriendlyName);

                DeleteFile(repo, fileName);

                repo.Checkout("master");

                var fileContents = ReadTextFromFile(repo, fileName);
                Assert.Equal(1, filter.SmudgeCalledCount);
                Assert.Equal(decodedInput, fileContents);
            }

            GlobalSettings.DeregisterFilter(filterRegistration);
        }