Martin Betak has uploaded a new change for review. Change subject: backend: Validate cdrom images for .iso suffix ......................................................................
backend: Validate cdrom images for .iso suffix Check for the filename ".iso" suffix of isoPath in UpdateVm and ChangeDisk commands. Change-Id: I7d4e6e6464e5f23483748dcd03607612b1fc56f4 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1013737 Signed-off-by: Martin Betak <mbe...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeDiskCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java M backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ValidationUtilsTest.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 6 files changed, 30 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/03/30903/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeDiskCommand.java index 076c1fb..20ea766 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeDiskCommand.java @@ -7,6 +7,7 @@ import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.action.ChangeDiskCommandParameters; import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.utils.ValidationUtils; import org.ovirt.engine.core.common.vdscommands.ChangeDiskVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; @@ -59,6 +60,11 @@ addCanDoActionMessage(VdcBllMessages.VM_CANNOT_WITHOUT_ACTIVE_STORAGE_DOMAIN_ISO); setSucceeded(false); retValue = false; + } else if (StringUtils.isNotEmpty(cdImagePath) && !cdImagePath.endsWith(ValidationUtils.ISO_SUFFIX)) { + addCanDoActionMessage(VdcBllMessages.VAR__ACTION__CHANGE_CD); + addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_INVALID_CDROM_DISK_FORMAT); + setSucceeded(false); + retValue = false; } return retValue; } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java index 8f5d44c..f4e4356 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java @@ -155,6 +155,7 @@ @CopyOnNewVersion @EditableField + @Pattern(regexp = ValidationUtils.ISO_SUFFIX_PATTERN, message = "ACTION_TYPE_FAILED_INVALID_CDROM_DISK_FORMAT") @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE) private String isoPath; diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java index 31d4a22..0157906 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java @@ -146,6 +146,7 @@ ACTION_TYPE_FAILED_VM_DURING_EXPORT(ErrorType.CONFLICT), ACTION_TYPE_FAILED_VM_IMAGE_IS_ILLEGAL(ErrorType.CONFLICT), ACTION_TYPE_FAILED_VM_HAS_NO_DISKS(ErrorType.CONFLICT), + ACTION_TYPE_FAILED_INVALID_CDROM_DISK_FORMAT(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_VM_SNAPSHOT_DOES_NOT_EXIST(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_VM_SNAPSHOT_TYPE_NOT_ALLOWED(ErrorType.CONFLICT), diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java index 30ef466..bd006b4 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java @@ -25,6 +25,9 @@ public static final String IP_PATTERN = "^\\b((25[0-5]|2[0-4]\\d|[01]\\d\\d|\\d?\\d)\\.){3}(25[0-5]|2[0-4]\\d|[01]\\d\\d|\\d?\\d)\\b$|^$"; + public static final String ISO_SUFFIX = ".iso"; + public static final String ISO_SUFFIX_PATTERN = "^$|^.+\\.iso$"; + /** the mask will be replaced with zero-padded number in the generated names of the VMs in the pool, * see NameForVmInPoolGeneratorTest PoolNameValidationTest for valid and invalid expressions of this pattern */ public static final String POOL_NAME_PATTERN = "^[\\p{L}0-9._-]+[" + VmPool.MASK_CHARACTER + "]*[\\p{L}0-9._-]*$|^[\\p{L}0-9._-]*[" + VmPool.MASK_CHARACTER + "]*[\\p{L}0-9._-]+$"; diff --git a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ValidationUtilsTest.java b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ValidationUtilsTest.java index 3e1f19f..331f7fd 100644 --- a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ValidationUtilsTest.java +++ b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ValidationUtilsTest.java @@ -64,4 +64,22 @@ assertFalse(ValidationUtils.validUri("://asdasd:12")); assertFalse(ValidationUtils.validUri("asd asd")); } + + @Test + public void testValidIsoPath() { + assertPatternMatches("Valid isoPath: ", ValidationUtils.ISO_SUFFIX_PATTERN, "", "foo.iso", "RHEVM-123456-tools.iso"); + assertPatternDoesNotMatch("Invalid isoPath: ", ValidationUtils.ISO_SUFFIX_PATTERN, "x", "sysprep.vfd", "disk.ISO"); + } + + private void assertPatternMatches(String message, String pattern, String... validStrings) { + for (String s : validStrings) { + assertTrue(message + s, Pattern.matches(pattern, s)); + } + } + + private void assertPatternDoesNotMatch(String message, String pattern, String... invalidStrings) { + for (String s : invalidStrings) { + assertTrue(message + s, !Pattern.matches(pattern, s)); + } + } } diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index 3fd7f88..64524bb 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -164,6 +164,7 @@ ACTION_TYPE_FAILED_VM_DURING_EXPORT=Cannot ${action} ${type}: VM is being exported now. Please try again in a few minutes. ACTION_TYPE_FAILED_VM_IMAGE_IS_ILLEGAL=Cannot ${action} ${type}. VM's Image might be corrupted. ACTION_TYPE_FAILED_VM_HAS_NO_DISKS=Cannot ${action} ${type}. VM has no disks. +ACTION_TYPE_FAILED_INVALID_CDROM_DISK_FORMAT=Cannot ${action} ${type}. Invalid CD image format. ACTION_TYPE_FAILED_IMAGE_REPOSITORY_NOT_FOUND=Cannot ${action} ${type}: Storage Domain cannot be accessed.\n\ -Please check that at least one Host is operational and Data Center state is up. ACTION_TYPE_FAILED_VM_IS_RUNNING=Cannot ${action} ${type}. VM is running. -- To view, visit http://gerrit.ovirt.org/30903 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7d4e6e6464e5f23483748dcd03607612b1fc56f4 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Martin Betak <mbe...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches