-
Notifications
You must be signed in to change notification settings - Fork 189
Evolve credentials command to accept profile input and to output keystore json #3511
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
Open
henriquevcosta
wants to merge
3
commits into
expo:main
Choose a base branch
from
henriquevcosta:add-profile-name-to-credentials
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
packages/eas-cli/src/__tests__/commands/credentials-test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import Credentials from '../../commands/credentials'; | ||
| import * as AndroidGraphqlClient from '../../credentials/android/api/GraphqlClient'; | ||
| import { getAppLookupParamsFromContextAsync } from '../../credentials/android/actions/BuildCredentialsUtils'; | ||
| import { testJksAndroidKeystoreFragment } from '../../credentials/__tests__/fixtures-android'; | ||
| import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json'; | ||
| import { getMockEasJson, getMockExpoConfig, mockCommandContext, mockTestCommand } from './utils'; | ||
|
|
||
| jest.mock('fs'); | ||
| jest.mock('../../credentials/android/api/GraphqlClient'); | ||
| jest.mock('../../credentials/android/actions/BuildCredentialsUtils'); | ||
| jest.mock('../../utils/json'); | ||
|
|
||
| describe(Credentials, () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('--json --non-interactive --platform android', () => { | ||
| const expWithAndroidPackage = { | ||
| ...getMockExpoConfig(), | ||
| android: { package: 'com.eas.test' }, | ||
| }; | ||
|
|
||
| test('outputs keystore info as JSON when credentials exist', async () => { | ||
| const ctx = mockCommandContext(Credentials, { | ||
| easJson: getMockEasJson(), | ||
| exp: expWithAndroidPackage, | ||
| }); | ||
| jest.mocked(getAppLookupParamsFromContextAsync).mockResolvedValue({ | ||
| account: { id: 'account-id', name: 'testuser' } as any, | ||
| projectName: 'testapp', | ||
| androidApplicationIdentifier: 'com.eas.test', | ||
| }); | ||
| jest.mocked(AndroidGraphqlClient.getDefaultAndroidAppBuildCredentialsAsync).mockResolvedValue({ | ||
| id: 'build-creds-id', | ||
| name: 'production', | ||
| isDefault: true, | ||
| isLegacy: false, | ||
| androidKeystore: testJksAndroidKeystoreFragment, | ||
| } as any); | ||
|
|
||
| const cmd = mockTestCommand(Credentials, [ | ||
| '--json', | ||
| '--non-interactive', | ||
| '--platform', | ||
| 'android', | ||
| ], ctx); | ||
| await cmd.run(); | ||
|
|
||
| expect(enableJsonOutput).toHaveBeenCalled(); | ||
| expect(printJsonOnlyOutput).toHaveBeenCalledWith({ | ||
| keystore: { | ||
| id: testJksAndroidKeystoreFragment.id, | ||
| type: testJksAndroidKeystoreFragment.type, | ||
| keyAlias: testJksAndroidKeystoreFragment.keyAlias, | ||
| md5CertificateFingerprint: testJksAndroidKeystoreFragment.md5CertificateFingerprint, | ||
| sha1CertificateFingerprint: testJksAndroidKeystoreFragment.sha1CertificateFingerprint, | ||
| sha256CertificateFingerprint: testJksAndroidKeystoreFragment.sha256CertificateFingerprint, | ||
| createdAt: testJksAndroidKeystoreFragment.createdAt, | ||
| updatedAt: testJksAndroidKeystoreFragment.updatedAt, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| test('outputs keystore null when no credentials exist', async () => { | ||
| const ctx = mockCommandContext(Credentials, { | ||
| easJson: getMockEasJson(), | ||
| exp: expWithAndroidPackage, | ||
| }); | ||
| jest.mocked(getAppLookupParamsFromContextAsync).mockResolvedValue({ | ||
| account: { id: 'account-id', name: 'testuser' } as any, | ||
| projectName: 'testapp', | ||
| androidApplicationIdentifier: 'com.eas.test', | ||
| }); | ||
| jest.mocked(AndroidGraphqlClient.getDefaultAndroidAppBuildCredentialsAsync).mockResolvedValue( | ||
| null | ||
| ); | ||
|
|
||
| const cmd = mockTestCommand(Credentials, [ | ||
| '--json', | ||
| '--non-interactive', | ||
| '--platform', | ||
| 'android', | ||
| ], ctx); | ||
| await cmd.run(); | ||
|
|
||
| expect(enableJsonOutput).toHaveBeenCalled(); | ||
| expect(printJsonOnlyOutput).toHaveBeenCalledWith({ keystore: null }); | ||
| }); | ||
|
|
||
| test('outputs keystore null when build credentials exist but have no keystore', async () => { | ||
| const ctx = mockCommandContext(Credentials, { | ||
| easJson: getMockEasJson(), | ||
| exp: expWithAndroidPackage, | ||
| }); | ||
| jest.mocked(getAppLookupParamsFromContextAsync).mockResolvedValue({ | ||
| account: { id: 'account-id', name: 'testuser' } as any, | ||
| projectName: 'testapp', | ||
| androidApplicationIdentifier: 'com.eas.test', | ||
| }); | ||
| jest.mocked(AndroidGraphqlClient.getDefaultAndroidAppBuildCredentialsAsync).mockResolvedValue({ | ||
| id: 'build-creds-id', | ||
| name: 'production', | ||
| isDefault: true, | ||
| isLegacy: false, | ||
| androidKeystore: null, | ||
| } as any); | ||
|
|
||
| const cmd = mockTestCommand(Credentials, [ | ||
| '--json', | ||
| '--non-interactive', | ||
| '--platform', | ||
| 'android', | ||
| ], ctx); | ||
| await cmd.run(); | ||
|
|
||
| expect(enableJsonOutput).toHaveBeenCalled(); | ||
| expect(printJsonOnlyOutput).toHaveBeenCalledWith({ keystore: null }); | ||
| }); | ||
|
|
||
| test('throws when no project directory', async () => { | ||
| const ctx = mockCommandContext(Credentials, { | ||
| easJson: getMockEasJson(), | ||
| optionalPrivateProjectConfig: null, | ||
| }); | ||
|
|
||
| const cmd = mockTestCommand(Credentials, [ | ||
| '--json', | ||
| '--non-interactive', | ||
| '--platform', | ||
| 'android', | ||
| ], ctx); | ||
|
|
||
| await expect(cmd.run()).rejects.toThrow( | ||
| 'Run this command from a project directory with app.json and eas.json to output Android keystore info as JSON.' | ||
| ); | ||
| expect(printJsonOnlyOutput).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
credentialscommand now usesEasNonInteractiveAndJsonFlags, whose shared flag contract says--jsonimplies--non-interactive, but this branch requires both flags to be explicitly true. In a normal TTY session,eas credentials --platform android --jsonwill skip this JSON path and drop into the interactive manager flow instead of emitting JSON-only output, which breaks script automation unless users add an extra undocumented requirement (--non-interactive).Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm that's a good point! In this case should I just make the tool non-interactive as soon as the
--jsonflag is passed? I don't know what other expectations are there around interactivity that it could break.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codex can you suggest a good way forward?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use Codex here, create an environment for this repo.