-
Notifications
You must be signed in to change notification settings - Fork 822
feat: support https for mock util plugin #13700
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
04e5d19
feat: allow secure connection for local testing
afnx 37dd61c
chore: lockfile
afnx 10b58a9
Merge branch 'dev-util-mock-pr1' of https://github.com/afnx/amplify-c…
afnx cd7d550
chore: extract api
afnx 596c690
fix: resolve test errors and add a new test
afnx a3f1f24
Merge remote-tracking branch 'upstream/dev' into dev-util-mock-pr1
afnx 0758399
fix: api interfaces
afnx 9788ec2
fix: improvements on https configuration
afnx 15cc8bf
Merge remote-tracking branch 'upstream/dev' into dev-util-mock-pr1
afnx 57fce3b
fix: lint
afnx 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
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
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
36 changes: 36 additions & 0 deletions
36
packages/amplify-util-mock/src/__tests__/get-https-config.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,36 @@ | ||
import { getHttpsConfig } from '../utils/get-https-config'; | ||
|
||
describe('getHttpsConfig', () => { | ||
let context; | ||
|
||
beforeEach(() => { | ||
context = { | ||
input: { | ||
argv: [], | ||
}, | ||
print: { | ||
error: jest.fn(), | ||
}, | ||
}; | ||
}); | ||
|
||
it('returns paths when --https option is followed by key and cert paths', () => { | ||
context.input.argv = ['--https', '/path/to/key', '/path/to/cert']; | ||
|
||
const config = getHttpsConfig(context); | ||
|
||
expect(config).toEqual({ | ||
sslKeyPath: '/path/to/key', | ||
sslCertPath: '/path/to/cert', | ||
}); | ||
}); | ||
|
||
it('returns null and prints error when --https option is not followed by key and cert paths', () => { | ||
context.input.argv = ['--https']; | ||
|
||
const config = getHttpsConfig(context); | ||
|
||
expect(config).toEqual(null); | ||
expect(context.print.error).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export function getHttpsConfig(context): { sslKeyPath: string; sslCertPath: string } | null { | ||
if (!context.input || !context.input.argv) { | ||
return null; | ||
} | ||
|
||
const argv = context.input.argv; | ||
const httpsIndex = argv.indexOf('--https'); | ||
|
||
if (httpsIndex !== -1) { | ||
if (httpsIndex < argv.length - 2) { | ||
const keyPath = argv[httpsIndex + 1]; | ||
const certPath = argv[httpsIndex + 2]; | ||
if (typeof keyPath === 'string' && typeof certPath === 'string') { | ||
return { sslKeyPath: keyPath, sslCertPath: certPath }; | ||
} else { | ||
context.print.error('\nThe provided paths for the SSL key and certificate are not valid.\n'); | ||
context.print.error('Please ensure you have entered the correct paths.\n'); | ||
} | ||
} else { | ||
context.print.error('\nThe --https option must be followed by the path to the SSL key and the path to the SSL certificate.\n'); | ||
context.print.error('Example: amplify mock api --https /path/to/key /path/to/cert\n'); | ||
context.print.error('In order to generate a key and certificate, you can use openssl:\n'); | ||
context.print.error('openssl req -nodes -new -x509 -keyout server.key -out server.cert\n'); | ||
context.print.error('Then, run the command again with the paths to the generated key and certificate.\n'); | ||
} | ||
} | ||
|
||
return null; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.