Skip to content

Commit

Permalink
more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyav committed Mar 6, 2024
1 parent f458e3b commit 3aebf18
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 5 additions & 2 deletions javatest/src/test/java/me/uma/javatest/UmaTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.uma.javatest;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -26,8 +27,8 @@

public class UmaTest {
UmaProtocolHelper umaProtocolHelper = new UmaProtocolHelper(new InMemoryPublicKeyCache(), new TestUmaRequester());
private static final String PUBKEY_HEX = "04f2998ab056897ddb91b5e6fad1e4bb6c4b7dda427409f667d0f4694b553e4feeeb08936c2993f7b931f6a3fa7e846f11165fae222de5e4a55c12def21a7c9fcf";
private static final String PRIVKEY_HEX = "10fbbee8f689b207bb22df2dfa27827ae9ae02e265980ea09ef5101ed5fb508f";
private static final String PUBKEY_HEX = "04419c5467ea563f0010fd614f85e885ac99c21b8e8d416241175fdd5efd2244fe907e2e6fa3dd6631b1b17cd28798da8d882a34c4776d44cc4090781c7aadea1b";
private static final String PRIVKEY_HEX = "77e891f0ecd265a3cda435eaa73792233ebd413aeb0dbb66f2940babfc9a2667";

private static final String CERT = "-----BEGIN CERTIFICATE-----\n" +
"MIIB1zCCAXygAwIBAgIUGN3ihBj1RnKoeTM/auDFnNoThR4wCgYIKoZIzj0EAwIw\n" +
Expand Down Expand Up @@ -279,6 +280,8 @@ public void serializeAndDeserializePubKeyResponse() {
parsedResponse = umaProtocolHelper.parseAsPubKeyResponse(json);
assertNotNull(parsedResponse);
assertEquals(certsOnlyResponse, parsedResponse);
assertArrayEquals(UmaTest.hexToBytes(PUBKEY_HEX), parsedResponse.getSigningPublicKey());
assertArrayEquals(UmaTest.hexToBytes(PUBKEY_HEX), parsedResponse.getEncryptionPublicKey());
}

static byte[] hexToBytes(String hex) {
Expand Down
14 changes: 9 additions & 5 deletions uma-sdk/src/commonMain/kotlin/me/uma/UmaProtocolHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ class UmaProtocolHelper @JvmOverloads constructor(
nonceCache: NonceCache,
): Boolean {
nonceCache.checkAndSaveNonce(query.nonce, query.timestamp)
return verifySignature(query.signablePayload(), query.signature, pubKeyResponse.getSigningPubKey())
return verifySignature(
query.signablePayload(),
query.signature,
pubKeyResponse.getSigningPublicKey()
)
}

/**
Expand Down Expand Up @@ -251,7 +255,7 @@ class UmaProtocolHelper @JvmOverloads constructor(
return verifySignature(
response.compliance.signablePayload(),
response.compliance.signature,
pubKeyResponse.getSigningPubKey(),
pubKeyResponse.getSigningPublicKey(),
)
}

Expand Down Expand Up @@ -391,7 +395,7 @@ class UmaProtocolHelper @JvmOverloads constructor(
return verifySignature(
payReq.signablePayload(),
compliance.signature,
pubKeyResponse.getSigningPubKey(),
pubKeyResponse.getSigningPublicKey(),
)
}

Expand Down Expand Up @@ -653,7 +657,7 @@ class UmaProtocolHelper @JvmOverloads constructor(
return verifySignature(
payReqResponse.signablePayload(payerIdentifier),
compliance.signature,
pubKeyResponse.getSigningPubKey(),
pubKeyResponse.getSigningPublicKey(),
)
}

Expand Down Expand Up @@ -702,7 +706,7 @@ class UmaProtocolHelper @JvmOverloads constructor(
return verifySignature(
postTransactionCallback.signablePayload(),
postTransactionCallback.signature,
pubKeyResponse.getSigningPubKey(),
pubKeyResponse.getSigningPublicKey(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ data class PubKeyResponse internal constructor(
expirationTimestamp = expirationTs,
)

fun getSigningPubKey(): ByteArray {
fun getSigningPublicKey(): ByteArray {
return if (signingCertificate != null) {
signingCertificate.getPubKeyBytes()
} else {
signingPubKey ?: throw IllegalStateException("No signing public key")
}
}

fun getEncryptionPubKey(): ByteArray {
fun getEncryptionPublicKey(): ByteArray {
return if (encryptionCertificate != null) {
encryptionCertificate.getPubKeyBytes()
} else {
Expand Down

0 comments on commit 3aebf18

Please sign in to comment.