StringUtils { public static String cleanString(final String stringToClean) { String cleanResult = ""; if (stringToClean != null) { cleanResult = REGEX_PASSWORD_QUERYSTRING.matcher(stringToClean).replaceAll(""); cleanResult = REGEX_PASSWORD_JSON.matcher(cleanResult).replaceAll(""); final Matcher detailsMatcher = REGEX_PASSWORD_DETAILS.matcher(cleanResult); while (detailsMatcher.find()) { final Matcher detailsIndexMatcher = REGEX_PASSWORD_DETAILS_INDEX.matcher(detailsMatcher.group()); if (detailsIndexMatcher.find()) { cleanResult = cleanDetails(cleanResult, detailsIndexMatcher.group()); } } } return cleanResult; }  static Charset getPreferredCharset(); static boolean isUtf8Supported(); static String join(final Iterable<? extends Object> iterable, final String delim); static String join(final String delimiter, final Object... components); static boolean isNotBlank(final String str); static String cleanupTags(String tags); static List<String> csvTagsToList(final String tags); static String listToCsvTags(final List<String> tagsList); static String getExceptionStackInfo(final Throwable e); static String unicodeEscape(final String s); static String getMaskedPasswordForDisplay(final String password); static String cleanString(final String stringToClean); static String cleanDetails(final String stringToClean, final String detailsIndexSting); static boolean areTagsEqual(final String tags1, final String tags2); static String stripControlCharacters(final String s); static int formatForOutput(final String text, final int start, final int columns, final char separator); static Map<String, String> stringToMap(final String s); static String mapToString(final Map<String, String> map); static List<T> applyPagination(final List<T> originalList, final Long startIndex, final Long pageSizeVal);  }
@Test public void testCleanPasswordFromJsonObjectAtEnd() { final String input = "{\"foo\":\"bar\",\"password\":\"test\"}"; final String expected = "{\"foo\":\"bar\",}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromJsonObjectInMiddle() { final String input = "{\"foo\":\"bar\",\"password\":\"test\",\"test\":\"blah\"}"; final String expected = "{\"foo\":\"bar\",\"test\":\"blah\"}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromJsonObjectAlone() { final String input = "{\"password\":\"test\"}"; final String expected = "{}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromJsonObjectAtStart() { final String input = "{\"password\":\"test\",\"test\":\"blah\"}"; final String expected = "{\"test\":\"blah\"}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromJsonObjectWithMultiplePasswords() { final String input = "{\"description\":\"foo\"}],\"password\":\"bar\",\"nic\":[{\"password\":\"bar2\",\"id\":\"1\"}]}"; final String expected = "{\"description\":\"foo\"}],\"nic\":[{\"id\":\"1\"}]}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromRequestString() { final String input = "username=foo&password=bar&url=foobar"; final String expected = "username=foo&url=foobar"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromEncodedRequestString() { final String input = "name=SS1&provider=SMB&zoneid=5a60af2b-3025-4f2a-9ecc-8e33bf2b94e3&url=cifs%3A%2F%2F10.102.192.150%2FSMB-Share%2Fsowmya%2Fsecondary%3Fuser%3Dsowmya%26password%3DXXXXX%40123%26domain%3DBLR"; final String expected = "name=SS1&provider=SMB&zoneid=5a60af2b-3025-4f2a-9ecc-8e33bf2b94e3&url=cifs%3A%2F%2F10.102.192.150%2FSMB-Share%2Fsowmya%2Fsecondary%3Fuser%3Dsowmya%26domain%3DBLR"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromRequestStringWithMultiplePasswords() { final String input = "username=foo&password=bar&url=foobar&password=bar2&test=4"; final String expected = "username=foo&url=foobar&test=4"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromRequestStringMatchedAtEndSingleQuote() { final String input = "'username=foo&password=bar'"; final String expected = "'username=foo'"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromRequestStringMatchedAtEndDoubleQuote() { final String input = "\"username=foo&password=bar\""; final String expected = "\"username=foo\""; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanPasswordFromRequestStringMatchedAtMiddleDoubleQuote() { final String input = "\"username=foo&password=bar&goo=sdf\""; final String expected = "\"username=foo&goo=sdf\""; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanSecretkeyFromJsonObjectAtEnd() { final String input = "{\"foo\":\"bar\",\"secretkey\":\"test\"}"; final String expected = "{\"foo\":\"bar\",}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanSecretkeyFromJsonObjectInMiddle() { final String input = "{\"foo\":\"bar\",\"secretkey\":\"test\",\"test\":\"blah\"}"; final String expected = "{\"foo\":\"bar\",\"test\":\"blah\"}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanSecretkeyFromJsonObjectAlone() { final String input = "{\"secretkey\":\"test\"}"; final String expected = "{}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanSecretkeyFromJsonObjectAtStart() { final String input = "{\"secretkey\":\"test\",\"test\":\"blah\"}"; final String expected = "{\"test\":\"blah\"}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanSecretkeyFromJsonObjectWithMultiplePasswords() { final String input = "{\"description\":\"foo\"}],\"secretkey\":\"bar\",\"nic\":[{\"secretkey\":\"bar2\",\"id\":\"1\"}]}"; final String expected = "{\"description\":\"foo\"}],\"nic\":[{\"id\":\"1\"}]}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanAccesskeyFromJsonObjectAtEnd() { final String input = "{\"foo\":\"bar\",\"accesskey\":\"test\"}"; final String expected = "{\"foo\":\"bar\",}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanAccesskeyFromJsonObjectInMiddle() { final String input = "{\"foo\":\"bar\",\"accesskey\":\"test\",\"test\":\"blah\"}"; final String expected = "{\"foo\":\"bar\",\"test\":\"blah\"}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanAccesskeyFromJsonObjectAlone() { final String input = "{\"accesskey\":\"test\"}"; final String expected = "{}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanAccesskeyFromJsonObjectAtStart() { final String input = "{\"accesskey\":\"test\",\"test\":\"blah\"}"; final String expected = "{\"test\":\"blah\"}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanAccesskeyFromJsonObjectWithMultiplePasswords() { final String input = "{\"description\":\"foo\"}],\"accesskey\":\"bar\",\"nic\":[{\"accesskey\":\"bar2\",\"id\":\"1\"}]}"; final String expected = "{\"description\":\"foo\"}],\"nic\":[{\"id\":\"1\"}]}"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanAccesskeyFromRequestString() { final String input = "username=foo&accesskey=bar&url=foobar"; final String expected = "username=foo&url=foobar"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }
@Test public void testCleanSecretkeyFromRequestString() { final String input = "username=foo&secretkey=bar&url=foobar"; final String expected = "username=foo&url=foobar"; final String result = StringUtils.cleanString(input); assertEquals(result, expected); }