Changeset 9934 in josm for trunk/test/unit


Ignore:
Timestamp:
2016-03-05T21:25:09+01:00 (7 years ago)
Author:
simon04
Message:

see #12584 - Add failing unit test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClientTest.java

    r9669 r9934  
    44import static org.junit.Assert.assertNotNull;
    55
     6import java.net.CookieHandler;
     7import java.net.CookieManager;
    68import java.net.MalformedURLException;
     9import java.net.URI;
    710import java.net.URL;
     11import java.util.Collections;
    812
    913import org.junit.BeforeClass;
     
    4448        //assertNotNull(accessToken);
    4549    }
     50
     51    /**
     52     * Unit test for correct cookie handling when logging in to the OSM website.
     53     *
     54     * https://josm.openstreetmap.de/ticket/12584
     55     * @throws Exception if any error occurs
     56     */
     57    @Test
     58    public void testCookieHandling() throws Exception {
     59        final OAuthParameters parameters = OAuthParameters.createDefault();
     60        final OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(parameters);
     61        assertNotNull(client.fetchOsmWebsiteSessionId());
     62
     63        // emulate Java Web Start behaviour
     64        // see https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/accessingCookies.html
     65        final CookieManager cm = new CookieManager();
     66        cm.put(new URI(parameters.getOsmLoginUrl()),
     67                Collections.singletonMap("Cookie", Collections.singletonList("_osm_session=" + String.valueOf(Math.PI).substring(2))));
     68        CookieHandler.setDefault(cm);
     69        assertNotNull(client.fetchOsmWebsiteSessionId());
     70    }
    4671}
Note: See TracChangeset for help on using the changeset viewer.