### Question:
X509CommonNameUserMapper extends X509AbstractMapper { public String mapCertificateToMainframeUserId(X509Certificate certificate) { if (isClientAuthCertificate(certificate)) { String dn = certificate.getSubjectX500Principal().getName(); LdapName ldapDN = getLdapName(dn); for (Rdn rdn : ldapDN.getRdns()) { if ("cn".equalsIgnoreCase(rdn.getType())) { return String.valueOf(rdn.getValue()); } } } return null; }  String mapCertificateToMainframeUserId(X509Certificate certificate); LdapName getLdapName(String dn);  }### Answer:
@Test void providedValidCertificate_returnUserId() { X509Certificate x509Certificate = X509Utils.getCertificate(X509Utils.correctBase64("zowe"), "CN=user,OU=CA CZ,O=Broadcom,L=Prague,ST=Czechia,C=CZ"); assertEquals("user", x509CommonNameUserMapper.mapCertificateToMainframeUserId(x509Certificate)); }
@Test void providedInvalidCertificate_returnNull() { X509Certificate x509Certificate = X509Utils.getCertificate(X509Utils.correctBase64("zowe"), "OU=CA CZ,O=Broadcom,L=Prague,ST=Czechia,C=CZ"); assertNull(x509CommonNameUserMapper.mapCertificateToMainframeUserId(x509Certificate)); }