Skip to content

Commit 39c8b16

Browse files
committed
action name check
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 2abe27a commit 39c8b16

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ protected Map<String, String> getFilteredExternalDetails(Map<String, String> det
404404
Map.Entry::getValue
405405
));
406406
}
407+
407408
protected void sendExtensionEntryPointOutOfSyncAlert(Extension extension) {
408409
String msg = String.format("Entry-point for %s are out of sync across management servers",
409410
extension);
@@ -927,6 +928,10 @@ public ExtensionCustomAction addCustomAction(AddCustomActionCmd cmd) {
927928
final String successMessage = cmd.getSuccessMessage();
928929
final String errorMessage = cmd.getErrorMessage();
929930
Map<String, String> details = cmd.getDetails();
931+
if (name == null || !name.matches("^[a-zA-Z0-9 _-]+$")) {
932+
throw new InvalidParameterValueException(String.format("Invalid action name: %s. It can contain " +
933+
"only alphabets, numbers, hyphen, underscore and space", name));
934+
}
930935
ExtensionCustomActionVO existingCustomAction = extensionCustomActionDao.findByNameAndExtensionId(extensionId, name);
931936
if (existingCustomAction != null) {
932937
throw new CloudRuntimeException("Action by name already exists");

framework/extensions/src/test/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManagerImplTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,13 @@ public void testAddCustomAction_InvalidResourceType() {
12111211
extensionsManager.addCustomAction(cmd);
12121212
}
12131213

1214+
@Test(expected = InvalidParameterValueException.class)
1215+
public void testAddCustomAction_InvalidName() {
1216+
AddCustomActionCmd cmd = mock(AddCustomActionCmd.class);
1217+
when(cmd.getName()).thenReturn("action;1");
1218+
extensionsManager.addCustomAction(cmd);
1219+
}
1220+
12141221
@Test
12151222
public void deleteCustomAction_RemovesActionAndDetails_ReturnsTrue() {
12161223
long actionId = 10L;

0 commit comments

Comments
 (0)