Skip to content

Commit 15fa2ef

Browse files
DaanHooglandspark404
authored andcommitted
findbugs: check for system template id == -> equals()
1 parent 0d7a965 commit 15fa2ef

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

server/src/com/cloud/template/TemplateManagerImpl.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,12 +1753,7 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
17531753
throw ex;
17541754
}
17551755

1756-
// Don't allow to modify system template
1757-
if (id == Long.valueOf(1)) {
1758-
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
1759-
ex.addProxyObject(String.valueOf(id), "templateId");
1760-
throw ex;
1761-
}
1756+
verifyTemplateId(id);
17621757

17631758
// do a permission check
17641759
_accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
@@ -1835,6 +1830,15 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
18351830
return _tmpltDao.findById(id);
18361831
}
18371832

1833+
void verifyTemplateId(Long id) {
1834+
// Don't allow to modify system template
1835+
if (id.equals(Long.valueOf(1))) {
1836+
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
1837+
ex.addProxyObject(String.valueOf(id), "templateId");
1838+
throw ex;
1839+
}
1840+
}
1841+
18381842
@Override
18391843
public String getConfigComponentName() {
18401844
return TemplateManager.class.getSimpleName();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.cloud.template;
2+
3+
import org.junit.Test;
4+
5+
import com.cloud.exception.InvalidParameterValueException;
6+
7+
public class TemplateManagerImplTest {
8+
9+
TemplateManagerImpl tmgr = new TemplateManagerImpl();
10+
11+
@Test(expected = InvalidParameterValueException.class)
12+
public void testVerifyTemplateIdOfSystemTemplate() {
13+
tmgr.verifyTemplateId(1L);
14+
}
15+
16+
public void testVerifyTemplateIdOfNonSystemTemplate() {
17+
tmgr.verifyTemplateId(1L);
18+
}
19+
}

0 commit comments

Comments
 (0)