@Test
public void testUpdateSSHHostPrincipalsNullValues() {

    InstanceCertManager instance = new InstanceCertManager(null, null, null, true);
    SshHostCsr csr = new SshHostCsr();
    csr.setPrincipals(new String[0]);
    csr.setPrincipals(new String[0]);
    SSHCertRecord record = new SSHCertRecord();
    instance.updateSSHHostPrincipals(csr, record);
    assertEquals(record.getPrincipals(), "127.0.0.1");
    String[] principals = new String[3];
    principals[0] = "principal1";
    principals[1] = "principal2";
    principals[2] = "principal4";
    csr.setPrincipals(principals);
    csr.setXPrincipals(null);
    record = new SSHCertRecord();
    instance.updateSSHHostPrincipals(csr, record);
    Set<String> result = new HashSet<>(Arrays.asList(record.getPrincipals().split(",")));
    assertEquals(result.size(), 3);
    assertTrue(result.contains("principal1"));
    assertTrue(result.contains("principal2"));
    assertTrue(result.contains("principal4"));
    // now let's try with principals set to null
    csr.setPrincipals(null);
    csr.setXPrincipals(principals);
    record = new SSHCertRecord();
    instance.updateSSHHostPrincipals(csr, record);
    result = new HashSet<>(Arrays.asList(record.getPrincipals().split(",")));
    assertEquals(result.size(), 3);
    assertTrue(result.contains("principal1"));
    assertTrue(result.contains("principal2"));
    assertTrue(result.contains("principal4"));
}