findbugs: check for system template id == -> equals()

This commit is contained in:
Daan Hoogland 2014-02-11 12:22:53 +01:00 committed by Hugo Trippaers
parent 0d7a96526c
commit 15fa2ef8df
2 changed files with 29 additions and 6 deletions

View File

@ -1753,12 +1753,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
throw ex;
}
// Don't allow to modify system template
if (id == Long.valueOf(1)) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
ex.addProxyObject(String.valueOf(id), "templateId");
throw ex;
}
verifyTemplateId(id);
// do a permission check
_accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
@ -1835,6 +1830,15 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
return _tmpltDao.findById(id);
}
void verifyTemplateId(Long id) {
// Don't allow to modify system template
if (id.equals(Long.valueOf(1))) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
ex.addProxyObject(String.valueOf(id), "templateId");
throw ex;
}
}
@Override
public String getConfigComponentName() {
return TemplateManager.class.getSimpleName();

View File

@ -0,0 +1,19 @@
package com.cloud.template;
import org.junit.Test;
import com.cloud.exception.InvalidParameterValueException;
public class TemplateManagerImplTest {
TemplateManagerImpl tmgr = new TemplateManagerImpl();
@Test(expected = InvalidParameterValueException.class)
public void testVerifyTemplateIdOfSystemTemplate() {
tmgr.verifyTemplateId(1L);
}
public void testVerifyTemplateIdOfNonSystemTemplate() {
tmgr.verifyTemplateId(1L);
}
}