Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ private List<String> computeSharedLocations(String[] restrictionLocations, List<
// We also put everything on lower case, to ensure String comparisons
Set<String> restrictionSet = Optional.ofNullable(restrictionLocations)
.map(locations -> Arrays.stream(restrictionLocations)
.map(String::toLowerCase)
.collect(Collectors.toSet()) )
.orElse(Collections.emptySet());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.opendevstack.component_catalog.org.opendevstack.component_catalog.server.model;

import org.opendevstack.component_catalog.server.model.CatalogItemUserActionParameterLocation;

public class CatalogItemUserActionParameterLocationMother {

public static CatalogItemUserActionParameterLocation of() {
return of("eu-mother-location");
}

public static CatalogItemUserActionParameterLocation of(String location) {
return CatalogItemUserActionParameterLocation.builder()
.location(location)
.value("1234")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opendevstack.component_catalog.server.mother;

import org.opendevstack.component_catalog.org.opendevstack.component_catalog.server.model.CatalogItemUserActionParameterLocationMother;
import org.opendevstack.component_catalog.server.model.CatalogItemUserActionParameter;
import org.opendevstack.component_catalog.server.model.CatalogItemUserActionParameterLocation;
import org.opendevstack.component_catalog.server.model.CatalogItemUserActionParameterValidation;
Expand All @@ -14,22 +15,26 @@ public static CatalogItemUserActionParameter of() {
return of("CatalogItemUserActionParameter Name");
}

public static CatalogItemUserActionParameter of(List<String> locations) {
return of("CatalogItemUserActionParameter Name", locations);
}

public static CatalogItemUserActionParameter of(String name) {
return of(name, "CatalogItemUserActionParameter Type", List.of(CatalogItemUserActionParameterValidationMother.of()));
}

public static CatalogItemUserActionParameter of(String name, List<String> locations) {
return of(name, "CatalogItemUserActionParameter Type", List.of(CatalogItemUserActionParameterValidationMother.of()), locations);
}

public static CatalogItemUserActionParameter of(String name, String type) {
return of(name, type, Collections.emptyList());
}


public static CatalogItemUserActionParameter of(String name, String type, List<CatalogItemUserActionParameterValidation> validations, List<String> locations) {
var locationObjects = locations.stream()
.map(loc -> {
var l = new CatalogItemUserActionParameterLocation();
l.setLocation(loc);
return l;
}).toList();
.map(CatalogItemUserActionParameterLocationMother::of).toList();
return CatalogItemUserActionParameter.builder()
.name(name)
.type(type)
Expand Down Expand Up @@ -58,4 +63,5 @@ public static CatalogItemUserActionParameter of(String name, String type, List<C
.validations(validations)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opendevstack.component_catalog.server.services.restrictions.evaluators;

import org.apache.commons.lang3.tuple.Pair;
import org.opendevstack.component_catalog.server.model.CatalogItemUserActionParameter;
import org.opendevstack.component_catalog.server.model.CatalogItemUserActionParameterLocation;
import org.opendevstack.component_catalog.server.mother.CatalogItemUserActionParameterMother;
Expand All @@ -10,6 +11,7 @@
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

class LocationsRestrictionsEvaluatorTest {
Expand Down Expand Up @@ -232,4 +234,29 @@ void givenRestrictionsWithTwoClusters_AndParamsWithOneCluster_whenEvaluate_AndPa
assertEquals("This product is not provisionable in the project location.", result.getRight());
}

@Test
void GivenRestrictionExpectsLowercaseEu_whenParameterLocationsIsUppercaseEU_thenFails() {
// given
var projectKey = "projectKey";
var restrictions = UserActionEntityRestrictionsMother.of(new String[]{"us-test", "eu"});

var evaluationRestrictions = new EvaluationRestrictions(projectKey, restrictions);

var params = RestrictionsParamsMother.of(
List.of(CatalogItemUserActionParameterMother.of(List.of("us-test", "EU", "US-DEV"))), // no parameters → simplest path
null
);

// when
Pair<Boolean, String> result = evaluator.evaluate(evaluationRestrictions, params);

// then
assertThat(result.getLeft())
.as("Uppercase 'EU' should NOT match lowercase 'eu'")
.isFalse();

assertThat(result.getRight())
.isEqualTo("This product is not provisionable in the project location.");
}

}