bug 11179: template url and format are not validated

added check to verify url ends with extension same as the template format specified
This commit is contained in:
Murali Reddy 2011-08-30 16:15:58 +05:30
parent c90397bd0e
commit f0fa75f793
1 changed files with 8 additions and 0 deletions

View File

@ -100,6 +100,14 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
throw new InvalidParameterValueException("Please specify a valid "+ cmd.getFormat().toLowerCase());
}
if ((cmd.getFormat().equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith("vhd.gz") ))
|| (cmd.getFormat().equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url.toLowerCase().endsWith("qcow2.gz") ))
|| (cmd.getFormat().equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase().endsWith("ova.gz")))
|| (cmd.getFormat().equalsIgnoreCase("img") && !url.toLowerCase().endsWith("img"))
|| (cmd.getFormat().equalsIgnoreCase("raw") && !url.toLowerCase().endsWith("raw")) ) {
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is a invalid for the format " + cmd.getFormat().toLowerCase());
}
profile.setUrl(validateUrl(url));
return profile;
}