Skip to content

Commit bf9da81

Browse files
authored
Merge pull request #50 from blackducksoftware/mc_plugin_install_fixes
IALERT_3130: Fix broken headers in marketplace install
2 parents c4e2fdf + b12dc2b commit bf9da81

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

src/main/java/com/synopsys/integration/jira/common/rest/service/PluginManagerService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,14 @@ public String retrievePluginToken() throws IntegrationException {
134134
requestBuilder.addQueryParameter(QUERY_KEY_OS_AUTH_TYPE, QUERY_VALUE_OS_AUTH_TYPE);
135135
requestBuilder.method(HttpMethod.GET);
136136
requestBuilder.addHeader(ACCEPT_HEADER, MEDIA_TYPE_INSTALLED);
137-
Map<String, String> response = jiraApiClient.getResponseHeaders(requestBuilder.build());
138-
return response.get("upm-token");
137+
JiraRequest request = requestBuilder.build();
138+
Map<String, String> response = jiraApiClient.getResponseHeaders(request);
139+
// Jira Cloud had a breaking change in its public API where the "upm-token" was renamed for their credential client
140+
// This change will support the new header name but keep the functionality of the old headers which are still used
141+
// by the OAuth client and Jira Server.
142+
Optional<String> pluginToken = Optional.ofNullable(response.get("upm-token"));
143+
return pluginToken.or(() -> Optional.ofNullable(response.get("Upm-Token")))
144+
.orElseThrow(() -> new IntegrationException("Jira upm-token not found."));
139145
}
140146

141147
private AvailableAppResponseModel getAvailableApp(String path, String appKey) throws IntegrationException {

src/test/java/com/synopsys/integration/jira/common/cloud/service/JiraCloudAppServiceTestIT.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import com.synopsys.integration.rest.RestConstants;
2222
import com.synopsys.integration.rest.exception.IntegrationRestException;
2323

24-
public class JiraCloudAppServiceTestIT extends JiraCloudParameterizedTestIT {
25-
private static final int WAIT_TIME = 1000;
24+
class JiraCloudAppServiceTestIT extends JiraCloudParameterizedTestIT {
25+
private static final int WAIT_TIME = 10000;
2626
private static final String APP_KEY = "com.synopsys.integration.alert";
2727
private static final String APP_CLOUD_URI = "https://blackducksoftware.github.io/alert-issue-property-indexer/JiraCloudApp/1.0.0/atlassian-connect.json";
2828

@@ -33,8 +33,7 @@ public void waitForUninstallToFinish() throws InterruptedException {
3333

3434
@ParameterizedTest
3535
@MethodSource("getParameters")
36-
@Disabled("This test is flaky as it occasionally takes too long to install and fails the test")
37-
public void installMarketplaceAppTest(JiraHttpClient jiraHttpClient) throws Exception {
36+
void installMarketplaceAppTest(JiraHttpClient jiraHttpClient) throws Exception {
3837
JiraCloudServiceTestUtility.validateConfiguration();
3938
JiraCloudServiceFactory serviceFactory = JiraCloudServiceTestUtility.createServiceFactory(jiraHttpClient);
4039
PluginManagerService pluginManagerService = serviceFactory.createPluginManagerService();
@@ -49,7 +48,7 @@ public void installMarketplaceAppTest(JiraHttpClient jiraHttpClient) throws Exce
4948
@ParameterizedTest
5049
@MethodSource("getParameters")
5150
@Disabled("Disabled because development mode will likely not be turned on most of the time")
52-
public void installCloudDevelopmentAppTest(JiraHttpClient jiraHttpClient) throws Exception {
51+
void installCloudDevelopmentAppTest(JiraHttpClient jiraHttpClient) throws Exception {
5352
JiraCloudServiceTestUtility.validateConfiguration();
5453
JiraCloudServiceFactory serviceFactory = JiraCloudServiceTestUtility.createServiceFactory(jiraHttpClient);
5554
PluginManagerService pluginManagerService = serviceFactory.createPluginManagerService();
@@ -63,8 +62,7 @@ public void installCloudDevelopmentAppTest(JiraHttpClient jiraHttpClient) throws
6362

6463
@ParameterizedTest
6564
@MethodSource("getParameters")
66-
@Disabled("This test is flaky as it occasionally takes too long to install and fails the test")
67-
public void getInstalledAppsTest(JiraHttpClient jiraHttpClient) throws IntegrationException, InterruptedException {
65+
void getInstalledAppsTest(JiraHttpClient jiraHttpClient) throws IntegrationException, InterruptedException {
6866
JiraCloudServiceTestUtility.validateConfiguration();
6967
JiraCloudServiceFactory serviceFactory = JiraCloudServiceTestUtility.createServiceFactory(jiraHttpClient);
7068
PluginManagerService pluginManagerService = serviceFactory.createPluginManagerService();

src/test/java/com/synopsys/integration/jira/common/rest/service/PluginManagerServiceServerTestIT.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.synopsys.integration.jira.common.rest.service;
22

3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
35
import org.junit.jupiter.params.ParameterizedTest;
46
import org.junit.jupiter.params.provider.MethodSource;
57

@@ -9,11 +11,11 @@
911
import com.synopsys.integration.jira.common.server.JiraServerServiceTestUtility;
1012
import com.synopsys.integration.jira.common.server.service.JiraServerServiceFactory;
1113

12-
public class PluginManagerServiceServerTestIT extends JiraServerParameterizedTestIT {
14+
class PluginManagerServiceServerTestIT extends JiraServerParameterizedTestIT {
1315

1416
@ParameterizedTest
1517
@MethodSource("getParameters")
16-
public void createIssueTest(JiraHttpClient jiraHttpClient) throws IntegrationException {
18+
void createIssueTest(JiraHttpClient jiraHttpClient) throws IntegrationException {
1719
JiraServerServiceTestUtility.validateConfiguration();
1820

1921
JiraServerServiceFactory serviceFactory = JiraServerServiceTestUtility.createServiceFactory(jiraHttpClient);
@@ -22,4 +24,16 @@ public void createIssueTest(JiraHttpClient jiraHttpClient) throws IntegrationExc
2224
boolean appInstalled = pluginManagerService.isAppInstalled("com.synopsys.integration.alert");
2325
System.out.println("App is installed " + appInstalled);
2426
}
27+
28+
@ParameterizedTest
29+
@MethodSource("getParameters")
30+
void retrievePluginTokenJiraServerCredentialClientTest(JiraHttpClient jiraHttpClient) throws IntegrationException {
31+
JiraServerServiceTestUtility.validateConfiguration();
32+
33+
JiraServerServiceFactory serviceFactory = JiraServerServiceTestUtility.createServiceFactory(jiraHttpClient);
34+
PluginManagerService pluginManagerService = serviceFactory.createPluginManagerService();
35+
36+
String pluginToken = pluginManagerService.retrievePluginToken();
37+
assertNotNull(pluginToken);
38+
}
2539
}

0 commit comments

Comments
 (0)