public async Task Should_store_body_regardless_of_the_body_size()
        {
            var fakeStorage = new FakeBodyStorage();
            // previously the max body storage default was larger than 100 KB

            var       enricher         = new BodyStorageFeature.BodyStorageEnricher(fakeStorage);
            const int ExpectedBodySize = 150000;
            var       body             = Encoding.UTF8.GetBytes(new string('a', ExpectedBodySize));

            await enricher.StoreErrorMessageBody(body, new Dictionary <string, string>(), new Dictionary <string, object>());

            Assert.AreEqual(ExpectedBodySize, fakeStorage.StoredBodySize, "Body should never be dropped for error messages");
        }
Пример #2
0
        public async Task Should_remove_body_when_above_threshold()
        {
            var fakeStorage        = new FakeBodyStorage();
            var maxBodySizeToStore = 20000;
            var settings           = new Settings
            {
                MaxBodySizeToStore = maxBodySizeToStore
            };

            var enricher = new BodyStorageFeature.BodyStorageEnricher(fakeStorage, settings);
            var body     = Encoding.UTF8.GetBytes(new string('a', maxBodySizeToStore + 1));

            await enricher.StoreAuditMessageBody(body, new Dictionary <string, string>(), new Dictionary <string, object>());

            Assert.AreEqual(0, fakeStorage.StoredBodySize, "Body should be removed if above threshold");
        }
Пример #3
0
        public async Task Should_store_body_in_storage_when_above_large_object_heap_but_below_threshold_and_not_binary()
        {
            var fakeStorage        = new FakeBodyStorage();
            var maxBodySizeToStore = 100000;
            var settings           = new Settings
            {
                MaxBodySizeToStore = maxBodySizeToStore
            };

            var enricher         = new BodyStorageFeature.BodyStorageEnricher(fakeStorage, settings);
            var expectedBodySize = BodyStorageFeature.BodyStorageEnricher.LargeObjectHeapThreshold + 1;
            var body             = Encoding.UTF8.GetBytes(new string('a', expectedBodySize));
            var metadata         = new Dictionary <string, object>();

            await enricher.StoreAuditMessageBody(body, new Dictionary <string, string>(), metadata);

            Assert.AreEqual(expectedBodySize, fakeStorage.StoredBodySize, "Body should be stored if below threshold");
            Assert.IsFalse(metadata.ContainsKey("Body"));
        }
Пример #4
0
        public async Task Should_remove_body_when_above_threshold_and_binary()
        {
            var fakeStorage        = new FakeBodyStorage();
            var maxBodySizeToStore = 20000;
            var settings           = new Settings
            {
                MaxBodySizeToStore = maxBodySizeToStore
            };

            var enricher = new BodyStorageFeature.BodyStorageEnricher(fakeStorage, settings);
            var body     = Encoding.UTF8.GetBytes(new string('a', maxBodySizeToStore + 1));
            var metadata = new Dictionary <string, object>();
            var headers  = new Dictionary <string, string> {
                { Headers.ContentType, "application/binary" }
            };

            await enricher.StoreAuditMessageBody(body, headers, metadata);

            Assert.AreEqual(0, fakeStorage.StoredBodySize, "Body should be removed if above threshold");
            Assert.IsFalse(metadata.ContainsKey("Body"));
        }