diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/PersistentCertificateRequestStorage.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/PersistentCertificateRequestStorage.kt index 566729a239..339fcb7978 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/PersistentCertificateRequestStorage.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/PersistentCertificateRequestStorage.kt @@ -141,9 +141,11 @@ class PersistentCertificateRequestStorage(private val database: CordaPersistence } } + // TODO consider scenario: There is a CSR that is signed but the certificate itself has expired or was revoked + // Also, at the moment we assume that once the CSR is approved it cannot be rejected. + // What if we approved something by mistake. val duplicates = session.createQuery(query).resultList.filter { - it.status in setOf(RequestStatus.NEW, RequestStatus.TICKET_CREATED, RequestStatus.APPROVED) || - it.certificateData?.certificateStatus == CertificateStatus.VALID + it.status != RequestStatus.REJECTED } return Pair(legalName, if (duplicates.isEmpty()) null else "Duplicate legal name") diff --git a/network-management/src/test/kotlin/com/r3/corda/networkmanage/common/persistence/PersistentCertificateRequestStorageTest.kt b/network-management/src/test/kotlin/com/r3/corda/networkmanage/common/persistence/PersistentCertificateRequestStorageTest.kt index df80ebdd6e..7825622855 100644 --- a/network-management/src/test/kotlin/com/r3/corda/networkmanage/common/persistence/PersistentCertificateRequestStorageTest.kt +++ b/network-management/src/test/kotlin/com/r3/corda/networkmanage/common/persistence/PersistentCertificateRequestStorageTest.kt @@ -156,6 +156,26 @@ class PersistentCertificateRequestStorageTest : TestBase() { assertThat(storage.getRequest(requestId2)!!.remark).containsIgnoringCase("duplicate") } + @Test + fun `request with the same legal name as a previously signed request`() { + val csr = createRequest("BankA").first + val requestId = storage.saveRequest(csr) + storage.markRequestTicketCreated(requestId) + storage.approveRequest(requestId, DOORMAN_SIGNATURE) + // Sign certificate + storage.putCertificatePath( + requestId, + JcaPKCS10CertificationRequest(csr).run { + // TODO We need a utility in InternalUtils for converting X500Name -> CordaX500Name + val (rootCa, intermediateCa, nodeCa) = createDevNodeCaCertPath(CordaX500Name.build(X500Principal(subject.encoded))) + buildCertPath(nodeCa.certificate, intermediateCa.certificate, rootCa.certificate) + }, + listOf(DOORMAN_SIGNATURE) + ) + val rejectedRequestId = storage.saveRequest(createRequest("BankA").first) + assertThat(storage.getRequest(rejectedRequestId)!!.remark).containsIgnoringCase("duplicate") + } + @Test fun `request with the same legal name as a previously rejected request`() { val requestId1 = storage.saveRequest(createRequest("BankA").first)