Changeset 19711 in josm for trunk/test
- Timestamp:
- 2026-11-27T21:55:54+01:00 (2 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java
r19056 r19711 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 5 7 6 8 import java.io.IOException; … … 10 12 import java.nio.charset.StandardCharsets; 11 13 import java.security.GeneralSecurityException; 14 import java.util.ArrayList; 15 import java.util.Collections; 16 import java.util.List; 17 import java.util.logging.Handler; 18 import java.util.logging.LogRecord; 12 19 13 20 import org.junit.jupiter.api.AfterEach; … … 17 24 import org.openstreetmap.josm.testutils.annotations.AssertionsInEDT; 18 25 import org.openstreetmap.josm.testutils.annotations.HTTPS; 26 import org.openstreetmap.josm.tools.Logging; 19 27 20 28 /** … … 54 62 } 55 63 64 /** 65 * The OAuth 2.0 authorization code of the redirect to Remote Control is not written to the log. 66 * @throws Exception if an error occurs 67 */ 68 @Test 69 void testAuthorizationCodeIsNotLogged() throws Exception { 70 final List<String> logged = Collections.synchronizedList(new ArrayList<>()); 71 final Handler handler = new Handler() { 72 @Override 73 public void publish(LogRecord logRecord) { 74 logged.add(String.valueOf(logRecord.getMessage())); 75 } 76 77 @Override 78 public void flush() { 79 // nothing to flush 80 } 81 82 @Override 83 public void close() { 84 // nothing to close 85 } 86 }; 87 Logging.getLogger().addHandler(handler); 88 try { 89 HttpURLConnection connection = (HttpURLConnection) new URL(httpBase 90 + "/oauth_authorization?code=a-secret-code&state=a-state").openConnection(); 91 connection.connect(); 92 connection.getResponseCode(); 93 connection.disconnect(); 94 } finally { 95 Logging.getLogger().removeHandler(handler); 96 } 97 final String log = String.join("\n", logged); 98 assertTrue(log.contains("RemoteControl received: GET /oauth_authorization?code=...stripped...&state=a-state"), log); 99 assertFalse(log.contains("a-secret-code"), log); 100 } 101 56 102 private void testListOfCommands(String url) throws IOException, ReflectiveOperationException { 57 103 HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
Note:
See TracChangeset
for help on using the changeset viewer.
