mirror of
https://github.com/corda/corda.git
synced 2024-12-22 06:17:55 +00:00
Fix to test in InMemoryIdentityServiceTests
This commit is contained in:
parent
a6bf8e35dd
commit
3407cd4580
@ -115,12 +115,12 @@ class InMemoryIdentityServiceTests {
|
|||||||
service.verifyAndRegisterAnonymousIdentity(aliceTxIdentity, alice.party)
|
service.verifyAndRegisterAnonymousIdentity(aliceTxIdentity, alice.party)
|
||||||
|
|
||||||
var actual = service.anonymousFromKey(aliceTxIdentity.party.owningKey)
|
var actual = service.anonymousFromKey(aliceTxIdentity.party.owningKey)
|
||||||
assertEquals<AnonymousPartyAndPath>(aliceTxIdentity, actual!!)
|
assertEquals(aliceTxIdentity, actual!!)
|
||||||
|
|
||||||
assertNull(service.anonymousFromKey(bobTxIdentity.party.owningKey))
|
assertNull(service.anonymousFromKey(bobTxIdentity.party.owningKey))
|
||||||
service.verifyAndRegisterAnonymousIdentity(bobTxIdentity, bob.party)
|
service.verifyAndRegisterAnonymousIdentity(bobTxIdentity, bob.party)
|
||||||
actual = service.anonymousFromKey(bobTxIdentity.party.owningKey)
|
actual = service.anonymousFromKey(bobTxIdentity.party.owningKey)
|
||||||
assertEquals<AnonymousPartyAndPath>(bobTxIdentity, actual!!)
|
assertEquals(bobTxIdentity, actual!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,37 +131,28 @@ class InMemoryIdentityServiceTests {
|
|||||||
fun `assert ownership`() {
|
fun `assert ownership`() {
|
||||||
withTestSerialization {
|
withTestSerialization {
|
||||||
val trustRoot = DUMMY_CA
|
val trustRoot = DUMMY_CA
|
||||||
val (alice, aliceTxIdentity) = createParty(ALICE.name, trustRoot)
|
val (alice, anonymousAlice) = createParty(ALICE.name, trustRoot)
|
||||||
|
val (bob, anonymousBob) = createParty(BOB.name, trustRoot)
|
||||||
val certFactory = CertificateFactory.getInstance("X509")
|
|
||||||
val bobRootKey = Crypto.generateKeyPair()
|
|
||||||
val bobRoot = getTestPartyAndCertificate(BOB.name, bobRootKey.public)
|
|
||||||
val bobRootCert = bobRoot.certificate
|
|
||||||
val bobTxKey = Crypto.generateKeyPair()
|
|
||||||
val bobTxCert = X509Utilities.createCertificate(CertificateType.IDENTITY, bobRootCert, bobRootKey, BOB.name, bobTxKey.public)
|
|
||||||
val bobCertPath = certFactory.generateCertPath(listOf(bobTxCert.cert, bobRootCert.cert))
|
|
||||||
val bob = PartyAndCertificate(BOB.name, bobRootKey.public, bobRootCert, bobCertPath)
|
|
||||||
|
|
||||||
// Now we have identities, construct the service and let it know about both
|
// Now we have identities, construct the service and let it know about both
|
||||||
val service = InMemoryIdentityService(setOf(alice, bob), emptyMap(), trustRoot.certificate.cert)
|
val service = InMemoryIdentityService(setOf(alice, bob), emptyMap(), trustRoot.certificate.cert)
|
||||||
service.verifyAndRegisterAnonymousIdentity(aliceTxIdentity, alice.party)
|
|
||||||
|
|
||||||
val anonymousBob = AnonymousPartyAndPath(AnonymousParty(bobTxKey.public),bobCertPath)
|
service.verifyAndRegisterAnonymousIdentity(anonymousAlice, alice.party)
|
||||||
service.verifyAndRegisterAnonymousIdentity(anonymousBob, bob.party)
|
service.verifyAndRegisterAnonymousIdentity(anonymousBob, bob.party)
|
||||||
|
|
||||||
// Verify that paths are verified
|
// Verify that paths are verified
|
||||||
service.assertOwnership(alice.party, aliceTxIdentity.party)
|
service.assertOwnership(alice.party, anonymousAlice.party)
|
||||||
service.assertOwnership(bob.party, anonymousBob.party)
|
service.assertOwnership(bob.party, anonymousBob.party)
|
||||||
assertFailsWith<IllegalArgumentException> {
|
assertFailsWith<IllegalArgumentException> {
|
||||||
service.assertOwnership(alice.party, anonymousBob.party)
|
service.assertOwnership(alice.party, anonymousBob.party)
|
||||||
}
|
}
|
||||||
assertFailsWith<IllegalArgumentException> {
|
assertFailsWith<IllegalArgumentException> {
|
||||||
service.assertOwnership(bob.party, aliceTxIdentity.party)
|
service.assertOwnership(bob.party, anonymousAlice.party)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertFailsWith<IllegalArgumentException> {
|
assertFailsWith<IllegalArgumentException> {
|
||||||
val owningKey = Crypto.decodePublicKey(trustRoot.certificate.subjectPublicKeyInfo.encoded)
|
val owningKey = Crypto.decodePublicKey(trustRoot.certificate.subjectPublicKeyInfo.encoded)
|
||||||
service.assertOwnership(Party(trustRoot.certificate.subject, owningKey), aliceTxIdentity.party)
|
service.assertOwnership(Party(trustRoot.certificate.subject, owningKey), anonymousAlice.party)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import net.corda.core.utilities.ByteSequence
|
|||||||
import net.corda.node.serialization.KryoServerSerializationScheme
|
import net.corda.node.serialization.KryoServerSerializationScheme
|
||||||
import net.corda.nodeapi.internal.serialization.*
|
import net.corda.nodeapi.internal.serialization.*
|
||||||
|
|
||||||
fun <T> withTestSerialization(block: () -> T): T {
|
inline fun <T> withTestSerialization(block: () -> T): T {
|
||||||
initialiseTestSerialization()
|
initialiseTestSerialization()
|
||||||
try {
|
try {
|
||||||
return block()
|
return block()
|
||||||
|
Loading…
Reference in New Issue
Block a user