@@ -7,30 +7,39 @@ import better.files.File
77import com .daml .nonempty .NonEmpty
88import com .digitalasset .canton .crypto .Fingerprint
99import com .digitalasset .canton .integration .CommunityIntegrationTest
10- import com .digitalasset .canton .integration .plugins .UseH2
1110import com .digitalasset .canton .integration .tests .examples .ExampleIntegrationTest .examplesPath
1211import com .digitalasset .canton .integration .tests .examples .OpenSslOfflineRootKeyDemoExampleIntegrationTest .demoFolder
1312import com .digitalasset .canton .topology .admin .grpc .TopologyStoreId .Authorized
1413import com .digitalasset .canton .topology .transaction .{DelegationRestriction , TopologyMapping }
14+ import org .scalatest .BeforeAndAfterEach
1515import org .scalatestplus .scalacheck .ScalaCheckPropertyChecks
1616
1717object OpenSslOfflineRootKeyDemoExampleIntegrationTest {
1818 lazy val demoFolder : File = examplesPath / " 10-offline-root-namespace-init"
1919}
2020
21- sealed abstract class OpenSslOfflineRootKeyDemoExampleIntegrationTest
21+ class OpenSslOfflineRootKeyDemoExampleIntegrationTest
2222 extends ExampleIntegrationTest (
2323 demoFolder / " manual-init-example.conf"
2424 )
2525 with CommunityIntegrationTest
26- with ScalaCheckPropertyChecks {
26+ with ScalaCheckPropertyChecks
27+ with BeforeAndAfterEach {
2728
2829 override def afterAll (): Unit = {
2930 super .afterAll()
3031 // Delete the temp files created by the test
3132 (demoFolder / " tmp" ).delete(swallowIOExceptions = true )
3233 }
3334
35+ override def afterEach (): Unit =
36+ List (
37+ " canton-examples.init-script" ,
38+ " canton-examples.openssl-signature-algorithm" ,
39+ " canton-examples.openssl-script-dir" ,
40+ " canton-examples.openssl-keys-dir" ,
41+ ).foreach(System .clearProperty)
42+
3443 private def delegationRestrictions (
3544 fingerprint : Fingerprint
3645 )(implicit env : FixtureParam ) = {
@@ -45,79 +54,71 @@ sealed abstract class OpenSslOfflineRootKeyDemoExampleIntegrationTest
4554 .restriction
4655 }
4756
48- " run offline root namespace key init demo" in { implicit env =>
49- import env .*
57+ List (
58+ (" openssl-example-ec256.sh" , " ecdsa256" ),
59+ (" openssl-example-ed25519.sh" , " ed25519" ),
60+ ).foreach { case (script, keySpec) =>
61+ s " run offline root namespace key init demo for $keySpec" in { implicit env =>
62+ import env .*
5063
51- val tmpDir = better.files.File .newTemporaryDirectory(" tmp" )
52- ExampleIntegrationTest .ensureSystemProperties(
53- " canton-examples.openssl-script-dir" -> demoFolder.pathAsString
54- )
55- ExampleIntegrationTest .ensureSystemProperties(
56- " canton-examples.openssl-keys-dir" -> tmpDir.pathAsString
57- )
58- runScript(demoFolder / " bootstrap.canton" )(environment)
59- participant1.is_initialized shouldBe true
60-
61- // Check root key restrictions
62- delegationRestrictions(
63- participant1.id.fingerprint
64- ) shouldBe DelegationRestriction .CanSignAllMappings
65-
66- val namespaceDelegationFingerprint = participant1.keys.public
67- .list()
68- .find(_.name.map(_.unwrap).contains(" IntermediateKey" ))
69- .value
70- .id
71-
72- // Check intermediate key restrictions
73- delegationRestrictions(
74- namespaceDelegationFingerprint
75- ) shouldBe DelegationRestriction .CanSignAllButNamespaceDelegations
76-
77- // Run the script adding a key with signing restrictions
78- runScript(demoFolder / " restricted-key.canton" )(environment)
79-
80- // Check restricted key restrictions
81- delegationRestrictions(
82- participant1.keys.public
64+ ExampleIntegrationTest .ensureSystemProperties(
65+ " canton-examples.init-script" -> script,
66+ " canton-examples.openssl-signature-algorithm" -> keySpec,
67+ )
68+
69+ val tmpDir = better.files.File .newTemporaryDirectory(" tmp" )
70+ ExampleIntegrationTest .ensureSystemProperties(
71+ " canton-examples.openssl-script-dir" -> demoFolder.pathAsString
72+ )
73+ ExampleIntegrationTest .ensureSystemProperties(
74+ " canton-examples.openssl-keys-dir" -> tmpDir.pathAsString
75+ )
76+ runScript(demoFolder / " bootstrap.canton" )(environment)
77+ participant1.is_initialized shouldBe true
78+
79+ // Check root key restrictions
80+ delegationRestrictions(
81+ participant1.id.fingerprint
82+ ) shouldBe DelegationRestriction .CanSignAllMappings
83+
84+ val namespaceDelegationFingerprint = participant1.keys.public
8385 .list()
84- .find(_.name.map(_.unwrap).contains(" RestrictedKey " ))
86+ .find(_.name.map(_.unwrap).contains(" IntermediateKey " ))
8587 .value
8688 .id
87- ) shouldBe DelegationRestriction .CanSignSpecificMappings (
88- NonEmpty .mk(
89- Set ,
90- TopologyMapping .Code .PartyToParticipant ,
91- TopologyMapping .Code .PartyToKeyMapping ,
89+
90+ // Check intermediate key restrictions
91+ delegationRestrictions(
92+ namespaceDelegationFingerprint
93+ ) shouldBe DelegationRestriction .CanSignAllButNamespaceDelegations
94+
95+ // Run the script adding a key with signing restrictions
96+ runScript(demoFolder / " restricted-key.canton" )(environment)
97+
98+ // Check restricted key restrictions
99+ delegationRestrictions(
100+ participant1.keys.public
101+ .list()
102+ .find(_.name.map(_.unwrap).contains(" RestrictedKey" ))
103+ .value
104+ .id
105+ ) shouldBe DelegationRestriction .CanSignSpecificMappings (
106+ NonEmpty .mk(
107+ Set ,
108+ TopologyMapping .Code .PartyToParticipant ,
109+ TopologyMapping .Code .PartyToKeyMapping ,
110+ )
92111 )
93- )
94112
95- // Run the script revoking the delegation
96- runScript(demoFolder / " revoke-namespace-delegation.canton" )(environment)
113+ // Run the script revoking the delegation
114+ runScript(demoFolder / " revoke-namespace-delegation.canton" )(environment)
97115
98- // Check the delegation is gone
99- participant1.topology.namespace_delegations
100- .list(
101- store = Authorized ,
102- filterTargetKey = Some (namespaceDelegationFingerprint),
103- ) shouldBe empty
116+ // Check the delegation is gone
117+ participant1.topology.namespace_delegations
118+ .list(
119+ store = Authorized ,
120+ filterTargetKey = Some (namespaceDelegationFingerprint),
121+ ) shouldBe empty
122+ }
104123 }
105124}
106-
107- final class OpenSslOfflineRootKeyDemoExampleIntegrationTestEc256
108- extends OpenSslOfflineRootKeyDemoExampleIntegrationTest {
109- registerPlugin(new UseH2 (loggerFactory))
110- ExampleIntegrationTest .ensureSystemProperties(
111- " canton-examples.init-script" -> " openssl-example-ec256.sh" ,
112- " canton-examples.openssl-signature-algorithm" -> " ecdsa256" ,
113- )
114- }
115-
116- final class OpenSslOfflineRootKeyDemoExampleIntegrationTestEd25519
117- extends OpenSslOfflineRootKeyDemoExampleIntegrationTest {
118- registerPlugin(new UseH2 (loggerFactory))
119- ExampleIntegrationTest .ensureSystemProperties(
120- " canton-examples.init-script" -> " openssl-example-ed25519.sh" ,
121- " canton-examples.openssl-signature-algorithm" -> " ed25519" ,
122- )
123- }
0 commit comments