forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ledger-api-client: Add test cases for
LedgerClient
. (digital-asset#…
…7195) * ledger-api-client: Add integration tests for the simple stuff. * sandbox-common: Make `SandboxFixtureWithAuth` a mixin. This makes it useful with `SandboxNextFixture` as well as `SandboxFixture`. Also, add types to non-private fields and methods, and make more fields protected rather than public. * ledger-api-client: Add tests to make sure the token is passed through. CHANGELOG_BEGIN CHANGELOG_END * sandbox-common: Tokens are for auth, not auth.
- Loading branch information
1 parent
ba74146
commit 30564a7
Showing
13 changed files
with
272 additions
and
115 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
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
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
99 changes: 99 additions & 0 deletions
99
...er/ledger-api-client/src/it/scala/com/digitalasset/ledger/client/LedgerClientAuthIT.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,99 @@ | ||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.client | ||
|
||
import com.daml.grpc.GrpcException | ||
import com.daml.ledger.api.domain | ||
import com.daml.ledger.api.testing.utils.{AkkaBeforeAndAfterAll, SuiteResourceManagementAroundEach} | ||
import com.daml.ledger.client.configuration.{ | ||
CommandClientConfiguration, | ||
LedgerClientConfiguration, | ||
LedgerIdRequirement | ||
} | ||
import com.daml.platform.common.LedgerIdMode | ||
import com.daml.platform.sandbox.SandboxRequiringAuthorization | ||
import com.daml.platform.sandbox.config.SandboxConfig | ||
import com.daml.platform.sandboxnext.SandboxNextFixture | ||
import org.scalatest.{AsyncWordSpec, Inside, Matchers} | ||
|
||
final class LedgerClientAuthIT | ||
extends AsyncWordSpec | ||
with Matchers | ||
with Inside | ||
with AkkaBeforeAndAfterAll | ||
with SuiteResourceManagementAroundEach | ||
with SandboxNextFixture | ||
with SandboxRequiringAuthorization { | ||
|
||
private val LedgerId = | ||
domain.LedgerId(s"${classOf[LedgerClientAuthIT].getSimpleName.toLowerCase}-ledger-id") | ||
|
||
private val ClientConfigurationWithoutToken = LedgerClientConfiguration( | ||
applicationId = classOf[LedgerClientAuthIT].getSimpleName, | ||
ledgerIdRequirement = LedgerIdRequirement.none, | ||
commandClient = CommandClientConfiguration.default, | ||
sslContext = None, | ||
token = None, | ||
) | ||
|
||
private val ClientConfiguration = ClientConfigurationWithoutToken.copy( | ||
token = Some(toHeader(readOnlyToken("Read-only party"))), | ||
) | ||
|
||
override protected def config: SandboxConfig = super.config.copy( | ||
ledgerIdMode = LedgerIdMode.Static(LedgerId), | ||
) | ||
|
||
"the ledger client" when { | ||
"it has a read-only token" should { | ||
"retrieve the ledger ID" in { | ||
for { | ||
client <- LedgerClient(channel, ClientConfiguration) | ||
} yield { | ||
client.ledgerId should be(LedgerId) | ||
} | ||
} | ||
|
||
"fail to conduct an admin operation with the same token" in { | ||
for { | ||
client <- LedgerClient(channel, ClientConfiguration) | ||
exception <- client.partyManagementClient | ||
.allocateParty(hint = Some("Bob"), displayName = None) | ||
.failed | ||
} yield { | ||
inside(exception) { | ||
case GrpcException.PERMISSION_DENIED() => succeed | ||
} | ||
} | ||
} | ||
|
||
"succeed in conducting an admin operation with an admin token" in { | ||
val partyName = "Carol" | ||
for { | ||
client <- LedgerClient(channel, ClientConfiguration) | ||
allocatedParty <- client.partyManagementClient | ||
.allocateParty( | ||
hint = Some(partyName), | ||
displayName = Some(partyName), | ||
token = Some(toHeader(adminToken)), | ||
) | ||
} yield { | ||
allocatedParty.displayName should be(Some(partyName)) | ||
} | ||
} | ||
} | ||
|
||
"it does not have a token" should { | ||
"fail to construct" in { | ||
for { | ||
exception <- LedgerClient(channel, ClientConfigurationWithoutToken).failed | ||
} yield { | ||
inside(exception) { | ||
case GrpcException.UNAUTHENTICATED() => succeed | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.