-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPMRPP-94930 check for valid rally urls (#40)
* EPMRPP-94930 check for valid rally urls
- Loading branch information
Showing
5 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ava/com/epam/reportportal/extension/bugtracking/rally/validator/IntegrationValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...com/epam/reportportal/extension/bugtracking/rally/validator/IntegrationValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |