@@ -24,7 +24,7 @@ public class StringUtilsTest {
2424 @ Test
2525 public void testCleanPasswordFromJsonObjectAtEnd () {
2626 String input = "{\" foo\" :\" bar\" ,\" password\" :\" test\" }" ;
27- //TODO: It would be nice to clean up the regex in question to not
27+ //TODO: It would be nice to clean up the regex in question to not
2828 //have to return the trailing comma in the expected string below
2929 String expected = "{\" foo\" :\" bar\" ,}" ;
3030 String result = StringUtils .cleanString (input );
@@ -78,7 +78,7 @@ public void testCleanPasswordFromRequestStringWithMultiplePasswords() {
7878 String result = StringUtils .cleanString (input );
7979 assertEquals (result , expected );
8080 }
81-
81+
8282 @ Test
8383 public void testCleanPasswordFromRequestStringMatchedAtEndSingleQuote () {
8484 String input = "'username=foo&password=bar'" ;
@@ -108,4 +108,104 @@ public void testJoin() {
108108 assertEquals ("a-b-c" , StringUtils .join ("-" , "a" , "b" , "c" ));
109109 assertEquals ("" , StringUtils .join ("-" ));
110110 }
111+
112+ @ Test
113+ public void testCleanSecretkeyFromJsonObjectAtEnd () {
114+ String input = "{\" foo\" :\" bar\" ,\" secretkey\" :\" test\" }" ;
115+ // TODO: It would be nice to clean up the regex in question to not
116+ // have to return the trailing comma in the expected string below
117+ String expected = "{\" foo\" :\" bar\" ,}" ;
118+ String result = StringUtils .cleanString (input );
119+ assertEquals (result , expected );
120+ }
121+
122+ @ Test
123+ public void testCleanSecretkeyFromJsonObjectInMiddle () {
124+ String input = "{\" foo\" :\" bar\" ,\" secretkey\" :\" test\" ,\" test\" :\" blah\" }" ;
125+ String expected = "{\" foo\" :\" bar\" ,\" test\" :\" blah\" }" ;
126+ String result = StringUtils .cleanString (input );
127+ assertEquals (result , expected );
128+ }
129+
130+ @ Test
131+ public void testCleanSecretkeyFromJsonObjectAlone () {
132+ String input = "{\" secretkey\" :\" test\" }" ;
133+ String expected = "{}" ;
134+ String result = StringUtils .cleanString (input );
135+ assertEquals (result , expected );
136+ }
137+
138+ @ Test
139+ public void testCleanSecretkeyFromJsonObjectAtStart () {
140+ String input = "{\" secretkey\" :\" test\" ,\" test\" :\" blah\" }" ;
141+ String expected = "{\" test\" :\" blah\" }" ;
142+ String result = StringUtils .cleanString (input );
143+ assertEquals (result , expected );
144+ }
145+
146+ @ Test
147+ public void testCleanSecretkeyFromJsonObjectWithMultiplePasswords () {
148+ String input = "{\" description\" :\" foo\" }],\" secretkey\" :\" bar\" ,\" nic\" :[{\" secretkey\" :\" bar2\" ,\" id\" :\" 1\" }]}" ;
149+ String expected = "{\" description\" :\" foo\" }],\" nic\" :[{\" id\" :\" 1\" }]}" ;
150+ String result = StringUtils .cleanString (input );
151+ assertEquals (result , expected );
152+ }
153+
154+ @ Test
155+ public void testCleanAccesskeyFromJsonObjectAtEnd () {
156+ String input = "{\" foo\" :\" bar\" ,\" accesskey\" :\" test\" }" ;
157+ // TODO: It would be nice to clean up the regex in question to not
158+ // have to return the trailing comma in the expected string below
159+ String expected = "{\" foo\" :\" bar\" ,}" ;
160+ String result = StringUtils .cleanString (input );
161+ assertEquals (result , expected );
162+ }
163+
164+ @ Test
165+ public void testCleanAccesskeyFromJsonObjectInMiddle () {
166+ String input = "{\" foo\" :\" bar\" ,\" accesskey\" :\" test\" ,\" test\" :\" blah\" }" ;
167+ String expected = "{\" foo\" :\" bar\" ,\" test\" :\" blah\" }" ;
168+ String result = StringUtils .cleanString (input );
169+ assertEquals (result , expected );
170+ }
171+
172+ @ Test
173+ public void testCleanAccesskeyFromJsonObjectAlone () {
174+ String input = "{\" accesskey\" :\" test\" }" ;
175+ String expected = "{}" ;
176+ String result = StringUtils .cleanString (input );
177+ assertEquals (result , expected );
178+ }
179+
180+ @ Test
181+ public void testCleanAccesskeyFromJsonObjectAtStart () {
182+ String input = "{\" accesskey\" :\" test\" ,\" test\" :\" blah\" }" ;
183+ String expected = "{\" test\" :\" blah\" }" ;
184+ String result = StringUtils .cleanString (input );
185+ assertEquals (result , expected );
186+ }
187+
188+ @ Test
189+ public void testCleanAccesskeyFromJsonObjectWithMultiplePasswords () {
190+ String input = "{\" description\" :\" foo\" }],\" accesskey\" :\" bar\" ,\" nic\" :[{\" accesskey\" :\" bar2\" ,\" id\" :\" 1\" }]}" ;
191+ String expected = "{\" description\" :\" foo\" }],\" nic\" :[{\" id\" :\" 1\" }]}" ;
192+ String result = StringUtils .cleanString (input );
193+ assertEquals (result , expected );
194+ }
195+
196+ @ Test
197+ public void testCleanAccesskeyFromRequestString () {
198+ String input = "username=foo&accesskey=bar&url=foobar" ;
199+ String expected = "username=foo&url=foobar" ;
200+ String result = StringUtils .cleanString (input );
201+ assertEquals (result , expected );
202+ }
203+
204+ @ Test
205+ public void testCleanSecretkeyFromRequestString () {
206+ String input = "username=foo&secretkey=bar&url=foobar" ;
207+ String expected = "username=foo&url=foobar" ;
208+ String result = StringUtils .cleanString (input );
209+ assertEquals (result , expected );
210+ }
111211}
0 commit comments