Skip to content

Commit

Permalink
fix: reject invalid thiing group names
Browse files Browse the repository at this point in the history
  • Loading branch information
jcosentino11 committed Aug 22, 2024
1 parent 40a78a4 commit b23cd94
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ public CreateLocalDeploymentResponse handleRequest(CreateLocalDeploymentRequest
}
}

if (request.getGroupName().contains(":")) {
throw new InvalidArgumentsError("Thing group name cannot contain colon characters");
}

LocalOverrideRequest localOverrideRequest = LocalOverrideRequest.builder().requestId(deploymentId)
.componentsToMerge(request.getRootComponentVersionsToAdd())
.componentsToRemove(request.getRootComponentsToRemove())
Expand Down
24 changes: 24 additions & 0 deletions server/src/test/java/com/aws/greengrass/cli/IPCCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient;
import software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClientV2;
import software.amazon.awssdk.aws.greengrass.model.ComponentDetails;
Expand Down Expand Up @@ -451,6 +453,28 @@ void GIVEN_kernel_running_WHEN_CLI_authorized_groups_updated_THEN_old_token_revo
}
}

@Order(11)
@ParameterizedTest
@ValueSource(strings = {"group:", "group:1", "group:1:1"})
void GIVEN_kernel_running_WHEN_local_deployment_with_invalid_thing_group_THEN_deployment_fails(String invalidThingGroupName, ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, SdkClientException.class);
ignoreExceptionOfType(context, PackageDownloadException.class);
ignoreExceptionOfType(context, ComponentVersionNegotiationException.class);

Path recipesPath = Paths.get(this.getClass().getResource("recipes").toURI());
Path artifactsPath = Paths.get(this.getClass().getResource("artifacts").toURI());

CreateLocalDeploymentRequest createLocalDeploymentRequest = new CreateLocalDeploymentRequest();
createLocalDeploymentRequest.setGroupName(invalidThingGroupName);
createLocalDeploymentRequest.setRootComponentVersionsToAdd(Collections.singletonMap("Component1", "1.0.0"));
createLocalDeploymentRequest.setRecipeDirectoryPath(recipesPath.toAbsolutePath().toString());
createLocalDeploymentRequest.setArtifactsDirectoryPath(artifactsPath.toAbsolutePath().toString());

ExecutionException executionException = assertThrows(ExecutionException.class, () ->
clientConnection.createLocalDeployment(createLocalDeploymentRequest, Optional.empty())
.getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS));
assertEquals(InvalidArgumentsError.class, executionException.getCause().getClass());
}

private String getAuthTokenFromInfoFile() throws IOException {
File[] authFiles = kernel.getNucleusPaths().cliIpcInfoPath().toFile().listFiles();
Expand Down

0 comments on commit b23cd94

Please sign in to comment.