Changeset 19711 in josm for trunk/test


Ignore:
Timestamp:
2026-11-27T21:55:54+01:00 (2 days ago)
Author:
stoecker
Message:

reduce privacy leaks when presenting log and debug information to users, patch by wangi - fix #25141

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r19056 r19711  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertFalse;
     6import static org.junit.jupiter.api.Assertions.assertTrue;
    57
    68import java.io.IOException;
    … …  
    1012import java.nio.charset.StandardCharsets;
    1113import java.security.GeneralSecurityException;
     14import java.util.ArrayList;
     15import java.util.Collections;
     16import java.util.List;
     17import java.util.logging.Handler;
     18import java.util.logging.LogRecord;
    1219
    1320import org.junit.jupiter.api.AfterEach;
    … …  
    1724import org.openstreetmap.josm.testutils.annotations.AssertionsInEDT;
    1825import org.openstreetmap.josm.testutils.annotations.HTTPS;
     26import org.openstreetmap.josm.tools.Logging;
    1927
    2028/**
    … …  
    5462    }
    5563
     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
    56102    private void testListOfCommands(String url) throws IOException, ReflectiveOperationException {
    57103        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
Note: See TracChangeset for help on using the changeset viewer.