Exemplo n.º 1
0
        public void IncompleteLineIsWrittenByDispose()
        {
            var secretTracker = new SecretTracker();

            var outputStream = new StringWriter();

            using (var secretStream = secretTracker.FilterTextWriter(outputStream))
            {
                secretStream.WriteLine("FullLine");
                secretStream.Write("IncompleteLine");
            }

            var output = outputStream.GetStringBuilder().ToString();

            Assert.AreEqual($"FullLine{Environment.NewLine}IncompleteLine", output);
        }
Exemplo n.º 2
0
        public void NullOrEmptySecretsAreIgnored()
        {
            var secretTracker = new SecretTracker();

            secretTracker.AddSecret(string.Empty);
            secretTracker.AddSecret(null);

            var outputStream = new StringWriter();

            using (var secretStream = secretTracker.FilterTextWriter(outputStream))
            {
                secretStream.WriteLine("DoesNotFail");
            }

            var output = outputStream.GetStringBuilder().ToString();

            Assert.AreEqual($"DoesNotFail{Environment.NewLine}", output);
        }
Exemplo n.º 3
0
        public void SecretIsDetectedInPartialLineFollowingNewline()
        {
            var secretTracker = new SecretTracker();

            secretTracker.AddSecret("SecretEmbedded");

            var outputStream = new StringWriter();

            using (var secretStream = secretTracker.FilterTextWriter(outputStream))
            {
                secretStream.WriteLine("FullLine");
                secretStream.Write($"IncompleteLine{Environment.NewLine}WithSecret");
                secretStream.WriteLine("EmbeddedInIt");
            }

            var output = outputStream.GetStringBuilder().ToString();

            Assert.AreEqual($"FullLine{Environment.NewLine}IncompleteLine{Environment.NewLine}With{Redacted}InIt{Environment.NewLine}", output);
        }
Exemplo n.º 4
0
        public void SecretsAreReplacedInTextStream()
        {
            var secretTracker = new SecretTracker();

            var outputStream = new StringWriter();

            using (var secretStream = secretTracker.FilterTextWriter(outputStream))
            {
                secretTracker.AddSecret("secret");
                secretStream.WriteLine("This is a secret.");

                secretTracker.AddSecret("is");
                secretStream.WriteLine("This is a secret.");
            }

            var output   = outputStream.GetStringBuilder().ToString();
            var expected = $"This is a {Redacted}.{Environment.NewLine}Th{Redacted} {Redacted} a {Redacted}.{Environment.NewLine}";

            Assert.AreEqual(expected, output);
        }
Exemplo n.º 5
0
        public void SecretsAreReplacedEvenIfTheyAreOverSmallerWrites()
        {
            var secretTracker = new SecretTracker();

            var outputStream = new StringWriter();

            using (var secretStream = secretTracker.FilterTextWriter(outputStream))
            {
                secretTracker.AddSecret("sIs5429Lon");

                // ThisIs5429Longer
                secretStream.Write("ThisIs5");
                secretStream.Write(42);
                secretStream.Write('9');
                secretStream.Write('L');
                secretStream.WriteLine("onger");
            }

            var output = outputStream.GetStringBuilder().ToString();

            Assert.AreEqual($"Thi{Redacted}ger{Environment.NewLine}", output);
        }