Skip to content

Commit

Permalink
adjust ios credentials manager to multitarget projects
Browse files Browse the repository at this point in the history
  • Loading branch information
dsokal committed Jun 7, 2021
1 parent 0139afe commit 2d2dd5b
Show file tree
Hide file tree
Showing 31 changed files with 899 additions and 830 deletions.
3 changes: 0 additions & 3 deletions packages/eas-cli/src/build/ios/__mocks__/bundleIdentifier.ts

This file was deleted.

12 changes: 2 additions & 10 deletions packages/eas-cli/src/build/ios/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import nullthrows from 'nullthrows';

import { createCredentialsContextAsync } from '../../credentials/context';
import IosCredentialsProvider from '../../credentials/ios/IosCredentialsProvider';
import { getAppFromContext } from '../../credentials/ios/actions/BuildCredentialsUtils';
import { resolveEntitlementsJsonAsync } from '../../credentials/ios/appstore/entitlements';
import { IosCredentials, Target } from '../../credentials/ios/types';
import { findAccountByName } from '../../user/Account';
import { CredentialsResult } from '../build';
import { BuildContext } from '../context';
import { Platform } from '../types';
Expand All @@ -25,13 +23,7 @@ export async function ensureIosCredentialsAsync(
});

const provider = new IosCredentialsProvider(ctx, {
app: {
account: nullthrows(
findAccountByName(ctx.user.accounts, buildCtx.commandCtx.accountName),
`You do not have access to account: ${buildCtx.commandCtx.accountName}`
),
projectName: buildCtx.commandCtx.projectName,
},
app: getAppFromContext(ctx),
targets,
iosCapabilitiesOptions: {
entitlements: await resolveEntitlementsJsonAsync(
Expand Down
3 changes: 3 additions & 0 deletions packages/eas-cli/src/credentials/__tests__/fixtures-ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
PushKey,
} from '../ios/appstore/Credentials.types';
import { IosDistCredentials, IosPushCredentials } from '../ios/credentials';
import { Target } from '../ios/types';
import { testProvisioningProfileBase64 } from './fixtures-base64-data';
import { testBundleIdentifier, testExperienceName } from './fixtures-constants';

Expand All @@ -40,6 +41,8 @@ export const testAppFragment: AppFragment = {
slug: 'testapp',
};

export const testTargets: Target[] = [{ targetName: 'testapp', bundleIdentifier: 'foo.bar.com' }];

export const testProvisioningProfileFragment: AppleProvisioningProfileFragment = {
id: 'test-prov-prof-id-1',
expiration: new Date(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { vol } from 'memfs';

import { findApplicationTarget } from '../../../project/ios/target';
import { testTargets } from '../../__tests__/fixtures-ios';
import * as credentialsJsonReader from '../read';

jest.mock('fs');
Expand Down Expand Up @@ -37,7 +39,7 @@ describe('credentialsJson', () => {
it('should throw error when credentials.json is missing', async () => {
const promise = credentialsJsonReader.readAndroidCredentialsAsync('.');
await expect(promise).rejects.toThrow(
'credentials.json must exist in the project root directory and contain a valid JSON'
'credentials.json does not exist in the project root directory'
);
});

Expand All @@ -47,9 +49,7 @@ describe('credentialsJson', () => {
'keystore.jks': 'somebinarydata',
});
const promise = credentialsJsonReader.readAndroidCredentialsAsync('.');
await expect(promise).rejects.toThrow(
'Android credentials are missing from credentials.json'
);
await expect(promise).rejects.toThrow('Android credentials are missing in credentials.json');
});
it('should throw error when one of the required fields is missing', async () => {
vol.fromJSON({
Expand All @@ -69,7 +69,7 @@ describe('credentialsJson', () => {
'credentials.json is not valid [ValidationError: "android.keystore.keystorePath" is required]'
);
});
it('should throw error when file specified in cedentials.json is missing', async () => {
it('should throw error when file specified in credentials.json is missing', async () => {
vol.fromJSON({
'./credentials.json': JSON.stringify({
android: {
Expand Down Expand Up @@ -105,19 +105,25 @@ describe('credentialsJson', () => {
'./pprofile': 'somebinarycontent',
'./cert.p12': 'somebinarycontent2',
});
const result = await credentialsJsonReader.readIosCredentialsAsync('.');
const applicationTarget = findApplicationTarget(testTargets);
const result = await credentialsJsonReader.readIosCredentialsAsync('.', applicationTarget);
expect(result).toEqual({
provisioningProfile: 'c29tZWJpbmFyeWNvbnRlbnQ=',
distributionCertificate: {
certificateP12: 'c29tZWJpbmFyeWNvbnRlbnQy',
certificatePassword: 'certPass',
[applicationTarget.targetName]: {
provisioningProfile: 'c29tZWJpbmFyeWNvbnRlbnQ=',
distributionCertificate: {
certificateP12: 'c29tZWJpbmFyeWNvbnRlbnQy',
certificatePassword: 'certPass',
},
},
});
});
it('should throw error when credentials.json is missing', async () => {
const promise = credentialsJsonReader.readIosCredentialsAsync('.');
const promise = credentialsJsonReader.readIosCredentialsAsync(
'.',
findApplicationTarget(testTargets)
);
await expect(promise).rejects.toThrow(
'credentials.json must exist in the project root directory and contain a valid JSON'
'credentials.json does not exist in the project root directory'
);
});
it('should throw error if ios field is missing', async () => {
Expand All @@ -126,8 +132,11 @@ describe('credentialsJson', () => {
'./pprofile': 'somebinarycontent',
'./cert.p12': 'somebinarycontent2',
});
const promise = credentialsJsonReader.readIosCredentialsAsync('.');
await expect(promise).rejects.toThrow('iOS credentials are missing from credentials.json');
const promise = credentialsJsonReader.readIosCredentialsAsync(
'.',
findApplicationTarget(testTargets)
);
await expect(promise).rejects.toThrow('iOS credentials are missing in credentials.json');
});
it('should throw error if some field is missing', async () => {
vol.fromJSON({
Expand All @@ -142,7 +151,10 @@ describe('credentialsJson', () => {
'./pprofile': 'somebinarycontent',
'./cert.p12': 'somebinarycontent2',
});
const promise = credentialsJsonReader.readIosCredentialsAsync('.');
const promise = credentialsJsonReader.readIosCredentialsAsync(
'.',
findApplicationTarget(testTargets)
);
await expect(promise).rejects.toThrow(
'credentials.json is not valid [ValidationError: "ios" does not match any of the allowed types]'
);
Expand All @@ -160,7 +172,10 @@ describe('credentialsJson', () => {
}),
'./pprofile': 'somebinarycontent',
});
const promise = credentialsJsonReader.readIosCredentialsAsync('.');
const promise = credentialsJsonReader.readIosCredentialsAsync(
'.',
findApplicationTarget(testTargets)
);
await expect(promise).rejects.toThrow("ENOENT: no such file or directory, open 'cert.p12'");
});
it('should throw error if provisioningProfile file is missing', async () => {
Expand All @@ -176,7 +191,10 @@ describe('credentialsJson', () => {
}),
'./cert.p12': 'somebinarycontent2',
});
const promise = credentialsJsonReader.readIosCredentialsAsync('.');
const promise = credentialsJsonReader.readIosCredentialsAsync(
'.',
findApplicationTarget(testTargets)
);
await expect(promise).rejects.toThrow("ENOENT: no such file or directory, open 'pprofile'");
});
});
Expand Down Expand Up @@ -206,7 +224,10 @@ describe('credentialsJson', () => {
'./dist-cert-1.p12': 'cert-1-somebinarycontent',
'./dist-cert-2.p12': 'cert-2-somebinarycontent',
});
const result = await credentialsJsonReader.readIosCredentialsAsync('.');
const result = await credentialsJsonReader.readIosCredentialsAsync(
'.',
findApplicationTarget(testTargets)
);
expect(result).toEqual({
target1: {
provisioningProfile: 'cHByb2ZpbGUtMS1zb21lYmluYXJ5Y29udGVudA==',
Expand Down
Loading

0 comments on commit 2d2dd5b

Please sign in to comment.