Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
[expo-cli] add --skip-credentials-check option
Browse files Browse the repository at this point in the history
We want people to be able to skip checking for remote credentials.
  • Loading branch information
satya164 committed Aug 26, 2020
1 parent ffaf58e commit 48c1198
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('ensureCredentialsAsync', () => {

expect(prompts).toHaveBeenCalledTimes(1);
});
it('should should throw an error when local or remote are not present (non interactive)', async () => {
it('should throw an error when local or remote are not present (non interactive)', async () => {
const provider = createMockCredentialsProvider({
hasRemote: false,
hasLocal: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/expo-cli/src/commands/eas-build/build/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { printBuildResults, printLogsUrls } from './utils/misc';

interface BuildOptions {
platform: BuildCommandPlatform;
skipCredentialsCheck?: boolean; // TODO: noop for now
skipCredentialsCheck?: boolean;
skipProjectConfiguration?: boolean;
wait?: boolean;
profile: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AndroidBuilder implements Builder {
const provider = new AndroidCredentialsProvider(this.ctx.projectDir, {
projectName: this.ctx.projectName,
accountName: this.ctx.accountName,
nonInteractive: this.ctx.nonInteractive,
});
await provider.initAsync();
const credentialsSource = await ensureCredentialsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class iOSBuilder implements Builder {
projectName: this.ctx.projectName,
accountName: this.ctx.accountName,
bundleIdentifier,
nonInteractive: this.ctx.nonInteractive,
skipCredentialsCheck: this.ctx.skipCredentialsCheck,
});
await provider.initAsync();
const credentialsSource = await ensureCredentialsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ export async function ensureCredentialsAsync(
case CredentialsSource.REMOTE:
log(log.chalk.bold(USING_REMOTE_CREDENTIALS_MSG));
return CredentialsSource.REMOTE;
case CredentialsSource.AUTO: {
case CredentialsSource.AUTO:
log('Resolving credentials source (auto mode)');
return await ensureCredentialsAutoAsync(provider, workflow, nonInteractive);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface AndroidCredentials {
interface Options {
projectName: string;
accountName: string;
nonInteractive: boolean;
}

export default class AndroidCredentialsProvider implements CredentialsProvider {
Expand All @@ -29,7 +30,7 @@ export default class AndroidCredentialsProvider implements CredentialsProvider {

public async initAsync() {
await this.ctx.init(this.projectDir, {
nonInteractive: this.ctx.nonInteractive,
nonInteractive: this.options.nonInteractive,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AndroidCredentialsProvider from '../AndroidCredentialsProvider';
const providerOptions = {
projectName: 'slug123',
accountName: 'owner123',
nonInteractive: false,
};

const mockFetchKeystore = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { vol } from 'memfs';

import { CredentialsSource } from '../../../easJson';
import * as route from '../../route';
import iOSCredentialsProvider from '../iOSCredentialsProvider';

const providerOptions = {
projectName: 'slug123',
accountName: 'owner123',
bundleIdentifier: 'example.bundle.identifier',
nonInteractive: false,
skipCredentialsCheck: false,
};

const mockGetDistCert = jest.fn();
Expand Down Expand Up @@ -174,7 +177,9 @@ describe('iOSCredentialsProvider', () => {
}));
const provider = new iOSCredentialsProvider('.', providerOptions);
await provider.initAsync();
await expect(provider.getCredentialsAsync(CredentialsSource.REMOTE)).rejects.toThrowError();
await expect(provider.getCredentialsAsync(CredentialsSource.REMOTE)).rejects.toThrowError(
'Provisioning profile is missing'
);
});
it('should return false if dist cert is missging', async () => {
mockGetProvisioningProfile.mockImplementation(() => ({
Expand All @@ -183,12 +188,32 @@ describe('iOSCredentialsProvider', () => {
}));
const provider = new iOSCredentialsProvider('.', providerOptions);
await provider.initAsync();
await expect(provider.getCredentialsAsync(CredentialsSource.REMOTE)).rejects.toThrowError();
await expect(provider.getCredentialsAsync(CredentialsSource.REMOTE)).rejects.toThrowError(
'Distribution certificate is missing'
);
});
it('should return false if there are no credentials', async () => {
const provider = new iOSCredentialsProvider('.', providerOptions);
await provider.initAsync();
await expect(provider.getCredentialsAsync(CredentialsSource.REMOTE)).rejects.toThrowError();
await expect(provider.getCredentialsAsync(CredentialsSource.REMOTE)).rejects.toThrowError(
'Distribution certificate is missing'
);
});
it('should not run credentials manager if credentials check is skipped', async () => {
const spy = jest.spyOn(route, 'runCredentialsManager').mockImplementation(() => {
throw new Error("Shouldn't be called");
});

const provider = new iOSCredentialsProvider('.', {
...providerOptions,
skipCredentialsCheck: true,
});
await provider.initAsync();
await expect(provider.getCredentialsAsync(CredentialsSource.REMOTE)).rejects.toThrowError(
'Distribution certificate is missing and credentials check was skipped. Run without --skip-credentials-check to set it up.'
);

spy.mockRestore();
});
});
describe('when calling useLocalAsync', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ export interface iOSCredentials {
};
}

interface Options extends AppLookupParams {
nonInteractive: boolean;
skipCredentialsCheck: boolean;
}

export default class iOSCredentialsProvider implements CredentialsProvider {
public readonly platform = 'ios';
private readonly ctx = new Context();
private credentials?: iOSCredentials;

constructor(private projectDir: string, private app: AppLookupParams) {}
constructor(private projectDir: string, private app: Options) {}

public async initAsync() {
await this.ctx.init(this.projectDir, {
nonInteractive: this.ctx.nonInteractive,
nonInteractive: this.app.nonInteractive,
});
}

Expand Down Expand Up @@ -77,14 +82,29 @@ export default class iOSCredentialsProvider implements CredentialsProvider {
return await credentialsJsonReader.readIosCredentialsAsync(this.projectDir);
}
private async getRemoteAsync(): Promise<iOSCredentials> {
await runCredentialsManager(this.ctx, new SetupIosBuildCredentials(this.app));
if (!this.app.skipCredentialsCheck) {
log('Skipping credentials check');
await runCredentialsManager(this.ctx, new SetupIosBuildCredentials(this.app));
}
const distCert = await this.ctx.ios.getDistCert(this.app);
if (!distCert) {
throw new Error('Missing distribution certificate'); // shouldn't happen
if (this.app.skipCredentialsCheck) {
throw new Error(
'Distribution certificate is missing and credentials check was skipped. Run without --skip-credentials-check to set it up.'
);
} else {
throw new Error('Distribution certificate is missing');
}
}
const provisioningProfile = await this.ctx.ios.getProvisioningProfile(this.app);
if (!provisioningProfile) {
throw new Error('Missing provisioning profile'); // shouldn't happen
if (this.app.skipCredentialsCheck) {
throw new Error(
'Provisioning profile is missing and credentials check was skipped. Run without --skip-credentials-check to set it up.'
);
} else {
throw new Error('Provisioning profile is missing');
}
}
return {
provisioningProfile: provisioningProfile.provisioningProfile,
Expand Down

0 comments on commit 48c1198

Please sign in to comment.