mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
Clean up X500 names in Corda simulation
Clean up X500 names in Corda simulation, and ensure they're consistent with the standard test names. This includes using the locations present in those test names, which requires updates to the node config test.
This commit is contained in:
parent
780f93e625
commit
e85ed639bb
@ -659,6 +659,7 @@ object X509Utilities {
|
||||
}
|
||||
|
||||
val X500Name.commonName: String get() = getRDNs(BCStyle.CN).first().first.value.toString()
|
||||
val X500Name.location: String get() = getRDNs(BCStyle.L).first().first.value.toString()
|
||||
|
||||
class CertificateStream(val input: InputStream) {
|
||||
private val certificateFactory = CertificateFactory.getInstance("X.509")
|
||||
|
@ -20,11 +20,11 @@ val DUMMY_KEY_2: KeyPair by lazy { generateKeyPair() }
|
||||
|
||||
val DUMMY_NOTARY_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(20)) }
|
||||
/** Dummy notary identity for tests and simulations */
|
||||
val DUMMY_NOTARY: Party get() = Party(X500Name("CN=Notary Service,O=R3,OU=corda,L=London,C=UK"), DUMMY_NOTARY_KEY.public)
|
||||
val DUMMY_NOTARY: Party get() = Party(X500Name("CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH"), DUMMY_NOTARY_KEY.public)
|
||||
|
||||
val DUMMY_MAP_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(30)) }
|
||||
/** Dummy network map service identity for tests and simulations */
|
||||
val DUMMY_MAP: Party get() = Party(X500Name("CN=Network Map Service,O=R3,OU=corda,L=London,C=UK"), DUMMY_MAP_KEY.public)
|
||||
val DUMMY_MAP: Party get() = Party(X500Name("CN=Network Map Service,O=R3,OU=corda,L=Amsterdam,C=NL"), DUMMY_MAP_KEY.public)
|
||||
|
||||
val DUMMY_BANK_A_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(40)) }
|
||||
/** Dummy bank identity for tests and simulations */
|
||||
@ -32,11 +32,11 @@ val DUMMY_BANK_A: Party get() = Party(X500Name("CN=Bank A,O=Bank A,L=London,C=UK
|
||||
|
||||
val DUMMY_BANK_B_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(50)) }
|
||||
/** Dummy bank identity for tests and simulations */
|
||||
val DUMMY_BANK_B: Party get() = Party(X500Name("CN=Bank B,O=Bank B,L=New York,C=USA"), DUMMY_BANK_B_KEY.public)
|
||||
val DUMMY_BANK_B: Party get() = Party(X500Name("CN=Bank B,O=Bank B,L=New York,C=US"), DUMMY_BANK_B_KEY.public)
|
||||
|
||||
val DUMMY_BANK_C_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(60)) }
|
||||
/** Dummy bank identity for tests and simulations */
|
||||
val DUMMY_BANK_C: Party get() = Party(X500Name("CN=Bank C,O=Bank C,L=Tokyo,C=Japan"), DUMMY_BANK_C_KEY.public)
|
||||
val DUMMY_BANK_C: Party get() = Party(X500Name("CN=Bank C,O=Bank C,L=Tokyo,C=JP"), DUMMY_BANK_C_KEY.public)
|
||||
|
||||
val ALICE_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(70)) }
|
||||
/** Dummy individual identity for tests and simulations */
|
||||
@ -49,3 +49,7 @@ val BOB: Party get() = Party(X500Name("CN=Bob Plc,O=Bob Plc,L=London,C=UK"), BOB
|
||||
val CHARLIE_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(90)) }
|
||||
/** Dummy individual identity for tests and simulations */
|
||||
val CHARLIE: Party get() = Party(X500Name("CN=Charlie Ltd,O=Charlie Ltd,L=London,C=UK"), CHARLIE_KEY.public)
|
||||
|
||||
val DUMMY_REGULATOR_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(100)) }
|
||||
/** Dummy regulator for tests and simulations */
|
||||
val DUMMY_REGULATOR: Party get() = Party(X500Name("CN=Regulator A,OU=Corda,O=AMF,L=Paris,C=FR"), DUMMY_REGULATOR_KEY.public)
|
||||
|
@ -216,7 +216,7 @@ is a three node example;
|
||||
cordapps []
|
||||
}
|
||||
node {
|
||||
name "CN=NodeB,O=R3,OU=corda,L=New York,C=USA"
|
||||
name "CN=NodeB,O=R3,OU=corda,L=New York,C=US"
|
||||
nearestCity "New York"
|
||||
advertisedServices = []
|
||||
p2pPort 10008
|
||||
|
@ -65,7 +65,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
rpcUsers = ext.rpcUsers
|
||||
}
|
||||
node {
|
||||
name "CN=Bank B,O=Bank B,L=New York,C=USA"
|
||||
name "CN=Bank B,O=Bank B,L=New York,C=US"
|
||||
nearestCity "New York"
|
||||
advertisedServices = []
|
||||
p2pPort 10008
|
||||
|
@ -52,7 +52,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
cordapps = []
|
||||
}
|
||||
node {
|
||||
name "CN=BankOfCorda,O=R3,OU=corda,L=New York,C=USA"
|
||||
name "CN=BankOfCorda,O=R3,OU=corda,L=New York,C=US"
|
||||
nearestCity "New York"
|
||||
advertisedServices = ["corda.issuer.USD"]
|
||||
p2pPort 10005
|
||||
|
@ -69,7 +69,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
useTestClock true
|
||||
}
|
||||
node {
|
||||
name "CN=Bank B,O=Bank B,L=New York,C=USA"
|
||||
name "CN=Bank B,O=Bank B,L=New York,C=US"
|
||||
nearestCity "New York"
|
||||
advertisedServices = []
|
||||
p2pPort 10008
|
||||
|
@ -2,6 +2,7 @@ package net.corda.simulation
|
||||
|
||||
import com.google.common.util.concurrent.Futures
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import net.corda.core.crypto.location
|
||||
import net.corda.core.flatMap
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.messaging.SingleMessageRecipient
|
||||
@ -12,6 +13,7 @@ import net.corda.core.node.services.containsType
|
||||
import net.corda.core.then
|
||||
import net.corda.core.utilities.DUMMY_MAP
|
||||
import net.corda.core.utilities.DUMMY_NOTARY
|
||||
import net.corda.core.utilities.DUMMY_REGULATOR
|
||||
import net.corda.core.utilities.ProgressTracker
|
||||
import net.corda.irs.api.NodeInterestRates
|
||||
import net.corda.node.services.config.NodeConfiguration
|
||||
@ -24,6 +26,7 @@ import net.corda.testing.node.InMemoryMessagingNetwork
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import net.corda.testing.node.TestClock
|
||||
import net.corda.testing.node.setTo
|
||||
import org.bouncycastle.asn1.x500.X500Name
|
||||
import rx.Observable
|
||||
import rx.subjects.PublishSubject
|
||||
import java.math.BigInteger
|
||||
@ -47,7 +50,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
throw IllegalArgumentException("The latency injector is only useful when using manual pumping.")
|
||||
}
|
||||
|
||||
val bankLocations = listOf("London", "Frankfurt", "Rome")
|
||||
val bankLocations = listOf(Pair("London", "UK"), Pair("Frankfurt", "DE"), Pair("Rome", "IT"))
|
||||
|
||||
// This puts together a mock network of SimulatedNodes.
|
||||
|
||||
@ -65,12 +68,11 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||
val letter = 'A' + counter
|
||||
val city = bankLocations[counter++ % bankLocations.size]
|
||||
val (city, country) = bankLocations[counter++ % bankLocations.size]
|
||||
|
||||
val cfg = TestNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
// TODO: Set this back to "Bank of $city" after video day.
|
||||
myLegalName = "CN=Bank $letter,O=Bank $letter,L=city",
|
||||
myLegalName = "CN=Bank $letter,O=Bank $letter,L=$city,C=$country",
|
||||
nearestCity = city,
|
||||
networkMapService = null)
|
||||
return SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot)
|
||||
@ -94,7 +96,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
val cfg = TestNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
myLegalName = DUMMY_MAP.name,
|
||||
nearestCity = "Amsterdam",
|
||||
nearestCity = X500Name(DUMMY_MAP.name).location,
|
||||
networkMapService = null)
|
||||
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {}
|
||||
}
|
||||
@ -108,22 +110,24 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
val cfg = TestNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
myLegalName = DUMMY_NOTARY.name,
|
||||
nearestCity = "Zurich",
|
||||
nearestCity = X500Name(DUMMY_NOTARY.name).location,
|
||||
networkMapService = null)
|
||||
return SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot)
|
||||
}
|
||||
}
|
||||
|
||||
object RatesOracleFactory : MockNetwork.Factory {
|
||||
// TODO: Make a more realistic legal name
|
||||
val RATES_SERVICE_NAME = "CN=Rates Service Provider,O=R3,OU=corda,L=Madrid,C=ES"
|
||||
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||
require(advertisedServices.containsType(NodeInterestRates.type))
|
||||
val cfg = TestNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
// TODO: Make a more realistic legal name
|
||||
myLegalName = "CN=Rates Service Provider,O=R3,OU=corda,L=Madrid,C=ES",
|
||||
nearestCity = "Madrid",
|
||||
myLegalName = RATES_SERVICE_NAME,
|
||||
nearestCity = X500Name(RATES_SERVICE_NAME).location,
|
||||
networkMapService = null)
|
||||
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
override fun start(): MockNetwork.MockNode {
|
||||
@ -145,9 +149,8 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||
val cfg = TestNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
// TODO: Make a more realistic legal name
|
||||
myLegalName = "CN=Regulator A,O=R3,OU=corda,L=Paris,C=FR",
|
||||
nearestCity = "Paris",
|
||||
myLegalName = DUMMY_REGULATOR.name,
|
||||
nearestCity = X500Name(DUMMY_REGULATOR.name).location,
|
||||
networkMapService = null)
|
||||
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
// TODO: Regulatory nodes don't actually exist properly, this is a last minute demo request.
|
||||
|
@ -22,7 +22,7 @@
|
||||
"interestPeriodAdjustment": "Adjusted"
|
||||
},
|
||||
"floatingLeg": {
|
||||
"floatingRatePayer": "CN=Bank B,O=Bank B,L=New York,C=USA",
|
||||
"floatingRatePayer": "CN=Bank B,O=Bank B,L=New York,C=US",
|
||||
"notional": "€25000000",
|
||||
"paymentFrequency": "Quarterly",
|
||||
"effectiveDate": "2016-03-11",
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
define(['utils/dayCountBasisLookup'], (dayCountBasisLookup) => {
|
||||
return {
|
||||
floatingRatePayer: "CN=Bank B,O=Bank B,L=New York,C=USA",
|
||||
floatingRatePayer: "CN=Bank B,O=Bank B,L=New York,C=US",
|
||||
notional: {
|
||||
quantity: 2500000000
|
||||
},
|
||||
|
@ -75,7 +75,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
cordapps = []
|
||||
}
|
||||
node {
|
||||
name "CN=Bank B,O=Bank B,L=New York,C=USA"
|
||||
name "CN=Bank B,O=Bank B,L=New York,C=US"
|
||||
nearestCity "New York"
|
||||
advertisedServices = []
|
||||
p2pPort 10006
|
||||
|
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
var FloatingLegViewModel = (function () {
|
||||
function FloatingLegViewModel() {
|
||||
this.floatingRatePayer = "CN=Bank B,O=Bank B,L=New York,C=USA";
|
||||
this.floatingRatePayer = "CN=Bank B,O=Bank B,L=New York,C=US";
|
||||
this.notional = {
|
||||
quantity: 2500000000
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
export class FloatingLegViewModel {
|
||||
constructor() { }
|
||||
|
||||
floatingRatePayer = "CN=Bank B,O=Bank B,L=New York,C=USA";
|
||||
floatingRatePayer = "CN=Bank B,O=Bank B,L=New York,C=US";
|
||||
notional: Object = {
|
||||
quantity: 2500000000
|
||||
};
|
||||
|
@ -76,7 +76,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
rpcUsers = ext.rpcUsers
|
||||
}
|
||||
node {
|
||||
name "CN=Bank B,O=Bank B,L=New York,C=USA"
|
||||
name "CN=Bank B,O=Bank B,L=New York,C=US"
|
||||
nearestCity "New York"
|
||||
advertisedServices = []
|
||||
p2pPort 10008
|
||||
@ -85,7 +85,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
rpcUsers = ext.rpcUsers
|
||||
}
|
||||
node {
|
||||
name "CN=BankOfCorda,O=R3,OU=corda,L=New York,C=USA"
|
||||
name "CN=BankOfCorda,O=R3,OU=corda,L=New York,C=US"
|
||||
nearestCity "London"
|
||||
advertisedServices = []
|
||||
p2pPort 10011
|
||||
|
@ -74,7 +74,7 @@ val MINI_CORP: Party get() = Party(X509Utilities.getDevX509Name("MiniCorp"), MIN
|
||||
|
||||
val BOC_KEY: KeyPair by lazy { generateKeyPair() }
|
||||
val BOC_PUBKEY: PublicKey get() = BOC_KEY.public
|
||||
val BOC: Party get() = Party(X500Name("CN=BankOfCorda,O=R3,OU=corda,L=New York,C=USA"), BOC_PUBKEY)
|
||||
val BOC: Party get() = Party(X500Name("CN=BankOfCorda,O=R3,OU=corda,L=New York,C=US"), BOC_PUBKEY)
|
||||
val BOC_PARTY_REF = BOC.ref(OpaqueBytes.of(1)).reference
|
||||
|
||||
val BIG_CORP_KEY: KeyPair by lazy { generateKeyPair() }
|
||||
|
@ -1,5 +1,8 @@
|
||||
package net.corda.demobench.model
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.databind.SerializationFeature
|
||||
import com.google.common.net.HostAndPort
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import com.typesafe.config.ConfigValueFactory
|
||||
@ -11,6 +14,7 @@ import net.corda.nodeapi.User
|
||||
import net.corda.nodeapi.config.parseAs
|
||||
import net.corda.webserver.WebServerConfig
|
||||
import org.junit.Test
|
||||
import java.io.StringWriter
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import kotlin.test.assertEquals
|
||||
@ -114,6 +118,19 @@ class NodeConfigTest {
|
||||
assertFalse(config.isCashIssuer)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reformat JSON via Jackson to ensure a consistent format for comparison purposes.
|
||||
*/
|
||||
private fun prettyPrint(content: String): String {
|
||||
val mapper = ObjectMapper()
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
mapper.enable(SerializationFeature.INDENT_OUTPUT)
|
||||
val sw = StringWriter()
|
||||
val parsed = mapper.readTree(content)
|
||||
mapper.writeValue(sw, parsed)
|
||||
return sw.toString()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test config text`() {
|
||||
val config = createConfig(
|
||||
@ -126,10 +143,10 @@ class NodeConfigTest {
|
||||
services = listOf("my.service"),
|
||||
users = listOf(user("jenny"))
|
||||
)
|
||||
assertEquals("{"
|
||||
assertEquals(prettyPrint("{"
|
||||
+ "\"extraAdvertisedServiceIds\":[\"my.service\"],"
|
||||
+ "\"h2port\":30001,"
|
||||
+ "\"myLegalName\":\"MyName\","
|
||||
+ "\"myLegalName\":\"My Name\","
|
||||
+ "\"nearestCity\":\"Stockholm\","
|
||||
+ "\"p2pAddress\":\"localhost:10001\","
|
||||
+ "\"rpcAddress\":\"localhost:40002\","
|
||||
@ -138,7 +155,7 @@ class NodeConfigTest {
|
||||
+ "],"
|
||||
+ "\"useTestClock\":true,"
|
||||
+ "\"webAddress\":\"localhost:20001\""
|
||||
+ "}", config.toText().stripWhitespace())
|
||||
+ "}"), prettyPrint(config.toText()))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -155,12 +172,12 @@ class NodeConfigTest {
|
||||
)
|
||||
config.networkMap = NetworkMapConfig(DUMMY_NOTARY.name, 12345)
|
||||
|
||||
assertEquals("{"
|
||||
assertEquals(prettyPrint("{"
|
||||
+ "\"extraAdvertisedServiceIds\":[\"my.service\"],"
|
||||
+ "\"h2port\":30001,"
|
||||
+ "\"myLegalName\":\"MyName\","
|
||||
+ "\"myLegalName\":\"My Name\","
|
||||
+ "\"nearestCity\":\"Stockholm\","
|
||||
+ "\"networkMapService\":{\"address\":\"localhost:12345\",\"legalName\":\"CN=NotaryService,O=R3,OU=corda,L=London,C=UK\"},"
|
||||
+ "\"networkMapService\":{\"address\":\"localhost:12345\",\"legalName\":\"CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH\"},"
|
||||
+ "\"p2pAddress\":\"localhost:10001\","
|
||||
+ "\"rpcAddress\":\"localhost:40002\","
|
||||
+ "\"rpcUsers\":["
|
||||
@ -168,7 +185,7 @@ class NodeConfigTest {
|
||||
+ "],"
|
||||
+ "\"useTestClock\":true,"
|
||||
+ "\"webAddress\":\"localhost:20001\""
|
||||
+ "}", config.toText().stripWhitespace())
|
||||
+ "}"), prettyPrint(config.toText()))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -177,7 +177,7 @@ fun main(args: Array<String>) {
|
||||
val issuerGBP = startNode(X500Name("CN=UK Bank Plc,O=UK Bank Plc,L=London,C=UK"), rpcUsers = arrayListOf(manager),
|
||||
advertisedServices = setOf(ServiceInfo(ServiceType.corda.getSubType("issuer.GBP"))),
|
||||
customOverrides = mapOf("nearestCity" to "London"))
|
||||
val issuerUSD = startNode(X500Name("CN=USA Bank Corp,O=USA Bank Corp,L=New York,C=USA"), rpcUsers = arrayListOf(manager),
|
||||
val issuerUSD = startNode(X500Name("CN=USA Bank Corp,O=USA Bank Corp,L=New York,C=US"), rpcUsers = arrayListOf(manager),
|
||||
advertisedServices = setOf(ServiceInfo(ServiceType.corda.getSubType("issuer.USD"))),
|
||||
customOverrides = mapOf("nearestCity" to "New York"))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user