|
19 | 19 | import com.mongodb.connection.ServerMonitoringMode;
|
20 | 20 | import org.junit.jupiter.api.Test;
|
21 | 21 | import org.junit.jupiter.params.ParameterizedTest;
|
| 22 | +import org.junit.jupiter.params.provider.MethodSource; |
22 | 23 | import org.junit.jupiter.params.provider.ValueSource;
|
23 | 24 |
|
24 | 25 | import java.io.UnsupportedEncodingException;
|
|
27 | 28 |
|
28 | 29 | import static org.junit.jupiter.api.Assertions.assertAll;
|
29 | 30 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 31 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
30 | 32 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
31 | 33 | import static org.junit.jupiter.api.Assertions.assertNull;
|
32 | 34 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
@@ -92,4 +94,20 @@ void serverMonitoringMode() {
|
92 | 94 | () -> new ConnectionString(DEFAULT_OPTIONS + "serverMonitoringMode=invalid"))
|
93 | 95 | );
|
94 | 96 | }
|
| 97 | + |
| 98 | + |
| 99 | + @ParameterizedTest |
| 100 | + @ValueSource(strings = {"mongodb://foo:bar/@hostname/java?", "mongodb://foo:bar?@hostname/java/", |
| 101 | + "mongodb+srv://foo:bar/@hostname/java?", "mongodb+srv://foo:bar?@hostname/java/", |
| 102 | + "mongodb://foo:bar/@[::1]:27018", "mongodb://foo:bar?@[::1]:27018", |
| 103 | + "mongodb://foo:12345678/@hostname", "mongodb+srv://foo:12345678/@hostname", |
| 104 | + "mongodb://foo:12345678/@hostname", "mongodb+srv://foo:12345678/@hostname", |
| 105 | + "mongodb://foo:12345678%40hostname", "mongodb+srv://foo:12345678%40hostname", |
| 106 | + "mongodb://foo:12345678@bar@hostname", "mongodb+srv://foo:12345678@bar@hostname" |
| 107 | + }) |
| 108 | + void unescapedPasswordsShouldNotBeLeakedInExceptionMessages(final String input) { |
| 109 | + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new ConnectionString(input)); |
| 110 | + assertFalse(exception.getMessage().contains("bar")); |
| 111 | + assertFalse(exception.getMessage().contains("12345678")); |
| 112 | + } |
95 | 113 | }
|
0 commit comments