    @Test
    public void testGetCNsMocked() {

        X500Principal normal = new X500Principal("CN=abc,OU=ou,O=o,C=canada,EMAILADDRESS=bob@bob.com");
        X500Principal bad1 = new X500Principal("CN=\"abc,CN=foo.com,\",OU=ou,O=o,C=canada,EMAILADDRESS=bob@bob.com");
        X500Principal bad2 = new X500Principal("ou=\",CN=evil.ca,\",  CN=good.net");

        when(x509.getSubjectX500Principal()).thenReturn(normal);
        String[] cns = Certificates.getCNs(x509);
        Assert.assertEquals(1, cns.length);
        Assert.assertEquals("abc", cns[0]);

        when(x509.getSubjectX500Principal()).thenReturn(bad2);
        cns = Certificates.getCNs(x509);
        Assert.assertEquals(1, cns.length);
        Assert.assertEquals("good.net", cns[0]);

        when(x509.getSubjectX500Principal()).thenReturn(bad1);
        cns = Certificates.getCNs(x509);
        Assert.assertEquals(1, cns.length);
        Assert.assertEquals("abc,CN=foo.com,", cns[0]);
    }