Skip to content
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
79 changes: 79 additions & 0 deletions __tests__/config_parser.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { parseApplicationId } from '../src/config_parser.js';
import fs from 'fs';
import path from 'path';
import os from 'os';

describe('parseApplicationId', () => {
let tmpDir;

beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hawkscan-test-'));
});

afterEach(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});

test('parses applicationId from standard stackhawk.yml', () => {
const configContent = `
app:
applicationId: 3b96390e-4c87-410e-bba3-460c9b2177cf
host: https://localhost:9000
env: Development
`;
fs.writeFileSync(path.join(tmpDir, 'stackhawk.yml'), configContent);
const result = parseApplicationId(tmpDir, ['stackhawk.yml']);
expect(result).toBe('3b96390e-4c87-410e-bba3-460c9b2177cf');
});

test('parses applicationId from first config file in list', () => {
const configContent = `
app:
applicationId: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
host: https://example.com
`;
fs.writeFileSync(path.join(tmpDir, 'custom.yml'), configContent);
const result = parseApplicationId(tmpDir, ['custom.yml']);
expect(result).toBe('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee');
});

test('returns null when config file does not exist', () => {
const result = parseApplicationId(tmpDir, ['nonexistent.yml']);
expect(result).toBeNull();
});

test('returns null when applicationId is missing from config', () => {
const configContent = `
app:
host: https://localhost:9000
`;
fs.writeFileSync(path.join(tmpDir, 'stackhawk.yml'), configContent);
const result = parseApplicationId(tmpDir, ['stackhawk.yml']);
expect(result).toBeNull();
});

test('returns null when app section is missing', () => {
const configContent = `
host: https://localhost:9000
`;
fs.writeFileSync(path.join(tmpDir, 'stackhawk.yml'), configContent);
const result = parseApplicationId(tmpDir, ['stackhawk.yml']);
expect(result).toBeNull();
});

test('tries second config file if first has no applicationId', () => {
const config1 = `
app:
host: https://localhost:9000
`;
const config2 = `
app:
applicationId: 11111111-2222-3333-4444-555555555555
host: https://example.com
`;
fs.writeFileSync(path.join(tmpDir, 'base.yml'), config1);
fs.writeFileSync(path.join(tmpDir, 'override.yml'), config2);
const result = parseApplicationId(tmpDir, ['base.yml', 'override.yml']);
expect(result).toBe('11111111-2222-3333-4444-555555555555');
});
});
4 changes: 4 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ beforeEach(() => {
delete process.env.INPUT_DEBUG;
delete process.env.INPUT_COMMAND;
delete process.env.INPUT_ARGS;
delete process.env.INPUT_COMMITSHACHECK;
});

test('gather minimal inputs', () => {
Expand All @@ -40,6 +41,7 @@ test('gather minimal inputs', () => {
dryRun: 'false',
installCLIOnly : 'false',
codeScanningAlerts: 'false',
commitShaCheck: 'false',
workspace : workspace,
sourceURL : 'https://download.stackhawk.com/hawk/cli',
verbose: 'false',
Expand All @@ -58,6 +60,7 @@ test('gather max inputs', () => {
dryRun: 'true',
codeScanningAlerts: 'true',
installCLIOnly : 'true',
commitShaCheck: 'true',
sourceURL : 'https://download.stackhawk.com/hawk/cli',
verbose: 'false',
debug: 'false'
Expand All @@ -74,6 +77,7 @@ test('gather max inputs', () => {
dryRun: 'true',
codeScanningAlerts: 'true',
installCLIOnly : 'true',
commitShaCheck: 'true',
sourceURL : 'https://download.stackhawk.com/hawk/cli',
verbose: 'false',
debug: 'false'
Expand Down
Loading
Loading