Skip to content

Commit f317a6e

Browse files
authored
Update Kafka-JUnit dependency, add tests to ensure sensitive fields c… (#63)
* Update Kafka-JUnit dependency, add tests to ensure sensitive fields cannot be logged * add missing header files
1 parent 19efcbb commit f317a6e

File tree

6 files changed

+192
-5
lines changed

6 files changed

+192
-5
lines changed

kafka-webview-ui/pom.xml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<java.version>1.8</java.version>
3333
<bootstrap.version>4.0.0-beta</bootstrap.version>
3434
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
35+
<kafka.version>0.11.0.2</kafka.version>
3536
</properties>
3637

3738
<dependencies>
@@ -46,7 +47,7 @@
4647
<dependency>
4748
<groupId>org.apache.kafka</groupId>
4849
<artifactId>kafka-clients</artifactId>
49-
<version>0.11.0.1</version>
50+
<version>${kafka.version}</version>
5051
</dependency>
5152

5253
<!-- Use ThymeLeaf 3.0.x -->
@@ -133,8 +134,25 @@
133134
<dependency>
134135
<groupId>com.salesforce.kafka.test</groupId>
135136
<artifactId>kafka-junit4</artifactId>
136-
<version>1.0.0</version>
137+
<version>2.2.0</version>
138+
<scope>test</scope>
139+
</dependency>
140+
<dependency>
141+
<groupId>org.apache.kafka</groupId>
142+
<artifactId>kafka_2.11</artifactId>
143+
<version>${kafka.version}</version>
137144
<scope>test</scope>
145+
<exclusions>
146+
<!-- Don't bring in kafka's logging framework -->
147+
<exclusion>
148+
<groupId>org.slf4j</groupId>
149+
<artifactId>slf4j-log4j12</artifactId>
150+
</exclusion>
151+
<exclusion>
152+
<groupId>javax.mail</groupId>
153+
<artifactId>mail</artifactId>
154+
</exclusion>
155+
</exclusions>
138156
</dependency>
139157
</dependencies>
140158

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/configuration/AppProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public String toString() {
7373
return "AppProperties{"
7474
+ "name='" + name + '\''
7575
+ ", uploadPath='" + uploadPath + '\''
76-
+ ", appKey='" + appKey + '\''
76+
+ ", appKey='XXXXXX'"
7777
+ ", maxConcurrentWebSocketConsumers=" + maxConcurrentWebSocketConsumers
7878
+ ", consumerIdPrefix='" + consumerIdPrefix + '\''
7979
+ '}';

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/controller/configuration/user/forms/UserForm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public String toString() {
111111
+ "id=" + id
112112
+ ", email='" + email + '\''
113113
+ ", displayName='" + displayName + '\''
114-
+ ", password='" + password + '\''
115-
+ ", password2='" + password2 + '\''
114+
+ ", password='XXXXX'"
115+
+ ", password2='XXXXX'"
116116
+ ", userRole=" + userRole
117117
+ '}';
118118
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2017, 2018 SourceLab.org (https://github.com/Crim/kafka-webview/)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package org.sourcelab.kafka.webview.ui.configuration;
26+
27+
import org.junit.Test;
28+
import java.lang.reflect.Field;
29+
30+
import static org.junit.Assert.assertFalse;
31+
32+
public class AppPropertiesTest {
33+
34+
/**
35+
* Validate toString never spits out sensitive fields.
36+
*/
37+
@Test
38+
public void testToString() throws NoSuchFieldException, IllegalAccessException {
39+
final String expectedSecret = "MySuperSecretKey";
40+
41+
// Create app Properties instance
42+
final AppProperties appProperties = new AppProperties();
43+
44+
// Jump through hoops to set property
45+
final Field field = appProperties.getClass().getDeclaredField("appKey");
46+
field.setAccessible(true);
47+
field.set(appProperties, expectedSecret);
48+
49+
final String result = appProperties.toString();
50+
assertFalse("Should not contain our sensitive field", result.contains(expectedSecret));
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2017, 2018 SourceLab.org (https://github.com/Crim/kafka-webview/)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package org.sourcelab.kafka.webview.ui.controller.configuration.user.forms;
26+
27+
import org.junit.Test;
28+
import java.lang.reflect.Field;
29+
30+
import static org.junit.Assert.*;
31+
32+
public class UserFormTest {
33+
34+
/**
35+
* Validate toString never spits out sensitive fields
36+
*/
37+
@Test
38+
public void testToString() throws IllegalAccessException, NoSuchFieldException {
39+
final String expectedSecret1 = "MySuperSecretKey";
40+
final String expectedSecret2 = "AnotherSecret";
41+
42+
// Create app Properties instance
43+
final UserForm userForm = new UserForm();
44+
45+
// Jump through hoops to set properties
46+
final Field field1 = userForm.getClass().getDeclaredField("password");
47+
field1.setAccessible(true);
48+
field1.set(userForm, expectedSecret1);
49+
50+
final Field field2 = userForm.getClass().getDeclaredField("password2");
51+
field2.setAccessible(true);
52+
field2.set(userForm, expectedSecret1);
53+
54+
final String result = userForm.toString();
55+
assertFalse("Should not contain our sensitive field", result.contains(expectedSecret1));
56+
assertFalse("Should not contain our sensitive field", result.contains(expectedSecret2));
57+
}
58+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2017, 2018 SourceLab.org (https://github.com/Crim/kafka-webview/)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package org.sourcelab.kafka.webview.ui.model;
26+
27+
import org.junit.Test;
28+
import java.lang.reflect.Field;
29+
30+
import static org.junit.Assert.assertFalse;
31+
32+
33+
public class ClusterTest {
34+
35+
/**
36+
* Validate toString never spits out sensitive fields
37+
*/
38+
@Test
39+
public void testToString() throws IllegalAccessException, NoSuchFieldException {
40+
final String expectedSecret1 = "MySuperSecretKey";
41+
final String expectedSecret2 = "AnotherSecret";
42+
43+
// Create app Properties instance
44+
final Cluster cluster = new Cluster();
45+
46+
// Jump through hoops to set properties
47+
final Field field1 = cluster.getClass().getDeclaredField("trustStorePassword");
48+
field1.setAccessible(true);
49+
field1.set(cluster, expectedSecret1);
50+
51+
final Field field2 = cluster.getClass().getDeclaredField("keyStorePassword");
52+
field2.setAccessible(true);
53+
field2.set(cluster, expectedSecret1);
54+
55+
final String result = cluster.toString();
56+
assertFalse("Should not contain our sensitive field", result.contains(expectedSecret1));
57+
assertFalse("Should not contain our sensitive field", result.contains(expectedSecret2));
58+
}
59+
}

0 commit comments

Comments
 (0)