public void ExtensionInsensitive_Should_AddDetail()
        {
            var logEvent  = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);
            var sensitive = SensitiveExtensions.Insensitive <StandardLoglevel>(logEvent);

            sensitive.Details.OfType <Sensitive>().Single().IsSensitive.Should().BeFalse();
        }
        public void ExtensionSensitive_Should_AddDetail()
        {
            var logEvent  = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);
            var sensitive = SensitiveExtensions.Sensitive <StandardLoglevel>(logEvent, setupName: "test");

            sensitive.Details.OfType <Sensitive>().Single().IsSensitive.Should().BeTrue();
            sensitive.Details.OfType <Sensitive>().Single().SetupName.Should().Be("test");
        }
        public void EncryptWithSensitiveSettingsNull_ShouldThrow_ArgumentNullException()
        {
            var logEvent  = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);
            var sensitive = SensitiveExtensions.Sensitive <StandardLoglevel>(logEvent);

            Assert.Throws <ArgumentNullException>(() => sensitive.Details
                                                  .OfType <Sensitive>().Single()
                                                  .Encrypt <StandardLoglevel>(null, Encoding.UTF8.GetBytes("Test")));
        }
        public void SerializeCipher_Should_Succeed()
        {
            var logEvent  = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);
            var sensitive = SensitiveExtensions.Sensitive <StandardLoglevel>(logEvent);

            sensitive.Details
            .OfType <Sensitive>().Single()
            .Serialize(new byte[] { 0x00, 0x01, 0x02, 0x03 }).Should().NotBeEmpty();
        }
        public void SerializeCipherNull_ShouldThrow_ArgumentNullException()
        {
            var logEvent  = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);
            var sensitive = SensitiveExtensions.Sensitive <StandardLoglevel>(logEvent);

            Assert.Throws <ArgumentNullException>(() => sensitive.Details
                                                  .OfType <Sensitive>().Single()
                                                  .Serialize(null));
        }
        public void EncryptWithUnsupportedSensitiveSettings_ShouldThrow_NotSupportedException()
        {
            var logEvent  = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);
            var sensitive = SensitiveExtensions.Sensitive <StandardLoglevel>(logEvent);

            Assert.Throws <NotSupportedException>(() => sensitive.Details
                                                  .OfType <Sensitive>().Single()
                                                  .Encrypt <StandardLoglevel>(Mock.Of <ISensitiveSettings>(), Encoding.UTF8.GetBytes("Test")));
        }
        public void AddInsensitive_Should_AddSensitiveDetail()
        {
            var logEvent = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);

            SensitiveExtensions.Insensitive <StandardLoglevel>(logEvent).Should().BeSameAs(logEvent);

            var sensitive = logEvent.Details.OfType <Sensitive>().Single();

            sensitive.IsSensitive.Should().BeFalse();
            sensitive.SetupName.Should().BeNull();
            sensitive.ToString().Should().Be("Insensitive");
        }
        public void AddSensitiveWithSetupName_Should_AddSensitiveDetail()
        {
            var logEvent = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);

            SensitiveExtensions.Sensitive <StandardLoglevel>(logEvent, "test").Should().BeSameAs(logEvent);

            var sensitive = logEvent.Details.OfType <Sensitive>().Single();

            sensitive.IsSensitive.Should().BeTrue();
            sensitive.SetupName.SequenceEqual("test");
            sensitive.ToString().Should().Be("Sensitive (Setup=test)");
        }
        public void AddSensitiveWithoutSetupName_Should_AddSensitiveDetail()
        {
            var logEvent = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);

            SensitiveExtensions.Sensitive <StandardLoglevel>(logEvent).Should().BeSameAs(logEvent);

            var sensitive = new Sensitive(true, null);

            sensitive.IsSensitive.Should().BeTrue();
            sensitive.SetupName.Should().BeNull();
            sensitive.ToString().Should().StartWith("Sensitive");
        }
Beispiel #10
0
        public void Encrypt_Should_Succeed()
        {
            var logEvent  = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);
            var sensitive = SensitiveExtensions.Sensitive <StandardLoglevel>(logEvent);

            var sensitiveSettings = new Aes256SensitiveSettings(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes("secret")));
            var cipher            = sensitive.Details
                                    .OfType <Sensitive>().Single()
                                    .Encrypt <StandardLoglevel>(sensitiveSettings, Encoding.UTF8.GetBytes("Test"));

            cipher.Should().NotBeEmpty();
        }
Beispiel #11
0
        public void EncryptWithDataNull_ShouldReturn_Null()
        {
            var logEvent  = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning);
            var sensitive = SensitiveExtensions.Sensitive <StandardLoglevel>(logEvent);

            var sensitiveSettings = new Aes256SensitiveSettings(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes("secret")));
            var cipher            = sensitive.Details
                                    .OfType <Sensitive>().Single()
                                    .Encrypt <StandardLoglevel>(sensitiveSettings, null);

            cipher.Should().BeNull();
        }
Beispiel #12
0
 public void ExtensionInsensitiveLogEventNull_ShouldThrow_ArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => SensitiveExtensions.Insensitive <StandardLoglevel>(null));
 }