|
13 | 13 | import java.io.InputStream; |
14 | 14 | import java.io.OutputStream; |
15 | 15 | import java.io.PrintStream; |
| 16 | +import java.io.PrintWriter; |
| 17 | +import java.io.StringWriter; |
16 | 18 | import java.net.InetSocketAddress; |
17 | 19 | import java.nio.charset.StandardCharsets; |
18 | 20 | import java.util.UUID; |
@@ -126,6 +128,35 @@ void nonSuccessHttpResponseDoesNotExposeBodyCanaryInException() throws IOExcepti |
126 | 128 | } |
127 | 129 | } |
128 | 130 |
|
| 131 | + @Test |
| 132 | + void malformedHttpEndpointDoesNotExposeCredentialsInPublicStackTrace() { |
| 133 | + String credential = "private-" + UUID.randomUUID(); |
| 134 | + OpenCliProperties properties = baseProps(1); |
| 135 | + properties.setRemoteAgentBaseUrl("http://operator:" + credential + "@invalid host"); |
| 136 | + try (OpenCliRemoteAgentHttpClient client = new OpenCliRemoteAgentHttpClient(properties)) { |
| 137 | + OpenCliCollectRequest request = OpenCliCollectRequest.builder().site("x").command("y").build(); |
| 138 | + OpenCliExecutableFailureException failure = Assertions.assertThrows( |
| 139 | + OpenCliExecutableFailureException.class, () -> client.collect(request)); |
| 140 | + StringWriter stack = new StringWriter(); |
| 141 | + failure.printStackTrace(new PrintWriter(stack)); |
| 142 | + Assertions.assertFalse(stack.toString().contains(credential)); |
| 143 | + Assertions.assertTrue(failure.getMessage().contains("correlationId=")); |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + @Test |
| 148 | + void nullEnvelopeUsesSafeCorrelatedParseFailure() throws IOException { |
| 149 | + try (JsonCollectStub stub = JsonCollectStub.start("null"); |
| 150 | + OpenCliRemoteAgentHttpClient client = new OpenCliRemoteAgentHttpClient(baseProps(stub.port()))) { |
| 151 | + OpenCliCollectRequest request = OpenCliCollectRequest.builder().site("x").command("y").build(); |
| 152 | + OpenCliExecutableFailureException failure = Assertions.assertThrows( |
| 153 | + OpenCliExecutableFailureException.class, () -> client.collect(request)); |
| 154 | + Assertions.assertTrue(failure.getMessage().contains("response envelope")); |
| 155 | + Assertions.assertTrue(failure.getMessage().contains("correlationId=")); |
| 156 | + Assertions.assertNull(failure.getCause()); |
| 157 | + } |
| 158 | + } |
| 159 | + |
129 | 160 | @Test |
130 | 161 | void malformedResponseDoesNotExposeParserSnippetInException() throws IOException { |
131 | 162 | String canary = "parser-secret-" + UUID.randomUUID(); |
|
0 commit comments