Skip to content

Commit ebb104f

Browse files
authored
EPMRPP-94930 check for valid rally urls (#40)
* EPMRPP-94930 check for valid rally urls
1 parent 335ff73 commit ebb104f

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

build.gradle

+19
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ dependencyManagement {
3838
}
3939
}
4040

41+
ext['junit-jupiter.version'] = "${junitVersion}"
42+
4143
dependencies {
4244
if (releaseMode) {
4345
implementation 'com.epam.reportportal:commons-dao'
@@ -55,6 +57,11 @@ dependencies {
5557
implementation 'net.oauth.core:oauth-httpclient4:20090913'
5658
implementation 'org.apache.tika:tika-core:1.14'
5759
implementation 'javax.inject:javax.inject:1'
60+
61+
testImplementation "org.junit.jupiter:junit-jupiter"
62+
testImplementation "org.junit.jupiter:junit-jupiter-params"
63+
testImplementation "org.junit.jupiter:junit-jupiter-api"
64+
testImplementation "org.junit.jupiter:junit-jupiter-engine"
5865
}
5966

6067
wrapper {
@@ -105,3 +112,15 @@ task assemblePlugin(type: Copy) {
105112
task assemblePlugins(type: Copy) {
106113
dependsOn subprojects.assemblePlugin
107114
}
115+
116+
test {
117+
useJUnitPlatform()
118+
maxParallelForks = 1
119+
testLogging {
120+
events = ['failed']
121+
exceptionFormat = 'short'
122+
}
123+
reports {
124+
junitXml.required = true
125+
}
126+
}

gradle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
version=5.12.0
22
description=EPAM Report portal. Rally Integration Plugin
33
pluginId = rally
4+
junitVersion=5.11.0

src/main/java/com/epam/reportportal/extension/bugtracking/rally/RallyStrategy.java

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.epam.reportportal.extension.bugtracking.BtsExtension;
5353
import com.epam.reportportal.extension.bugtracking.InternalTicket;
5454
import com.epam.reportportal.extension.bugtracking.InternalTicketAssembler;
55+
import com.epam.reportportal.extension.bugtracking.rally.validator.IntegrationValidator;
5556
import com.epam.reportportal.extension.util.FileNameExtractor;
5657
import com.epam.reportportal.model.externalsystem.AllowedValue;
5758
import com.epam.reportportal.model.externalsystem.PostFormField;
@@ -171,6 +172,7 @@ public boolean testConnection(Integration integration) {
171172
.orElseThrow(() -> new ReportPortalException(UNABLE_INTERACT_WITH_INTEGRATION,
172173
"Rally Project value cannot be NULL"
173174
));
175+
IntegrationValidator.validateThirdPartyUrl(integration);
174176

175177
try (RallyRestApi restApi = getClient(integration.getParams())) {
176178
QueryRequest rq = new QueryRequest(PROJECT);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2024 EPAM Systems
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.epam.reportportal.extension.bugtracking.rally.validator;
18+
19+
import com.epam.reportportal.rules.commons.validation.BusinessRule;
20+
import com.epam.reportportal.rules.commons.validation.Suppliers;
21+
import com.epam.reportportal.rules.exception.ErrorType;
22+
import com.epam.ta.reportportal.commons.Predicates;
23+
import com.epam.ta.reportportal.entity.integration.Integration;
24+
25+
/**
26+
* @author <a href="mailto:[email protected]">Siarhei Hrabko</a>
27+
*/
28+
public final class IntegrationValidator {
29+
30+
private static final String RALLY_BASE_URL = "https://rally1.rallydev.com";
31+
32+
private IntegrationValidator() {
33+
//static only
34+
}
35+
36+
37+
/**
38+
* Validates Validates Rally server url.
39+
*
40+
* @param integration {@link Integration}
41+
*/
42+
public static void validateThirdPartyUrl(Integration integration) {
43+
var valid = String.valueOf(integration.getParams().getParams().get("url"))
44+
.startsWith(RALLY_BASE_URL);
45+
46+
BusinessRule.expect(valid, Predicates.equalTo(true))
47+
.verify(ErrorType.BAD_REQUEST_ERROR,
48+
Suppliers.formattedSupplier("Integration url is not acceptable")
49+
);
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2024 EPAM Systems
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.epam.reportportal.extension.bugtracking.rally.validator;
18+
19+
import com.epam.reportportal.rules.exception.ReportPortalException;
20+
import com.epam.ta.reportportal.entity.integration.Integration;
21+
import com.epam.ta.reportportal.entity.integration.IntegrationParams;
22+
import java.util.HashMap;
23+
import java.util.Map;
24+
import org.junit.jupiter.api.Assertions;
25+
import org.junit.jupiter.params.ParameterizedTest;
26+
import org.junit.jupiter.params.provider.CsvSource;
27+
28+
class IntegrationValidatorTest {
29+
30+
@ParameterizedTest
31+
@CsvSource(value = {
32+
"https://rally1.rallydev.com",
33+
"https://rally1.rallydev.com/"
34+
}, delimiter = ',')
35+
void validateThirdPartyUrl(String url) {
36+
Assertions.assertDoesNotThrow(() ->
37+
IntegrationValidator.validateThirdPartyUrl(getIntegration(url)));
38+
}
39+
40+
@ParameterizedTest
41+
@CsvSource(value = {
42+
"http://rally1.rallydev.com",
43+
"https://zloi.hacker.com"
44+
}, delimiter = ',')
45+
void validateThirdPartyUrlFailed(String url) {
46+
Assertions.assertThrows(ReportPortalException.class, () ->
47+
IntegrationValidator.validateThirdPartyUrl(getIntegration(url)));
48+
}
49+
50+
private static Integration getIntegration(String url) {
51+
Map<String, Object> params = new HashMap<>();
52+
params.put("url", url);
53+
54+
IntegrationParams integrationParams = new IntegrationParams();
55+
integrationParams.setParams(params);
56+
57+
Integration integration = new Integration();
58+
integration.setParams(integrationParams);
59+
60+
return integration;
61+
}
62+
63+
}

0 commit comments

Comments
 (0)