From 1f0cad304266fccc1f302fe3278e214d58f67c48 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Mon, 27 Jan 2020 14:34:25 -0600 Subject: [PATCH 1/2] Make FilteredMap key matching case-insensitive Fixes #152 --- .../src/main/java/com/bugsnag/util/FilteredMap.java | 2 +- .../test/java/com/bugsnag/util/FilteredMapTest.java | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bugsnag/src/main/java/com/bugsnag/util/FilteredMap.java b/bugsnag/src/main/java/com/bugsnag/util/FilteredMap.java index 1adc9269..40499e05 100644 --- a/bugsnag/src/main/java/com/bugsnag/util/FilteredMap.java +++ b/bugsnag/src/main/java/com/bugsnag/util/FilteredMap.java @@ -113,7 +113,7 @@ private boolean shouldFilterKey(String key) { } for (String filter : keyFilters) { - if (key.contains(filter)) { + if (key.toLowerCase().contains(filter.toLowerCase())) { return true; } } diff --git a/bugsnag/src/test/java/com/bugsnag/util/FilteredMapTest.java b/bugsnag/src/test/java/com/bugsnag/util/FilteredMapTest.java index 32bf424c..9aa17fbd 100644 --- a/bugsnag/src/test/java/com/bugsnag/util/FilteredMapTest.java +++ b/bugsnag/src/test/java/com/bugsnag/util/FilteredMapTest.java @@ -17,6 +17,7 @@ public class FilteredMapTest { private static final String KEY_UNFILTERED = "unfiltered"; private static final String KEY_FILTERED = "auth"; + private static final String KEY_FILTERED_UPPERCASE = "myAuth"; private static final String KEY_NESTED = "nested"; private static final String KEY_UNMODIFIABLE = "unmodifiable"; private static final String VAL_UNFILTERED = "Foo"; @@ -34,6 +35,7 @@ public void setUp() { HashMap map = new HashMap(); map.put(KEY_UNFILTERED, VAL_UNFILTERED); map.put(KEY_FILTERED, VAL_FILTERED); + map.put(KEY_FILTERED_UPPERCASE, VAL_FILTERED); HashMap nestedMap = new HashMap(); nestedMap.put(KEY_UNFILTERED, VAL_UNFILTERED); @@ -47,7 +49,7 @@ public void setUp() { @Test public void testSize() { - assertEquals(4, filteredMap.size()); + assertEquals(5, filteredMap.size()); } @Test @@ -60,7 +62,7 @@ public void testIsEmpty() { @Test public void testClear() { - assertEquals(4, filteredMap.size()); + assertEquals(5, filteredMap.size()); filteredMap.clear(); assertTrue(filteredMap.isEmpty()); } @@ -94,6 +96,7 @@ public void testRemove() { @Test public void testGet() { assertEquals(PLACEHOLDER_FILTERED, filteredMap.get(KEY_FILTERED)); + assertEquals(PLACEHOLDER_FILTERED, filteredMap.get(KEY_FILTERED_UPPERCASE)); assertEquals(VAL_UNFILTERED, filteredMap.get(KEY_UNFILTERED)); Object actual = filteredMap.get(KEY_NESTED); @@ -108,7 +111,7 @@ public void testGet() { @Test public void testKeySet() { Set keySet = filteredMap.keySet(); - assertEquals(4, keySet.size()); + assertEquals(5, keySet.size()); assertTrue(keySet.contains(KEY_FILTERED)); assertTrue(keySet.contains(KEY_UNFILTERED)); assertTrue(keySet.contains(KEY_NESTED)); @@ -117,7 +120,7 @@ public void testKeySet() { @Test public void testValues() { Collection values = filteredMap.values(); - assertEquals(4, values.size()); + assertEquals(5, values.size()); assertTrue(values.contains(VAL_UNFILTERED)); assertTrue(values.contains(PLACEHOLDER_FILTERED)); @@ -139,7 +142,7 @@ public void testValues() { @Test public void testEntrySet() { Set> entries = filteredMap.entrySet(); - assertEquals(4, entries.size()); + assertEquals(5, entries.size()); int expectedCount = 0; From f65e144dbfc2acaa4000e475c7efc57116ae9522 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Mon, 27 Jan 2020 15:53:19 -0600 Subject: [PATCH 2/2] Update BugsnagTest#testFilterHeaders --- bugsnag/src/test/java/com/bugsnag/BugsnagTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java b/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java index fe299514..5842f678 100644 --- a/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java +++ b/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java @@ -210,9 +210,9 @@ public void deliver(Serializer serializer, Object object, Map he (Map) requestTab.get("headers"); assertEquals("[FILTERED]", headersMap.get("Authorization")); - assertEquals("User:Password", headersMap.get("authorization")); + assertEquals("User:Password", headersMap.get("auth")); assertEquals("[FILTERED]", headersMap.get("Cookie")); - assertEquals("123456ABCDEF", headersMap.get("cookie")); + assertEquals("[FILTERED]", headersMap.get("x-cookie")); } @Override @@ -225,9 +225,9 @@ public void close() { public void beforeNotify(Report report) { Map headers = new HashMap(); headers.put("Authorization", "User:Password"); - headers.put("authorization", "User:Password"); + headers.put("auth", "User:Password"); headers.put("Cookie", "123456ABCDEF"); - headers.put("cookie", "123456ABCDEF"); + headers.put("x-cookie", "123456ABCDEF"); report.addToTab("request", "headers", headers); }