Skip to content

fix: integration silent errors #197

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 3 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DecryptManifestList } from './types' // eslint-disable-line no-unused-v
* 1. The code is not tied to a specific copy of the manifest information
* 2. The tests can be run on a subset of tests for debugging.
*/
export async function buildDecryptFixtures (fixtures: string, vectorFile: string, testName: string, slice: string) {
export async function buildDecryptFixtures (fixtures: string, vectorFile: string, testName?: string, slice?: string) {
const [start = 0, end = 9999] = (slice || '').split(':').map(n => parseInt(n, 10))

const centralDirectory = await Open.file(vectorFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import got from 'got'
* 1. The code is not tied to a specific copy of the manifest information
* 2. The tests can be run on a subset of tests for debugging.
*/
export async function buildEncryptFixtures (fixtures: string, manifestFile: string, keyFile: string, testName: string, slice: string) {
export async function buildEncryptFixtures (fixtures: string, manifestFile: string, keyFile: string, testName?: string, slice?: string) {
const [start = 0, end = 9999] = (slice || '').split(':').map(n => parseInt(n, 10))
const { tests, plaintexts }: EncryptManifestList = await getParsedJSON(manifestFile)
const { keys }: KeyList = await getParsedJSON(keyFile)
Expand Down
24 changes: 14 additions & 10 deletions modules/integration-browser/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ if (!existsSync(fixtures)) {
}

;(async (argv) => {
const { _: [ command ], testName, slice, karma, decryptOracle = '' } = argv
const { _: [ command ], testName, slice, karma } = argv

writeFileSync(`${fixtures}/decrypt_tests.json`, JSON.stringify([]))
writeFileSync(`${fixtures}/encrypt_tests.json`, JSON.stringify([]))
writeFileSync(`${fixtures}/decrypt_oracle.json`, JSON.stringify(decryptOracle))

if (command === 'decrypt') {
const { vectorFile } = argv
const vectorPath = join(__dirname, vectorFile as string)
if (!existsSync(vectorPath)) throw new Error(`No file found at ${vectorPath}`)
// @ts-ignore
await buildDecryptFixtures(fixtures, vectorFile, testName, slice)
// It is not clear how to get yargs/typescript to play nicely with sub commands
const { vectorFile } = argv as unknown as { vectorFile: string}
if (!existsSync(vectorFile)) throw new Error(`No file found at ${vectorFile}`)
await buildDecryptFixtures(fixtures, vectorFile as string, testName, slice)
} else if (command === 'encrypt') {
const { manifestFile, keyFile } = argv
// @ts-ignore
await buildEncryptFixtures(fixtures, manifestFile, keyFile, testName, slice)
// It is not clear how to get yargs/typescript to play nicely with sub commands
const { manifestFile, keyFile, decryptOracle } = argv as unknown as { manifestFile: string, keyFile: string, decryptOracle: string}
writeFileSync(`${fixtures}/decrypt_oracle.json`, JSON.stringify(decryptOracle))

await buildEncryptFixtures(fixtures, manifestFile as string, keyFile as string, testName, slice)
} else {
console.log(`Unknown command ${command}`)
cli.showHelp()
Expand All @@ -101,3 +101,7 @@ if (!existsSync(fixtures)) {
})
}
})(cli.argv)
.catch(err => {
console.log(err)
process.exit(1)
})
10 changes: 6 additions & 4 deletions modules/integration-node/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ const cli = yargs
/* I set the result to 1 so that if I fall through the exit condition is a failure */
let result = 1
if (command === 'decrypt') {
const { vectorFile } = argv
// @ts-ignore
const { vectorFile } = argv as unknown as { vectorFile: string}
result = await integrationDecryptTestVectors(vectorFile, tolerateFailures, testName)
} else if (command === 'encrypt') {
const { manifestFile, keyFile, decryptOracle } = argv
// @ts-ignore
const { manifestFile, keyFile, decryptOracle } = argv as unknown as { manifestFile: string, keyFile: string, decryptOracle: string}
result = await integrationEncryptTestVectors(manifestFile, keyFile, decryptOracle, tolerateFailures, testName)
} else {
console.log(`Unknown command ${command}`)
Expand All @@ -78,3 +76,7 @@ const cli = yargs

if (result) process.exit(result)
})(cli.argv)
.catch(err => {
console.log(err)
process.exit(1)
})