Skip to content

Commit

Permalink
Adding tests for unknown API Error Codes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderjordanbaker committed Nov 3, 2023
1 parent ff4fad1 commit 06e8acf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,21 @@ public void testAPITooManyRequests() throws IOException {
Assertions.fail();
}

@Test
public void testAPIUnknownError() throws IOException {
String body = TestingUtility.readFile("models/apiUnknownError.json");
AppStoreServerAPIClient client = getAppStoreServerAPIClient(body, request -> {}, 400);
try {
client.getTransactionInfo("1234");
} catch (APIException e) {
Assertions.assertEquals(400 , e.getHttpStatusCode());
Assertions.assertNull(e.getApiError());
Assertions.assertEquals(9990000L, e.getRawApiError());
return;
}
Assertions.fail();
}

public AppStoreServerAPIClient getClientWithBody(String path, Consumer<Request> requestVerifier) throws IOException {
String body = TestingUtility.readFile(path);
return getAppStoreServerAPIClient(body, requestVerifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public static byte[] readBytes(String file) throws IOException {
}
}

public static SignedDataVerifier getSignedPayloadVerifier(Environment environment, String bundleId, Long appAppleId) throws IOException {
return new SignedDataVerifier(Set.of(new ByteArrayInputStream(readBytes("certs/testCA.der"))), bundleId, appAppleId, environment, false);
}

public static SignedDataVerifier getSignedPayloadVerifier(Environment environment, String bundleId) throws IOException {
return new SignedDataVerifier(Set.of(new ByteArrayInputStream(readBytes("certs/testCA.der"))), bundleId, 1234L, environment, false);
return getSignedPayloadVerifier(environment, bundleId, 1234L);
}

public static SignedDataVerifier getSignedPayloadVerifier() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public void testWrongBundleIdForServerNotification() throws IOException {
Assertions.assertEquals(Status.INVALID_APP_IDENTIFIER, exception.getStatus());
}

@Test
public void testWrongAppAppleIdForNotification() throws IOException {
SignedDataVerifier verifier = TestingUtility.getSignedPayloadVerifier(Environment.PRODUCTION, "com.example", 1235L);
VerificationException exception = Assertions.assertThrows(VerificationException.class, () -> verifier.verifyAndDecodeNotification(TestingUtility.readFile("mock_signed_data/testNotification")));
Assertions.assertEquals(Status.INVALID_APP_IDENTIFIER, exception.getStatus());
}

@Test
public void testWrongBundleIdForTransaction() throws IOException {
SignedDataVerifier verifier = TestingUtility.getSignedPayloadVerifier(Environment.SANDBOX, "com.example.x");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void testXcodeSignedRenewalInfo() throws IOException, VerificationExcepti

JWSRenewalInfoDecodedPayload renewalInfo = verifier.verifyAndDecodeRenewalInfo(encodedRenewalInfo);

System.out.println(renewalInfo);
Assertions.assertNull(renewalInfo.getExpirationIntent());
Assertions.assertEquals("0", renewalInfo.getOriginalTransactionId());
Assertions.assertEquals("pass.premium", renewalInfo.getAutoRenewProductId());
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/models/apiUnknownError.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errorCode": 9990000,
"errorMessage": "Testing error."
}

0 comments on commit 06e8acf

Please sign in to comment.