Skip to content

Commit

Permalink
Create gentest-validate script to validate test signatures
Browse files Browse the repository at this point in the history
Differential Revision: D51999865

fbshipit-source-id: c4e684bf291469f7422091358e54eeb80a8ec29a
  • Loading branch information
joevilches authored and facebook-github-bot committed Dec 12, 2023
1 parent ccc2bf2 commit 59d66f3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
40 changes: 40 additions & 0 deletions gentest/gentest-validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

import * as fs from 'node:fs/promises';
import {dirname} from 'path';
import {fileURLToPath} from 'url';
import signedsource from 'signedsource';

const yogaDir = dirname(dirname(fileURLToPath(import.meta.url)));
const cppTestDir = `${yogaDir}/tests/generated`;
const jsTestDir = `${yogaDir}/javascript/tests/generated`;
const javaTestDir = `${yogaDir}/java/tests/com/facebook/yoga`;
const testDirs = [cppTestDir, jsTestDir, javaTestDir];

for (const testDir of testDirs) {
const tests = await fs.readdir(testDir);

for (const test of tests) {
const testData = await fs.readFile(`${testDir}/${test}`, 'utf8');
try {
const validSignature = signedsource.verifySignature(testData);
if (!validSignature) {
console.error(`Invalid signature for ${test}`);
process.exitCode = 1;
}
} catch (e) {
// Java test dir does not separate generated tests from non-generated ones
if (testDir != javaTestDir) {
console.error(`${test}: ${e}`);
process.exitCode = 1;
}
}
}
}
3 changes: 2 additions & 1 deletion gentest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.0",
"private": true,
"scripts": {
"gentest": "node --loader=babel-register-esm ./gentest-driver.ts"
"gentest": "node --loader=babel-register-esm ./gentest-driver.ts",
"gentest-validate": "node --loader=babel-register-esm ./gentest-validate.ts"
},
"type": "module",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"tsc": "yarn workspaces run tsc",
"gentest": "yarn workspace gentest run gentest"
"gentest": "yarn workspace gentest run gentest",
"gentest-validate": "yarn workspace gentest run gentest-validate"
},
"workspaces": [
"javascript",
Expand All @@ -16,7 +17,6 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"babel-register-esm": "^1.2.5",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^27.1.7",
Expand Down

0 comments on commit 59d66f3

Please sign in to comment.