mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Add e2e tests
This commit is contained in:
parent
fdef99931e
commit
c00abfb054
8 changed files with 555 additions and 0 deletions
67
e2e/aikido-npm.e2e.spec.js
Normal file
67
e2e/aikido-npm.e2e.spec.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import { describe, it, beforeEach, afterEach } from 'node:test';
|
||||
import { strict as assert } from 'node:assert';
|
||||
import { createTempDir, cleanupTempDir, runAikidoCommand, isPackageManagerAvailable } from './test-helpers.js';
|
||||
|
||||
describe('aikido-npm e2e tests', () => {
|
||||
let tempDir;
|
||||
|
||||
beforeEach(async () => {
|
||||
tempDir = await createTempDir();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await cleanupTempDir(tempDir);
|
||||
});
|
||||
|
||||
it('should allow installation of legitimate package (axios)', async () => {
|
||||
// Fail if npm is not available
|
||||
const npmAvailable = await isPackageManagerAvailable('npm');
|
||||
assert.ok(npmAvailable, 'npm is not available - check CI/CD configuration');
|
||||
|
||||
const result = await runAikidoCommand('aikido-npm', ['install', 'axios', '--dry-run'], {
|
||||
cwd: tempDir,
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
// Should succeed (exit code 0) and not show malware warning
|
||||
assert.equal(result.code, 0, `Expected success but got: ${result.stderr}`);
|
||||
assert.ok(!result.stdout.includes('MALWARE'), 'Should not detect axios as malware');
|
||||
assert.ok(!result.stderr.includes('MALWARE'), 'Should not detect axios as malware');
|
||||
});
|
||||
|
||||
it('should block installation of malware package (eslint-js)', async () => {
|
||||
// Fail if npm is not available
|
||||
const npmAvailable = await isPackageManagerAvailable('npm');
|
||||
assert.ok(npmAvailable, 'npm is not available - check CI/CD configuration');
|
||||
|
||||
const result = await runAikidoCommand('aikido-npm', ['install', 'eslint-js'], {
|
||||
cwd: tempDir,
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
// Should fail (non-zero exit code) and show malware warning
|
||||
assert.notEqual(result.code, 0, 'Should fail when trying to install malware');
|
||||
|
||||
// Check that malware was detected
|
||||
const output = result.stdout + result.stderr;
|
||||
assert.ok(
|
||||
output.includes('malware') || output.includes('MALWARE') || output.includes('blocked') || output.includes('dangerous') || output.includes('Malicious changes detected'),
|
||||
`Should detect malware but got: ${output}`
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle npm install with version specifiers', async () => {
|
||||
// Fail if npm is not available
|
||||
const npmAvailable = await isPackageManagerAvailable('npm');
|
||||
assert.ok(npmAvailable, 'npm is not available - check CI/CD configuration');
|
||||
|
||||
const result = await runAikidoCommand('aikido-npm', ['install', 'axios@1.0.0', '--dry-run'], {
|
||||
cwd: tempDir,
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
// Should succeed with version specifier
|
||||
assert.equal(result.code, 0, `Expected success with version specifier but got: ${result.stderr}`);
|
||||
assert.ok(!result.stdout.includes('MALWARE'), 'Should not detect axios with version as malware');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue