Resubmitting KeyProperty code change since tests failed
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / BasicAuthAccountServiceImplTest.java
index 5434749..a905ca8 100644 (file)
@@ -42,6 +42,8 @@ import org.onap.portalapp.portal.domain.EPEndpoint;
 import org.onap.portalapp.portal.domain.EPEndpointAccount;
 import org.onap.portalapp.portal.framework.MockitoTestSuite;
 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.onboarding.util.KeyConstants;
+import org.onap.portalsdk.core.onboarding.util.KeyProperties;
 import org.onap.portalsdk.core.service.DataAccessService;
 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
 import org.onap.portalsdk.core.util.SystemProperties;
@@ -51,7 +53,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
 
 
 @RunWith(PowerMockRunner.class)
-@PrepareForTest({ CipherUtil.class , SystemProperties.class})
+@PrepareForTest({ CipherUtil.class , SystemProperties.class, KeyProperties.class, KeyConstants.class})
 public class BasicAuthAccountServiceImplTest {
        @Mock
        DataAccessService dataAccessService = new DataAccessServiceImpl();
@@ -78,16 +80,26 @@ public class BasicAuthAccountServiceImplTest {
                Mockito.doNothing().when(dataAccessService).saveDomainObject(basicAuthCredentials, null);
                basicAuthAccountServiceImpl.saveBasicAuthAccount(basicAuthCredentials);
                
+       }
+
+               @Test(expected= Exception.class)
+       public void saveBasicAuthAccountValidTest() throws Exception {
+                               BasicAuthCredentials basicAuthCredentials = new BasicAuthCredentials();
+                               basicAuthCredentials.setPassword("<IMG SRC=\"jav\tascript:alert('XSS');\">");
+                               Mockito.doNothing().when(dataAccessService).saveDomainObject(basicAuthCredentials, null);
+                               basicAuthAccountServiceImpl.saveBasicAuthAccount(basicAuthCredentials);
+
        }
        
        @Test
        public void saveBasicAuthAccountTest_password() throws Exception{
                PowerMockito.mockStatic(CipherUtil.class);
-               PowerMockito.mockStatic(SystemProperties.class);
+               PowerMockito.mockStatic(KeyProperties.class);
+               PowerMockito.mockStatic(KeyConstants.class);
                BasicAuthCredentials credentials = new BasicAuthCredentials();
                credentials.setPassword("password");
                String result = null;
-               Mockito.when(CipherUtil.encryptPKC("password", SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn(result);
+               Mockito.when(CipherUtil.encryptPKC("password", KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenReturn(result);
                basicAuthAccountServiceImpl.saveBasicAuthAccount(credentials);
        }
        
@@ -154,7 +166,8 @@ public class BasicAuthAccountServiceImplTest {
        @Test
        public void getAccountDataTest_password() throws Exception {
                PowerMockito.mockStatic(CipherUtil.class);
-               PowerMockito.mockStatic(SystemProperties.class);
+               PowerMockito.mockStatic(KeyProperties.class);
+               PowerMockito.mockStatic(KeyConstants.class);
                List<BasicAuthCredentials> list = new ArrayList<>();
                BasicAuthCredentials basicAuthCredentials = new BasicAuthCredentials();
                basicAuthCredentials.setPassword("password");
@@ -162,7 +175,7 @@ public class BasicAuthAccountServiceImplTest {
                Mockito.when((List<BasicAuthCredentials>) dataAccessService.getList(BasicAuthCredentials.class, null))
                .thenReturn(list);
                String result = null;
-               Mockito.when(CipherUtil.decryptPKC("password", SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn(result);
+               Mockito.when(CipherUtil.decryptPKC("password", KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenReturn(result);
                
        }
 
@@ -175,4 +188,17 @@ public class BasicAuthAccountServiceImplTest {
                basicAuthAccountServiceImpl.deleteEndpointAccout(1l);
                
        }
+       
+       @Test
+       public void getBasicAuthCredentialsById() throws Exception{
+               List<BasicAuthCredentials> list = new ArrayList<>();
+               BasicAuthCredentials basicAuthCredentials = new BasicAuthCredentials();
+               basicAuthCredentials.setPassword("password");
+               basicAuthCredentials.setId(1l);
+               list.add(basicAuthCredentials);
+               Mockito.when((List<BasicAuthCredentials>) dataAccessService.getList(BasicAuthCredentials.class, null))
+               .thenReturn(list);
+               basicAuthAccountServiceImpl.getBasicAuthCredentialsById(1l);
+               
+       }
 }