Skip to content

Commit

Permalink
feat(sdk): scope custom claims android and ios tests. (#664)
Browse files Browse the repository at this point in the history
Signed-off-by: Volodymyr Kubiv <[email protected]>
  • Loading branch information
vkubiv authored Nov 10, 2023
1 parent 1107841 commit 398e66e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
66 changes: 34 additions & 32 deletions demo/app/android/app/src/androidTest/kotlin/integration_test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import dev.trustbloc.wallet.sdk.didion.Didion
import dev.trustbloc.wallet.sdk.localkms.Localkms
import dev.trustbloc.wallet.sdk.oauth2.Oauth2
import dev.trustbloc.wallet.sdk.openid4ci.*
import dev.trustbloc.wallet.sdk.openid4vp.PresentCredentialOpts
import dev.trustbloc.wallet.sdk.openid4vp.Interaction as VPInteraction
import dev.trustbloc.wallet.sdk.version.Version
import dev.trustbloc.wallet.sdk.otel.Otel
Expand All @@ -37,11 +38,11 @@ class IntegrationTest {
instrumentationContext = InstrumentationRegistry.getInstrumentation().context
}

@Test
@Test
fun fullFlow() {
val trace = Otel.newTrace()
val trace = Otel.newTrace()

assertThat(Version.getVersion()).isEqualTo("testVer")
assertThat(Version.getVersion()).isEqualTo("testVer")
assertThat(Version.getGitRevision()).isEqualTo("testRev")
assertThat(Version.getBuildTime()).isEqualTo("testTime")

Expand Down Expand Up @@ -77,9 +78,9 @@ class IntegrationTest {
val authorizationRequestURI = BuildConfig.INITIATE_VERIFICATION_URL

val openID4VPInteractionRequiredArgs = dev.trustbloc.wallet.sdk.openid4vp.Args(
authorizationRequestURI,
crypto,
didResolver
authorizationRequestURI,
crypto,
didResolver
)

val vpOpts = dev.trustbloc.wallet.sdk.openid4vp.Opts()
Expand Down Expand Up @@ -114,11 +115,12 @@ class IntegrationTest {
selectedCreds.add(requirementDescriptor.matchedVCs.atIndex(0))

// Presenting from selected credentials.
vpInteraction.presentCredential(selectedCreds)
vpInteraction.presentCredentialWithOpts(selectedCreds, PresentCredentialOpts().addScopeClaim(
"registration", """{"email":"[email protected]"}"""))
}

@Test
fun testAuthFlow() {
fun testAuthFlow() {
val trace = Otel.newTrace()

assertThat(Version.getVersion()).isEqualTo("testVer")
Expand All @@ -140,7 +142,7 @@ class IntegrationTest {
// Issue VCs
val requestURI = BuildConfig.INITIATE_ISSUANCE_URLS_AUTH_CODE_FLOW
println("requestURI ->")
println( requestURI)
println(requestURI)

val requiredOpenID4CIArgs = IssuerInitiatedInteractionArgs(requestURI, crypto, didResolver)
println("requiredOpenID4CIArgs")
Expand All @@ -156,7 +158,7 @@ class IntegrationTest {

assertThat(ciInteraction.dynamicClientRegistrationSupported()).isTrue()

if (ciInteraction.dynamicClientRegistrationSupported()){
if (ciInteraction.dynamicClientRegistrationSupported()) {
var dynamicRegistrationEndpoint = ciInteraction.dynamicClientRegistrationEndpoint()
assertThat(dynamicRegistrationEndpoint).isNotEmpty()

Expand All @@ -175,7 +177,7 @@ class IntegrationTest {
clientMetadata.setTokenEndpointAuthMethod("none")

var authorizationCodeGrantParams = ciInteraction.authorizationCodeGrantParams()
if (authorizationCodeGrantParams.hasIssuerState()){
if (authorizationCodeGrantParams.hasIssuerState()) {
var issuerState = authorizationCodeGrantParams.issuerState()
clientMetadata.setIssuerState(issuerState)
assertThat(clientMetadata.issuerState()).isNotEmpty()
Expand All @@ -200,39 +202,39 @@ class IntegrationTest {
var redirectUrl = URI(authorizationLink)

val client = OkHttpClient.Builder()
.retryOnConnectionFailure(true)
.followRedirects(false)
.build()
.retryOnConnectionFailure(true)
.followRedirects(false)
.build()

var request = Request.Builder()
.url(redirectUrl.toString())
.header("Connection", "close")
.build()
.url(redirectUrl.toString())
.header("Connection", "close")
.build()
val response = client.newCall(request).execute()
assertThat(response.isRedirect).isTrue()
var location = response.headers["Location"]
assertThat(location).contains("cognito-mock.trustbloc.local")
if (location != null) {
if (location.contains("cognito-mock.trustbloc.local")){
var upr = URI(location.replace("cognito-mock.trustbloc.local", "localhost"));
assertThat(upr.toString()).contains("localhost")
var request = Request.Builder()
if (location != null) {
if (location.contains("cognito-mock.trustbloc.local")) {
var upr = URI(location.replace("cognito-mock.trustbloc.local", "localhost"));
assertThat(upr.toString()).contains("localhost")
var request = Request.Builder()
.url(upr.toString())
.header("Connection", "close")
.build()
val response = client.newCall(request).clone().execute()
location = response.headers["location"]
assertThat(location).contains("oidc/redirect")
var request2 = Request.Builder()
val response = client.newCall(request).clone().execute()
location = response.headers["location"]
assertThat(location).contains("oidc/redirect")
var request2 = Request.Builder()
.url(location.toString())
.header("Connection", "close")
.build()
val response2 = client.newCall(request2).clone().execute()
location = response2.headers["location"]
assertThat(location).contains("127.0.0.1")
var issuedCreds = ciInteraction.requestCredentialWithAuth(userDID.assertionMethod(), location, null)
assertThat(issuedCreds.length()).isGreaterThan(0)
}
val response2 = client.newCall(request2).clone().execute()
location = response2.headers["location"]
assertThat(location).contains("127.0.0.1")
var issuedCreds = ciInteraction.requestCredentialWithAuth(userDID.assertionMethod(), location, null)
assertThat(issuedCreds.length()).isGreaterThan(0)
}
}
}
}
4 changes: 3 additions & 1 deletion demo/app/ios/Runner/Tests/IntegrationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class IntegrationTest: XCTestCase {
selectedCreds.add(requirementDescriptor.matchedVCs!.atIndex(0))

// Presenting from selected credentials.
try vpInteraction.presentCredential(selectedCreds)
try vpInteraction.presentCredential(withOpts: selectedCreds,
opts: Openid4vpNewPresentCredentialOpts()?.addScopeClaim("registration", claimJSON:#"{"email":"[email protected]"}"#)
)
}

func testAuthFlow() throws {
Expand Down
2 changes: 1 addition & 1 deletion scripts/android_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

cd test/integration
INITIATE_ISSUANCE_URL="$(../../build/bin/integration-cli issuance bank_issuer)"
INITIATE_VERIFICATION_URL="$(../../build/bin/integration-cli verification v_myprofile_jwt_verified_employee)"
INITIATE_VERIFICATION_URL="$(../../build/bin/integration-cli verification v_myprofile_jwt_verified_employee#withScope=registration)"
INITIATE_ISSUANCE_URLS_AUTH_CODE_FLOW="$(../../build/bin/integration-cli auth-code-flow bank_issuer did_ion_issuer)"

echo "INITIATE_ISSUANCE_URL:${INITIATE_ISSUANCE_URL}"
Expand Down
2 changes: 1 addition & 1 deletion scripts/ios_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

cd test/integration
INITIATE_ISSUANCE_URL="$(../../build/bin/integration-cli issuance bank_issuer)"
INITIATE_VERIFICATION_URL="$(../../build/bin/integration-cli verification v_myprofile_jwt_verified_employee)"
INITIATE_VERIFICATION_URL="$(../../build/bin/integration-cli verification v_myprofile_jwt_verified_employee#withScope=registration)"
INITIATE_ISSUANCE_URLS_AUTH_CODE_FLOW="$(../../build/bin/integration-cli auth-code-flow bank_issuer did_ion_issuer)"

echo "INITIATE_ISSUANCE_URL:${INITIATE_ISSUANCE_URL}"
Expand Down

0 comments on commit 398e66e

Please sign in to comment.