Skip to content

Commit 8c9b4d3

Browse files
Merge pull request #86 from alexanderjordanbaker/AppAppleIdProductionException
Resolves https://github.com/apple/app-store-server-library-node/issue…
2 parents 8700697 + 59a1943 commit 8c9b4d3

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ const bundleId = "com.example"
3939
const filePath = "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"
4040
const encodedKey = readFile(filePath) // Specific implementation may vary
4141
const environment = Environment.SANDBOX
42+
const appAppleId = undefined // appAppleId is required when the environment is Production
4243

43-
const client = new AppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment)
44+
const client = new AppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment, appAppleId)
4445

4546
try {
4647
const response: SendTestNotificationResponse = await client.requestTestNotification()

jws_verification.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export class SignedDataVerifier {
5757
this.bundleId = bundleId;
5858
this.environment = environment
5959
this.appAppleId = appAppleId
60+
if (environment === Environment.PRODUCTION && appAppleId === undefined) {
61+
throw new Error("appAppleId is required when the environment is Production")
62+
}
6063
}
6164

6265
/**

tests/unit-tests/jws_verification.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SignedJWTVerifierTest extends SignedDataVerifier {
3434

3535
describe("Chain Verification Checks", () => {
3636
it('should validate a chain without OCSP', async () => {
37-
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
37+
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
3838
const publicKey = await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
3939
expect(Buffer.from(LEAF_CERT_PUBLIC_KEY_BASE64_ENCODED, 'base64')).toMatchObject(publicKey.export({
4040
type: 'spki',
@@ -43,7 +43,7 @@ describe("Chain Verification Checks", () => {
4343
})
4444

4545
it('should fail to validate a chain with an invalid intermediate OID', async () => {
46-
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
46+
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
4747
try {
4848
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_FOR_INTERMEDIATE_CA_INVALID_OID_BASE64_ENCODED, INTERMEDIATE_CA_INVALID_OID_BASE64_ENCODED)
4949
assert(false)
@@ -54,7 +54,7 @@ describe("Chain Verification Checks", () => {
5454
})
5555

5656
it('should fail to validate a chain with an invalid leaf OID', async () => {
57-
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
57+
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
5858
try {
5959
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_INVALID_OID_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
6060
assert(false)
@@ -65,7 +65,7 @@ describe("Chain Verification Checks", () => {
6565
})
6666

6767
it('should fail to validate a chain with empty root certificate array', async () => {
68-
const verifier = new SignedJWTVerifierTest([], false, Environment.PRODUCTION, "com.example");
68+
const verifier = new SignedJWTVerifierTest([], false, Environment.PRODUCTION, "com.example", 1234);
6969
try {
7070
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
7171
assert(false)
@@ -76,7 +76,7 @@ describe("Chain Verification Checks", () => {
7676
})
7777

7878
it('should fail to validate a chain with an expired chain', async () => {
79-
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
79+
const verifier = new SignedJWTVerifierTest([Buffer.from(ROOT_CA_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
8080
verifier.effectiveDate = new Date(2280946846000)
8181
try {
8282
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
@@ -88,12 +88,12 @@ describe("Chain Verification Checks", () => {
8888
})
8989

9090
it('should validate a real chain with OCSP', async () => {
91-
const verifier = new SignedJWTVerifierTest([Buffer.from(REAL_APPLE_ROOT_BASE64_ENCODED, 'base64')], true, Environment.PRODUCTION, "com.example");
91+
const verifier = new SignedJWTVerifierTest([Buffer.from(REAL_APPLE_ROOT_BASE64_ENCODED, 'base64')], true, Environment.PRODUCTION, "com.example", 1234);
9292
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), REAL_APPLE_SIGNING_CERTIFICATE_BASE64_ENCODED, REAL_APPLE_INTERMEDIATE_BASE64_ENCODED)
9393
})
9494

9595
it('should fail to validate a chain with mismatched root certificates', async () => {
96-
const verifier = new SignedJWTVerifierTest([Buffer.from(REAL_APPLE_ROOT_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example");
96+
const verifier = new SignedJWTVerifierTest([Buffer.from(REAL_APPLE_ROOT_BASE64_ENCODED, 'base64')], false, Environment.PRODUCTION, "com.example", 1234);
9797
try {
9898
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
9999
assert(false)
@@ -106,7 +106,7 @@ describe("Chain Verification Checks", () => {
106106

107107
it('should fail to validate a chain with invalid root certificates', async () => {
108108
try {
109-
const verifier = new SignedJWTVerifierTest([Buffer.from("abc", "utf-8")], false, Environment.PRODUCTION, "com.example");
109+
const verifier = new SignedJWTVerifierTest([Buffer.from("abc", "utf-8")], false, Environment.PRODUCTION, "com.example", 1234);
110110
await verifier.testVerifyCertificateChain(verifier.getRootCertificates(), LEAF_CERT_BASE64_ENCODED, INTERMEDIATE_CA_BASE64_ENCODED)
111111
} catch (e) {
112112
return

0 commit comments

Comments
 (0)