Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: code style #87

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.apple.itunes.storekit.model.TransactionHistoryRequest;
import com.apple.itunes.storekit.model.TransactionInfoResponse;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.Call;
Expand All @@ -39,6 +38,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class AppStoreServerAPIClient {
Expand Down Expand Up @@ -79,7 +79,7 @@ private Response makeRequest(String path, String method, Map<String, List<String
requestBuilder.addHeader("User-Agent", USER_AGENT);
requestBuilder.addHeader("Authorization", "Bearer " + bearerTokenAuthenticator.generateToken());
requestBuilder.addHeader("Accept", "application/json");
HttpUrl.Builder urlBuilder = urlBase.resolve(path).newBuilder();
HttpUrl.Builder urlBuilder = Objects.requireNonNull(urlBase.resolve(path)).newBuilder();
for (Map.Entry<String, List<String>> entry : queryParameters.entrySet()) {
for (String queryValue : entry.getValue()) {
urlBuilder.addQueryParameter(entry.getKey(), queryValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.time.temporal.ChronoUnit;
import java.util.Base64;
import java.util.Map;
import java.util.stream.Collectors;

public class BearerTokenAuthenticator {
private static final String APP_STORE_CONNECT_AUDIENCE = "appstoreconnect-v1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
Information that represents the customer’s purchase of the app, cryptographically signed by the App Store.
@see <a href="https://developer.apple.com/documentation/storekit/apptransaction">AppTransaction</a>
*/
public class AppTransaction implements DecodedSignedData {

Expand Down Expand Up @@ -253,7 +252,6 @@ public AppTransaction deviceVerificationNonce(UUID deviceVerificationNonce) {
@see <a href="https://developer.apple.com/documentation/storekit/apptransaction/4013175-preorderdate">preorderDate</a>
*/

public Long getPreorderDate() {
return preorderDate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void testExtendRenewalDateForAllActiveSubscribers() throws IOException, A
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<String, Object> root = null;
Map<String, Object> root;
try {
root = new ObjectMapper().readValue(buffer.readUtf8(), Map.class);
} catch (JsonProcessingException e) {
Expand Down Expand Up @@ -118,7 +118,7 @@ public void testExtendSubscriptionRenewalDate() throws IOException, APIException
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<String, Object> root = null;
Map<String, Object> root;
try {
root = new ObjectMapper().readValue(buffer.readUtf8(), Map.class);
} catch (JsonProcessingException e) {
Expand Down Expand Up @@ -259,7 +259,7 @@ public void testGetNotificationHistory() throws APIException, IOException {
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<String, Object> root = null;
Map<String, Object> root;
try {
root = new ObjectMapper().readValue(buffer.readUtf8(), Map.class);
} catch (JsonProcessingException e) {
Expand Down Expand Up @@ -412,7 +412,7 @@ public void testSendConsumptionData() throws APIException, IOException {
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<String, Object> root = null;
Map<String, Object> root;
try {
root = new ObjectMapper().readValue(buffer.readUtf8(), Map.class);
} catch (JsonProcessingException e) {
Expand Down Expand Up @@ -573,6 +573,7 @@ private AppStoreServerAPIClient getAppStoreServerAPIClient(String body, Consumer

private AppStoreServerAPIClient getAppStoreServerAPIClient(String body, Consumer<Request> requestVerifier, int statusCode) throws IOException {
try (InputStream key = this.getClass().getClassLoader().getResourceAsStream("certs/testSigningKey.p8")) {
Assertions.assertNotNull(key);
return new AppStoreServerAPIClient(new String(key.readAllBytes()), "keyId", "issuerId", "com.example", Environment.LOCAL_TESTING) {
@Override
protected Response getResponse(Request request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BearerTokenAuthenticatorTest {
@Test
void testCreatingToken() throws Exception {
try (InputStream key = this.getClass().getClassLoader().getResourceAsStream("certs/testSigningKey.p8")) {
Assertions.assertNotNull(key);
var tokenGenerator = new BearerTokenAuthenticator(new String(key.readAllBytes()), "keyId", "issuerId", "bundleId");
String token = tokenGenerator.generateToken();
Assertions.assertNotNull(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

public class JWSRenewalInfoDecodedPayloadTest {

@Test
public void testRenewalInfoDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
public void testRenewalInfoDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
String signedRenewalInfo = SignedDataCreator.createSignedDataFromJson("models/signedRenewalInfo.json");

JWSRenewalInfoDecodedPayload renewalInfo = TestingUtility.getSignedPayloadVerifier().verifyAndDecodeRenewalInfo(signedRenewalInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.UUID;

public class JWSTransactionDecodedPayloadTest {

@Test
public void testTransactionDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
public void testTransactionDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
String signedTransaction = SignedDataCreator.createSignedDataFromJson("models/signedTransaction.json");

JWSTransactionDecodedPayload transaction = TestingUtility.getSignedPayloadVerifier().verifyAndDecodeTransaction(signedTransaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.List;
import java.util.Set;

public class ResponseBodyV2DecodedPayloadTest {

@Test
public void testNotificationDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
public void testNotificationDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
String signedNotification = SignedDataCreator.createSignedDataFromJson("models/signedNotification.json");

ResponseBodyV2DecodedPayload notification = TestingUtility.getSignedPayloadVerifier().verifyAndDecodeNotification(signedNotification);
Expand All @@ -46,7 +45,7 @@ public void testNotificationDecoding() throws IOException, NoSuchAlgorithmExcept
}

@Test
public void testSummaryNotificationDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
public void testSummaryNotificationDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
String signedNotification = SignedDataCreator.createSignedDataFromJson("models/signedSummaryNotification.json");

ResponseBodyV2DecodedPayload notification = TestingUtility.getSignedPayloadVerifier().verifyAndDecodeNotification(signedNotification);
Expand All @@ -73,12 +72,12 @@ public void testSummaryNotificationDecoding() throws IOException, NoSuchAlgorith
}

@Test
public void testExternalPurchaseTokenNotificationDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
public void testExternalPurchaseTokenNotificationDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
String signedNotification = SignedDataCreator.createSignedDataFromJson("models/signedExternalPurchaseTokenNotification.json");

SignedDataVerifier verifier = new SignedDataVerifier(Set.of(new ByteArrayInputStream(TestingUtility.readBytes("certs/testCA.der"))), "com.example", 1234L, Environment.LOCAL_TESTING, false) {
@Override
protected void verifyNotification(String bundleId, Long appAppleId, Environment notificationEnv) throws VerificationException {
protected void verifyNotification(String bundleId, Long appAppleId, Environment notificationEnv) {
Assertions.assertEquals("com.example", bundleId);
Assertions.assertEquals(55555, appAppleId);
Assertions.assertEquals(Environment.PRODUCTION, notificationEnv);
Expand All @@ -104,12 +103,12 @@ protected void verifyNotification(String bundleId, Long appAppleId, Environment
}

@Test
public void testExternalPurchaseTokenSandboxNotificationDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
public void testExternalPurchaseTokenSandboxNotificationDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
String signedNotification = SignedDataCreator.createSignedDataFromJson("models/signedExternalPurchaseTokenSandboxNotification.json");

SignedDataVerifier verifier = new SignedDataVerifier(Set.of(new ByteArrayInputStream(TestingUtility.readBytes("certs/testCA.der"))), "com.example", 1234L, Environment.LOCAL_TESTING, false) {
@Override
protected void verifyNotification(String bundleId, Long appAppleId, Environment notificationEnv) throws VerificationException {
protected void verifyNotification(String bundleId, Long appAppleId, Environment notificationEnv) {
Assertions.assertEquals("com.example", bundleId);
Assertions.assertEquals(55555, appAppleId);
Assertions.assertEquals(Environment.SANDBOX, notificationEnv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PromotionalOfferSignatureCreatorTest {
@Test
void testSignatureCreator() throws Exception {
try (InputStream key = this.getClass().getClassLoader().getResourceAsStream("certs/testSigningKey.p8")) {
Assertions.assertNotNull(key);
PromotionalOfferSignatureCreator signatureCreator = new PromotionalOfferSignatureCreator(new String(key.readAllBytes()), "keyId", "bundleId");
String signature = signatureCreator.createSignature("productId", "offerId", "applicationUsername", UUID.fromString("20fba8a0-2b80-4a7d-a17f-85c1854727f8"), 1698148900000L);
Assertions.assertNotNull(signature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.ECDSAKeyProvider;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.KeyFactory;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import java.util.Map;

public class SignedDataCreator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.apple.itunes.storekit.model.Environment;
import com.apple.itunes.storekit.verification.SignedDataVerifier;
import org.junit.jupiter.api.Assertions;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -19,6 +20,7 @@ public static String readFile(String file) throws IOException {

public static byte[] readBytes(String file) throws IOException {
try (InputStream stream = TestingUtility.class.getClassLoader().getResourceAsStream(file)) {
Assertions.assertNotNull(stream);
return stream.readAllBytes();
}
}
Expand Down
Loading