-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for client bindings (#9036)
* Add tests for client bindings changelog_begin changelog_end Closes #8636 * Address #9036 (comment)
- Loading branch information
1 parent
27fd932
commit 1bec211
Showing
3 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
runtime-components/non-repudiation-client/src/test/resources/logback-test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="stderr-appender" class="ch.qos.logback.core.ConsoleAppender"> | ||
<target>System.err</target> | ||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||
<level>trace</level> | ||
</filter> | ||
<encoder> | ||
<pattern>%date{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", UTC} %-5level %logger{5}@[%-4.30thread] - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="${LOGLEVEL:-WARN}"> | ||
<appender-ref ref="stderr-appender"/> | ||
</root> | ||
|
||
</configuration> |
103 changes: 103 additions & 0 deletions
103
...diation-client/src/test/scala/com/daml/nonrepudiation/client/SigningInterceptorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.nonrepudiation.client | ||
|
||
import java.time.{Clock, Instant, ZoneId} | ||
import java.util.Collections | ||
|
||
import com.daml.ledger.api.v1.CommandServiceOuterClass.SubmitAndWaitRequest | ||
import com.daml.ledger.javaapi.data.Command | ||
import com.daml.ledger.api.v1.CommandsOuterClass.{Command => ProtoCommand} | ||
import com.daml.ledger.api.v1.command_service.CommandServiceGrpc.CommandService | ||
import com.daml.ledger.api.v1.command_submission_service.CommandSubmissionServiceGrpc.CommandSubmissionService | ||
import com.daml.ledger.rxjava.DamlLedgerClient | ||
import com.daml.nonrepudiation.testing._ | ||
import com.daml.nonrepudiation.{ | ||
AlgorithmString, | ||
CommandIdString, | ||
NonRepudiationProxy, | ||
SignatureBytes, | ||
SignedPayload, | ||
} | ||
import com.daml.resources.grpc.{GrpcResourceOwnerFactories => Resources} | ||
import io.grpc.netty.NettyChannelBuilder | ||
import org.scalatest.Inside | ||
import org.scalatest.flatspec.AsyncFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.duration.DurationInt | ||
|
||
final class SigningInterceptorSpec extends AsyncFlatSpec with Matchers with Inside { | ||
|
||
behavior of "SigningInterceptor" | ||
|
||
it should "be possible to use it with the Java bindings" in { | ||
val (key, certificate) = generateKeyAndCertificate() | ||
val builders = | ||
DummyTestSetup.Builders( | ||
useNetworkStack = true, | ||
serviceExecutionContext = ExecutionContext.global, | ||
) | ||
|
||
val certificates = new Certificates | ||
val signedPayloads = new SignedPayloads[CommandIdString] | ||
|
||
val expectedAlgorithm = AlgorithmString.SHA256withRSA | ||
val expectedFingerprint = certificates.put(certificate) | ||
val expectedTimestamp = Instant.now() | ||
|
||
val proxy = | ||
for { | ||
_ <- Resources.forServer(builders.participantServer, 5.seconds) | ||
participant <- Resources.forChannel(builders.participantChannel, 5.seconds) | ||
proxy <- NonRepudiationProxy.owner( | ||
participant, | ||
builders.proxyServer, | ||
certificates, | ||
signedPayloads, | ||
Clock.fixed(expectedTimestamp, ZoneId.systemDefault()), | ||
CommandService.scalaDescriptor.fullName, | ||
CommandSubmissionService.scalaDescriptor.fullName, | ||
) | ||
} yield proxy | ||
|
||
proxy.use { _ => | ||
val clientChannelBuilder = | ||
builders.proxyChannel | ||
.asInstanceOf[NettyChannelBuilder] | ||
.intercept(SigningInterceptor.signCommands(key, certificate)) | ||
val client = DamlLedgerClient.newBuilder(clientChannelBuilder).build() | ||
client.connect() | ||
val command = ProtoCommand.parseFrom(generateCommand().getCommands.commands.head.toByteArray) | ||
val expectedWorkflowId = "workflow-id" | ||
val expectedApplicationId = "application-id" | ||
val expectedCommandId = "command-id" | ||
val expectedParty = "party-1" | ||
client.getCommandClient | ||
.submitAndWait( | ||
expectedWorkflowId, | ||
expectedApplicationId, | ||
expectedCommandId, | ||
expectedParty, | ||
Collections.singletonList(Command.fromProtoCommand(command)), | ||
) | ||
.blockingGet() | ||
inside(signedPayloads.get(CommandIdString.wrap("command-id"))) { | ||
case Seq(SignedPayload(algorithm, fingerprint, payload, signature, timestamp)) => | ||
val commands = SubmitAndWaitRequest.parseFrom(payload.unsafeArray).getCommands | ||
algorithm shouldBe expectedAlgorithm | ||
fingerprint shouldBe expectedFingerprint | ||
commands.getWorkflowId shouldBe expectedWorkflowId | ||
commands.getApplicationId shouldBe expectedApplicationId | ||
commands.getCommandId shouldBe expectedCommandId | ||
commands.getParty shouldBe expectedParty | ||
commands.getCommandsCount shouldBe 1 | ||
signature shouldBe SignatureBytes.sign(expectedAlgorithm, key, payload) | ||
timestamp shouldBe expectedTimestamp | ||
} | ||
} | ||
} | ||
|
||
} |