### Eclipse Workspace Patch 1.0
#P josm
diff --git test/unit/org/openstreetmap/josm/io/OsmConnectionTest.java test/unit/org/openstreetmap/josm/io/OsmConnectionTest.java
index f742a38..c960509 100644
|
|
|
|
| 8 | 8 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| 9 | 9 | |
| 10 | 10 | import java.net.MalformedURLException; |
| 11 | | import java.net.URL; |
| | 11 | import java.net.URI; |
| 12 | 12 | |
| 13 | 13 | import javax.swing.JOptionPane; |
| 14 | 14 | |
| … |
… |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | private static HttpClient apiRequest() throws MalformedURLException { |
| 62 | | return HttpClient.create(new URL(API_URL + "/0.6/changeset/create"), "PUT"); |
| | 62 | return HttpClient.create(URI.create(API_URL + "/0.6/changeset/create").toURL(), "PUT"); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * Stores the advanced OAuth parameters the way the authentication preferences do, that is under the API URL. |
| 67 | 67 | */ |
| 68 | 68 | private static OAuth20Parameters rememberParameters() { |
| 69 | | OAuth20Parameters parameters = new OAuth20Parameters(CLIENT_ID, null, API_URL, API_URL, REDIRECT_URI); |
| | 69 | final OAuth20Parameters parameters = new OAuth20Parameters(CLIENT_ID, null, API_URL, API_URL, REDIRECT_URI); |
| 70 | 70 | parameters.rememberPreferences(); |
| 71 | 71 | return parameters; |
| 72 | 72 | } |
| … |
… |
|
| 81 | 81 | */ |
| 82 | 82 | @Test |
| 83 | 83 | void testOAuthParametersComeFromTheApiUrl() throws Exception { |
| 84 | | OAuth20Parameters parameters = rememberParameters(); |
| | 84 | final OAuth20Parameters parameters = rememberParameters(); |
| 85 | 85 | // a token is needed, otherwise the connection would try to obtain one |
| 86 | 86 | OAuthAccessTokenHolder.getInstance().setAccessToken(API_URL, new OAuth20Token(parameters, |
| 87 | 87 | "{\"token_type\":\"bearer\", \"access_token\":\"a-token\"}")); |
| 88 | 88 | |
| 89 | | TestConnection connection = new TestConnection(); |
| | 89 | final TestConnection connection = new TestConnection(); |
| 90 | 90 | assertNull(connection.parameters()); |
| 91 | | HttpClient client = apiRequest(); |
| | 91 | final HttpClient client = apiRequest(); |
| 92 | 92 | connection.addOAuth20AuthorizationHeader(client); |
| 93 | 93 | |
| 94 | 94 | assertEquals(CLIENT_ID, connection.parameters().getClientId()); |
| … |
… |
|
| 110 | 110 | Config.getPref().putInt("message.oauth.oauth20.obtain.automatically.value", JOptionPane.NO_OPTION); |
| 111 | 111 | |
| 112 | 112 | // no parameters remembered for this API, and it has no client id built into JOSM |
| 113 | | HttpClient client = apiRequest(); |
| 114 | | MissingOAuthAccessTokenException thrown = assertThrows(MissingOAuthAccessTokenException.class, |
| | 113 | final HttpClient client = apiRequest(); |
| | 114 | final MissingOAuthAccessTokenException thrown = assertThrows(MissingOAuthAccessTokenException.class, |
| 115 | 115 | () -> new TestConnection().addOAuth20AuthorizationHeader(client)); |
| 116 | 116 | assertNotNull(thrown.getMessage(), "gave up only after asking the user, rather than for the missing client id"); |
| 117 | 117 | assertTrue(thrown.getMessage().contains(API_URL), thrown.getMessage()); |
| … |
… |
|
| 125 | 125 | */ |
| 126 | 126 | @Test |
| 127 | 127 | void testExistingTokenSignsTheConnection() throws Exception { |
| 128 | | OAuth20Parameters parameters = new OAuth20Parameters(CLIENT_ID, null, API_URL, API_URL, REDIRECT_URI); |
| | 128 | final OAuth20Parameters parameters = new OAuth20Parameters(CLIENT_ID, null, API_URL, API_URL, REDIRECT_URI); |
| 129 | 129 | OAuthAccessTokenHolder.getInstance().setAccessToken(API_URL, new OAuth20Token(parameters, |
| 130 | 130 | "{\"token_type\":\"bearer\", \"access_token\":\"another-token\"}")); |
| 131 | 131 | |
| 132 | | HttpClient client = apiRequest(); |
| | 132 | final HttpClient client = apiRequest(); |
| 133 | 133 | new TestConnection().addOAuth20AuthorizationHeader(client); |
| 134 | 134 | assertEquals("Bearer another-token", client.getRequestHeader("Authorization")); |
| 135 | 135 | } |