Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1511#discussion_r78647094
  
    --- Diff: server/test/org/apache/cloudstack/network/lb/CertServiceTest.java 
---
    @@ -440,129 +441,130 @@ public void runUploadSslCertBadkeyPair() throws 
IOException, IllegalAccessExcept
         public void runUploadSslCertBadkeyAlgo() throws IOException, 
IllegalAccessException, NoSuchFieldException {
     
             // Reading appropritate files
    -        String certFile = 
URLDecoder.decode(getClass().getResource("/certs/rsa_self_signed.crt").getFile(),Charset.defaultCharset().name());
    -        String keyFile = 
URLDecoder.decode(getClass().getResource("/certs/dsa_self_signed.key").getFile(),Charset.defaultCharset().name());
    +        final String certFile = 
URLDecoder.decode(getClass().getResource("/certs/rsa_self_signed.crt").getFile(),Charset.defaultCharset().name());
    +        final String keyFile = 
URLDecoder.decode(getClass().getResource("/certs/dsa_self_signed.key").getFile(),Charset.defaultCharset().name());
     
    -        String cert = readFileToString(new File(certFile));
    -        String key = readFileToString(new File(keyFile));
    +        final String cert = readFileToString(new File(certFile));
    +        final String key = readFileToString(new File(keyFile));
     
    -        CertServiceImpl certService = new CertServiceImpl();
    +        final CertServiceImpl certService = new CertServiceImpl();
     
             //setting mock objects
             certService._accountMgr = Mockito.mock(AccountManager.class);
    -        Account account = new AccountVO("testaccount", 1, "networkdomain", 
(short)0, UUID.randomUUID().toString());
    +        final Account account = new AccountVO("testaccount", 1, 
"networkdomain", (short)0, UUID.randomUUID().toString());
             
when(certService._accountMgr.getAccount(anyLong())).thenReturn(account);
     
             certService._domainDao = Mockito.mock(DomainDao.class);
    -        DomainVO domain = new DomainVO("networkdomain", 1L, 1L, 
"networkdomain");
    +        final DomainVO domain = new DomainVO("networkdomain", 1L, 1L, 
"networkdomain");
             
when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain);
     
             certService._sslCertDao = Mockito.mock(SslCertDao.class);
             
when(certService._sslCertDao.persist(any(SslCertVO.class))).thenReturn(new 
SslCertVO());
     
             //creating the command
    -        UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn();
    -        Class<?> _class = uploadCmd.getClass().getSuperclass();
    +        final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn();
    +        final Class<?> klazz = uploadCmd.getClass().getSuperclass();
     
    -        Field certField = _class.getDeclaredField("cert");
    +        final Field certField = klazz.getDeclaredField("cert");
             certField.setAccessible(true);
             certField.set(uploadCmd, cert);
     
    -        Field keyField = _class.getDeclaredField("key");
    +        final Field keyField = klazz.getDeclaredField("key");
             keyField.setAccessible(true);
             keyField.set(uploadCmd, key);
     
             try {
                 certService.uploadSslCert(uploadCmd);
                 fail("Given a private key which has a different algorithm than 
the certificate, upload should fail");
    -        } catch (Exception e) {
    -            assertTrue(e.getMessage().contains("Public and private key 
have different algorithms"));
    +        } catch (final Exception e) {
    +            assertTrue("Did not expect message: " + e.getMessage(),
    +                    e.getMessage().contains("Error parsing certificate 
data Parsing certificate/key failed: Invalid Key format."));
             }
         }
     
         @Test
         public void runUploadSslCertExpiredCert() throws IOException, 
IllegalAccessException, NoSuchFieldException {
     
             // Reading appropritate files
    -        String certFile = 
URLDecoder.decode(getClass().getResource("/certs/expired_cert.crt").getFile(),Charset.defaultCharset().name());
    -        String keyFile = 
URLDecoder.decode(getClass().getResource("/certs/rsa_self_signed.key").getFile(),Charset.defaultCharset().name());
    +        final String certFile = 
URLDecoder.decode(getClass().getResource("/certs/expired_cert.crt").getFile(),Charset.defaultCharset().name());
    +        final String keyFile = 
URLDecoder.decode(getClass().getResource("/certs/rsa_self_signed.key").getFile(),Charset.defaultCharset().name());
     
    -        String cert = readFileToString(new File(certFile));
    -        String key = readFileToString(new File(keyFile));
    +        final String cert = readFileToString(new File(certFile));
    +        final String key = readFileToString(new File(keyFile));
     
    -        CertServiceImpl certService = new CertServiceImpl();
    +        final CertServiceImpl certService = new CertServiceImpl();
     
             //setting mock objects
             certService._accountMgr = Mockito.mock(AccountManager.class);
    -        Account account = new AccountVO("testaccount", 1, "networkdomain", 
(short)0, UUID.randomUUID().toString());
    +        final Account account = new AccountVO("testaccount", 1, 
"networkdomain", (short)0, UUID.randomUUID().toString());
             
when(certService._accountMgr.getAccount(anyLong())).thenReturn(account);
     
             certService._domainDao = Mockito.mock(DomainDao.class);
    -        DomainVO domain = new DomainVO("networkdomain", 1L, 1L, 
"networkdomain");
    +        final DomainVO domain = new DomainVO("networkdomain", 1L, 1L, 
"networkdomain");
             
when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain);
     
             certService._sslCertDao = Mockito.mock(SslCertDao.class);
             
when(certService._sslCertDao.persist(any(SslCertVO.class))).thenReturn(new 
SslCertVO());
     
             //creating the command
    -        UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn();
    -        Class<?> _class = uploadCmd.getClass().getSuperclass();
    +        final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn();
    +        final Class<?> klazz = uploadCmd.getClass().getSuperclass();
     
    -        Field certField = _class.getDeclaredField("cert");
    +        final Field certField = klazz.getDeclaredField("cert");
             certField.setAccessible(true);
             certField.set(uploadCmd, cert);
     
    -        Field keyField = _class.getDeclaredField("key");
    +        final Field keyField = klazz.getDeclaredField("key");
             keyField.setAccessible(true);
             keyField.set(uploadCmd, key);
     
             try {
                 certService.uploadSslCert(uploadCmd);
                 fail("Given an expired certificate, upload should fail");
    -        } catch (Exception e) {
    +        } catch (final Exception e) {
                 assertTrue(e.getMessage().contains("Certificate expired"));
             }
         }
     
         @Test
         public void runUploadSslCertNotX509() throws IOException, 
IllegalAccessException, NoSuchFieldException {
             // Reading appropritate files
    -        String certFile = 
URLDecoder.decode(getClass().getResource("/certs/non_x509_pem.crt").getFile(),Charset.defaultCharset().name());
    -        String keyFile = 
URLDecoder.decode(getClass().getResource("/certs/rsa_self_signed.key").getFile(),Charset.defaultCharset().name());
    +        final String certFile = 
URLDecoder.decode(getClass().getResource("/certs/non_x509_pem.crt").getFile(),Charset.defaultCharset().name());
    +        final String keyFile = 
URLDecoder.decode(getClass().getResource("/certs/rsa_self_signed.key").getFile(),Charset.defaultCharset().name());
     
    -        String cert = readFileToString(new File(certFile));
    -        String key = readFileToString(new File(keyFile));
    +        final String cert = readFileToString(new File(certFile));
    +        final String key = readFileToString(new File(keyFile));
    --- End diff --
    
    Please see line comments 158-159 as they apply to lines 535-536 as well.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to