source: josm/trunk/test/unit/org/openstreetmap/josm/gui/io/DownloadOpenChangesetsTaskTest.java@ 18991

Last change on this file since 18991 was 18991, checked in by taylor.smock, 3 months ago

Fix #22810: OSM OAuth 1.0a/Basic auth deprecation and removal

As of 2024-02-15, something changed in the OSM server configuration. This broke
our OAuth 1.0a implementation (see #23475). As such, we are removing OAuth 1.0a
from JOSM now instead of when the OSM server removes support in June 2024.

For third-party OpenStreetMap servers, the Basic Authentication method has been
kept. However, they should be made aware that it may be removed if a non-trivial
bug occurs with it. We highly recommend that the third-party servers update to
the current OpenStreetMap website implementation (if only for their own security).

Failing that, the third-party server can implement RFC8414. As of this commit,
we currently use the authorization_endpoint and token_endpoint fields.
To check and see if their third-party server implements RFC8414, they can go
to <server host>/.well-known/oauth-authorization-server.

Prominent third-party OpenStreetMap servers may give us a client id for their
specific server. That client id may be added to the hard-coded client id list
at maintainer discretion. At a minimum, the server must be publicly
available and have a significant user base.

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNotNull;
6import static org.junit.jupiter.api.Assertions.assertNull;
7import static org.junit.jupiter.api.Assertions.assertTrue;
8
9import java.awt.GraphicsEnvironment;
10import java.net.URL;
11import java.util.HashMap;
12import java.util.Map;
13
14import javax.swing.JOptionPane;
15import javax.swing.JPanel;
16
17import org.junit.jupiter.api.Test;
18import org.openstreetmap.josm.TestUtils;
19import org.openstreetmap.josm.data.UserIdentityManager;
20import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard;
21import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
22import org.openstreetmap.josm.testutils.annotations.OsmApi;
23import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
24import org.openstreetmap.josm.testutils.mockers.WindowMocker;
25import org.openstreetmap.josm.tools.UserCancelException;
26
27import mockit.Invocation;
28import mockit.Mock;
29import mockit.MockUp;
30
31/**
32 * Unit tests of {@link DownloadOpenChangesetsTask} class.
33 */
34@BasicPreferences
35@OsmApi(OsmApi.APIType.DEV)
36class DownloadOpenChangesetsTaskTest {
37 /**
38 * OAuth wizard mocker.
39 */
40 public static class OAuthWizardMocker extends MockUp<OAuthAuthorizationWizard> {
41 /** {@code true} if wizard has been called */
42 public boolean called;
43
44 @Mock
45 void showDialog() throws UserCancelException {
46 this.called = true;
47 throw new UserCancelException();
48 }
49
50 @Mock
51 void obtainAccessToken(final Invocation invocation, final URL serverUrl) {
52 if (GraphicsEnvironment.isHeadless()) {
53 // we can't really let execution proceed any further as construction of the ui
54 // elements will fail with a mocked Window
55 this.called = true;
56 return;
57 }
58 // else we can allow a bit more of the code to be covered before we raise
59 // UserCancelException in showDialog
60 invocation.proceed(serverUrl);
61 }
62 }
63
64 /**
65 * Test of {@link DownloadOpenChangesetsTask} class when anonymous.
66 */
67 @Test
68 void testAnonymous() {
69 TestUtils.assumeWorkingJMockit();
70 if (GraphicsEnvironment.isHeadless()) {
71 new WindowMocker();
72 }
73 final Map<String, Object> optionPaneMock = new HashMap<>(2);
74 optionPaneMock.put("<html>Could not retrieve the list of your open changesets because<br>JOSM does not know "
75 + "your identity.<br>You have either chosen to work anonymously or you are not "
76 + "entitled<br>to know the identity of the user on whose behalf you are working.</html>", JOptionPane.OK_OPTION);
77 optionPaneMock.put("Obtain OAuth 2.0 token for authentication?", JOptionPane.NO_OPTION);
78 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(optionPaneMock);
79
80 DownloadOpenChangesetsTask task = new DownloadOpenChangesetsTask(new JPanel());
81 assertNull(task.getChangesets());
82
83 assertTrue(UserIdentityManager.getInstance().isAnonymous());
84 task.run();
85 assertNull(task.getChangesets());
86
87 assertEquals(2, jopsMocker.getInvocationLog().size());
88 Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(1);
89 assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]);
90 assertEquals("Missing user identity", invocationLogEntry[2]);
91
92 invocationLogEntry = jopsMocker.getInvocationLog().get(0);
93 assertEquals(JOptionPane.NO_OPTION, (int) invocationLogEntry[0]);
94 assertEquals("Obtain authentication to OSM servers", invocationLogEntry[2]);
95 }
96
97 /**
98 * Test of {@link DownloadOpenChangesetsTask} class when "partially identified".
99 */
100 @Test
101 void testPartiallyIdentified() {
102 TestUtils.assumeWorkingJMockit();
103 if (GraphicsEnvironment.isHeadless()) {
104 new WindowMocker();
105 }
106 final Map<String, Object> optionPaneMock = new HashMap<>(2);
107 optionPaneMock.put("There are no open changesets", JOptionPane.OK_OPTION);
108 optionPaneMock.put("Obtain OAuth 2.0 token for authentication?", JOptionPane.NO_OPTION);
109 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(optionPaneMock);
110
111 DownloadOpenChangesetsTask task = new DownloadOpenChangesetsTask(new JPanel());
112 UserIdentityManager.getInstance().setPartiallyIdentified(System.getProperty("osm.username", "josm_test"));
113 assertTrue(UserIdentityManager.getInstance().isPartiallyIdentified());
114 task.run();
115 assertNotNull(task.getChangesets());
116
117 assertEquals(2, jopsMocker.getInvocationLog().size());
118 Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(1);
119 assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]);
120 assertEquals("No open changesets", invocationLogEntry[2]);
121
122 invocationLogEntry = jopsMocker.getInvocationLog().get(0);
123 assertEquals(JOptionPane.NO_OPTION, (int) invocationLogEntry[0]);
124 assertEquals("Obtain authentication to OSM servers", invocationLogEntry[2]);
125 }
126}
Note: See TracBrowser for help on using the repository browser.