Skip to content
Open
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
18 changes: 16 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,22 @@ fi

# KICS appends the extension itself, so a trailing .json would only confuse the file lookup
INPUT_OUTPUT_NAME="${INPUT_OUTPUT_NAME%.json}"
[[ ! -z "$INPUT_OUTPUT_NAME" ]] && set -- "$@" --output-name "$INPUT_OUTPUT_NAME"
cd "$GITHUB_WORKSPACE"
if [ -n "$INPUT_OUTPUT_NAME" ]; then
set -- "$@" --output-name "$INPUT_OUTPUT_NAME"
elif [ -n "$INPUT_CONFIG_PATH" ]; then
# KICS still reads the config itself and reports any config errors.
INPUT_OUTPUT_NAME=$(node -e '
const { readFileSync } = require("node:fs");
try {
const name = JSON.parse(readFileSync(process.argv[1], "utf8"))?.["output-name"];
if (typeof name === "string" && !/[\/\\\r\n\0]/.test(name)) {
process.stdout.write(name.replace(/\.json$/, ""));
}
} catch {}
' -- "$INPUT_CONFIG_PATH")
fi
export INPUT_OUTPUT_NAME

CP_PATH="./${INPUT_OUTPUT_NAME:-results}.json"
if [ ! -z "$INPUT_OUTPUT_PATH" ]; then
Expand All @@ -81,7 +96,6 @@ fi
####################
# Run KICS Scan #
####################
cd "$GITHUB_WORKSPACE"
echo "${DATETIME} - INF : about to scan directory $INPUT_PATH"
echo "${DATETIME} - INF : kics command kics -p $INPUT_PATH $OUTPUT_FORMATS_PARAM $PLATFORM_TYPE_PARAM $EXCLUDE_CATEGORIES_PARAM $EXCLUDE_RESULTS_PARAM $EXCLUDE_SEVERITIES_PARAM $EXCLUDE_QUERIES_PARAM $EXCLUDE_GITIGNORE $VERBOSE_PARAM $IGNORE_ON_EXIT_PARAM $FAIL_ON_PARAM $TIMEOUT_PARAM $PROFILING_PARAM $BOM_PARAM $INCLUDE_QUERIES_PARAM $DISABLE_SECRETS_PARAM $DISABLE_FULL_DESCRIPTIONS_PARAM $CLOUD_PROVIDER $*"
/app/bin/kics scan --no-progress -p "$INPUT_PATH" $OUTPUT_FORMATS_PARAM $PLATFORM_TYPE_PARAM $EXCLUDE_CATEGORIES_PARAM $EXCLUDE_RESULTS_PARAM $EXCLUDE_SEVERITIES_PARAM $EXCLUDE_QUERIES_PARAM $EXCLUDE_GITIGNORE $VERBOSE_PARAM $IGNORE_ON_EXIT_PARAM $FAIL_ON_PARAM $TIMEOUT_PARAM $PROFILING_PARAM $BOM_PARAM $INCLUDE_QUERIES_PARAM $DISABLE_SECRETS_PARAM $DISABLE_FULL_DESCRIPTIONS_PARAM $CLOUD_PROVIDER "$@"
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/entrypoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const path = require('node:path')
const { runEntrypoint, flagValue } = require('../helpers/run-entrypoint')
const { startFakeGitHub } = require('../helpers/fake-github')
const { kicsResults } = require('../helpers/fixtures')
const { knownBug } = require('../helpers/known-bug')

const DEFAULT_QUERIES = '/app/bin/assets/queries'

Expand Down Expand Up @@ -248,13 +247,13 @@ test('whole action: entrypoint, KICS, JavaScript stage and GitHub', async (t) =>
assert.equal(fs.existsSync(path.join(run.workspace, 'results.json')), true)
})

await t.test('reports from a config file with a custom output-name are still picked up', knownBug('main.js only reads results.json, so a config with output-name makes the scan fail with ENOENT (#96, #106)'), async (t) => {
await t.test('reports from a config file with a custom output-name are still picked up', async (t) => {
const run = await runEntrypoint(t, {
runMain: true,
results: kicsResults(),
resultsName: 'my-results',
workspaceFiles: { 'kics.json': JSON.stringify({ 'output-name': 'my-results' }) },
inputs: { config_path: 'kics.json', enable_jobs_summary: 'true' },
inputs: { config_path: 'kics.json', output_path: 'reports', enable_jobs_summary: 'true' },
})
assert.match(run.summary, /\| TOTAL \| 4 \|/, run.stdout + run.stderr)
})
Expand Down
1 change: 1 addition & 0 deletions test/helpers/run-entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ exit "\${FAKE_KICS_EXIT:-0}"
`

const NODE_SHIM = `#!/bin/bash
if [ "$1" = "-e" ]; then exec "$REAL_NODE" "$@"; fi
{ echo "cwd=$(pwd)"; echo "args=$*"; echo "KICS_EXIT_CODE=$KICS_EXIT_CODE"; } > "$SANDBOX/node-call.txt"
if [ -n "$RUN_MAIN" ]; then exec "$REAL_NODE" "$MAIN_JS"; fi
`
Expand Down