Skip to content

Commit

Permalink
EPMRPP-94930 check for valid rally urls (#40)
Browse files Browse the repository at this point in the history
* EPMRPP-94930 check for valid rally urls
  • Loading branch information
grabsefx authored Dec 17, 2024
1 parent 335ff73 commit ebb104f
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencyManagement {
}
}

ext['junit-jupiter.version'] = "${junitVersion}"

dependencies {
if (releaseMode) {
implementation 'com.epam.reportportal:commons-dao'
Expand All @@ -55,6 +57,11 @@ dependencies {
implementation 'net.oauth.core:oauth-httpclient4:20090913'
implementation 'org.apache.tika:tika-core:1.14'
implementation 'javax.inject:javax.inject:1'

testImplementation "org.junit.jupiter:junit-jupiter"
testImplementation "org.junit.jupiter:junit-jupiter-params"
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "org.junit.jupiter:junit-jupiter-engine"
}

wrapper {
Expand Down Expand Up @@ -105,3 +112,15 @@ task assemblePlugin(type: Copy) {
task assemblePlugins(type: Copy) {
dependsOn subprojects.assemblePlugin
}

test {
useJUnitPlatform()
maxParallelForks = 1
testLogging {
events = ['failed']
exceptionFormat = 'short'
}
reports {
junitXml.required = true
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version=5.12.0
description=EPAM Report portal. Rally Integration Plugin
pluginId = rally
junitVersion=5.11.0
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.epam.reportportal.extension.bugtracking.BtsExtension;
import com.epam.reportportal.extension.bugtracking.InternalTicket;
import com.epam.reportportal.extension.bugtracking.InternalTicketAssembler;
import com.epam.reportportal.extension.bugtracking.rally.validator.IntegrationValidator;
import com.epam.reportportal.extension.util.FileNameExtractor;
import com.epam.reportportal.model.externalsystem.AllowedValue;
import com.epam.reportportal.model.externalsystem.PostFormField;
Expand Down Expand Up @@ -171,6 +172,7 @@ public boolean testConnection(Integration integration) {
.orElseThrow(() -> new ReportPortalException(UNABLE_INTERACT_WITH_INTEGRATION,
"Rally Project value cannot be NULL"
));
IntegrationValidator.validateThirdPartyUrl(integration);

try (RallyRestApi restApi = getClient(integration.getParams())) {
QueryRequest rq = new QueryRequest(PROJECT);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.extension.bugtracking.rally.validator;

import com.epam.reportportal.rules.commons.validation.BusinessRule;
import com.epam.reportportal.rules.commons.validation.Suppliers;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.ta.reportportal.commons.Predicates;
import com.epam.ta.reportportal.entity.integration.Integration;

/**
* @author <a href="mailto:[email protected]">Siarhei Hrabko</a>
*/
public final class IntegrationValidator {

private static final String RALLY_BASE_URL = "https://rally1.rallydev.com";

private IntegrationValidator() {
//static only
}


/**
* Validates Validates Rally server url.
*
* @param integration {@link Integration}
*/
public static void validateThirdPartyUrl(Integration integration) {
var valid = String.valueOf(integration.getParams().getParams().get("url"))
.startsWith(RALLY_BASE_URL);

BusinessRule.expect(valid, Predicates.equalTo(true))
.verify(ErrorType.BAD_REQUEST_ERROR,
Suppliers.formattedSupplier("Integration url is not acceptable")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.extension.bugtracking.rally.validator;

import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.entity.integration.IntegrationParams;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class IntegrationValidatorTest {

@ParameterizedTest
@CsvSource(value = {
"https://rally1.rallydev.com",
"https://rally1.rallydev.com/"
}, delimiter = ',')
void validateThirdPartyUrl(String url) {
Assertions.assertDoesNotThrow(() ->
IntegrationValidator.validateThirdPartyUrl(getIntegration(url)));
}

@ParameterizedTest
@CsvSource(value = {
"http://rally1.rallydev.com",
"https://zloi.hacker.com"
}, delimiter = ',')
void validateThirdPartyUrlFailed(String url) {
Assertions.assertThrows(ReportPortalException.class, () ->
IntegrationValidator.validateThirdPartyUrl(getIntegration(url)));
}

private static Integration getIntegration(String url) {
Map<String, Object> params = new HashMap<>();
params.put("url", url);

IntegrationParams integrationParams = new IntegrationParams();
integrationParams.setParams(params);

Integration integration = new Integration();
integration.setParams(integrationParams);

return integration;
}

}

0 comments on commit ebb104f

Please sign in to comment.