Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIM 8631-revert old commit and add null check for security config #10656

Merged
merged 1 commit into from
Feb 14, 2025
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 @@ -62,10 +62,9 @@ public Plan applyTo(Plan oldPlan) {

var definition = result.getPlanDefinitionV4();
definition.setSelectionRule(selectionRule);
if (securityConfiguration != null) {
if (definition.getSecurity() != null) {
definition.getSecurity().setConfiguration(securityConfiguration);
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import io.gravitee.apim.core.plan.model.PlanWithFlows;
import io.gravitee.apim.infra.domain_service.plan.PlanSynchronizationLegacyWrapper;
import io.gravitee.apim.infra.json.jackson.JacksonJsonDiffProcessor;
import io.gravitee.definition.model.v4.plan.PlanMode;
import io.gravitee.definition.model.v4.plan.PlanStatus;
import io.gravitee.repository.management.model.Parameter;
import io.gravitee.rest.api.model.parameters.Key;
Expand Down Expand Up @@ -80,6 +81,8 @@ class UpdatePlanUseCaseTest {
public static final String STAGING_PLAN_API_ID = "staging-plan-api-id";
public static final String NATIVE_PLAN_ID = "native-plan-id";
public static final String NATIVE_API_ID = "native-api-id";
public static final String NEW_TEST_PLAN_ID = "newtest-plan-id";
public static final String NEW_TEST_PLAN_API_ID = "newtest-plan-api-id";
private final ObjectMapper objectMapper = new ObjectMapper();
PlanCrudServiceInMemory planCrudService = new PlanCrudServiceInMemory();
PlanQueryServiceInMemory planQueryService = new PlanQueryServiceInMemory();
Expand Down Expand Up @@ -127,15 +130,19 @@ void setUp() {
var stagingPlan = PlanFixtures.aPlanHttpV4().toBuilder().id(STAGING_PLAN_ID).apiId(STAGING_PLAN_API_ID).order(1).build();
stagingPlan.getPlanDefinitionV4().setStatus(PlanStatus.STAGING);
var nativePlan = PlanFixtures.aPlanNativeV4().toBuilder().id(NATIVE_PLAN_ID).apiId(NATIVE_API_ID).order(3).build();
List<Plan> allPlans = List.of(plan, anotherPlan, deprecatedPlan, stagingPlan, nativePlan);
var newTestPlan = PlanFixtures.aPlanHttpV4().toBuilder().id(NEW_TEST_PLAN_ID).apiId(NEW_TEST_PLAN_API_ID).order(2).build();
newTestPlan.getPlanDefinitionV4().setSecurity(null);
newTestPlan.setPlanMode(PlanMode.PUSH);
List<Plan> allPlans = List.of(plan, anotherPlan, deprecatedPlan, stagingPlan, nativePlan, newTestPlan);
planCrudService.initWith(allPlans);
planQueryService.initWith(allPlans);
apiCrudService.initWith(
List.of(
ApiFixtures.aProxyApiV4().toBuilder().id(API_ID).build(),
ApiFixtures.aProxyApiV4().toBuilder().id(DEPRECATED_PLAN_API_ID).build(),
ApiFixtures.aProxyApiV4().toBuilder().id(STAGING_PLAN_API_ID).build(),
ApiFixtures.aNativeApi().toBuilder().id(NATIVE_API_ID).build()
ApiFixtures.aNativeApi().toBuilder().id(NATIVE_API_ID).build(),
ApiFixtures.aProxyApiV4().toBuilder().id(NEW_TEST_PLAN_API_ID).build()
)
);

Expand Down Expand Up @@ -197,6 +204,54 @@ void should_update_plan(PlanUpdates updatePlan) {
);
}

@Test
void should_update_plan_when_security_is_null() {
// Given
PlanUpdates updatePlan = planMinimal().toBuilder().id(NEW_TEST_PLAN_ID).order(1).build();
var input = new UpdatePlanUseCase.Input(
updatePlan,
_api -> Collections.singletonList(FlowFixtures.aProxyFlowV4()),
NEW_TEST_PLAN_API_ID,
new AuditInfo("user-id", "user-name", AuditActor.builder().build())
);

// When
var output = updatePlanUseCase.execute(input);

// Then
assertThat(output)
.isNotNull()
.extracting(UpdatePlanUseCase.Output::updated)
.extracting(
PlanWithFlows::getId,
PlanWithFlows::getCrossId,
PlanWithFlows::getName,
PlanWithFlows::getDescription,
PlanWithFlows::getOrder,
PlanWithFlows::getCharacteristics,
PlanWithFlows::getExcludedGroups,
PlanWithFlows::isCommentRequired,
PlanWithFlows::getCommentMessage,
PlanWithFlows::getGeneralConditions,
PlanWithFlows::getPlanTags,
PlanWithFlows::getSelectionRule
)
.containsExactly(
NEW_TEST_PLAN_ID,
"my-plan-crossId",
updatePlan.getName(),
updatePlan.getDescription(),
updatePlan.getOrder(),
updatePlan.getCharacteristics(),
updatePlan.getExcludedGroups(),
updatePlan.isCommentRequired(),
updatePlan.getCommentMessage(),
updatePlan.getGeneralConditions(),
updatePlan.getTags(),
updatePlan.getSelectionRule()
);
}

@Test
void should_update_native_plan() {
// Given
Expand Down