36 lines
1.8 KiB
JavaScript
36 lines
1.8 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert');
|
|
const { blockedReason, partitionBlocked } = require('../src/features/uploadBlocklist.js');
|
|
|
|
test('Sperre: Dateien mit Zugangsdaten werden erkannt', () => {
|
|
for (const name of ['credentials.json', 'data/credentials.json', 'C:\\proj\\.env', '.env.production', 'id_rsa', 'release.keystore', 'server.pem', 'secrets.json', '.npmrc']) {
|
|
assert.ok(blockedReason(name, {}), `${name} sollte gesperrt sein`);
|
|
}
|
|
});
|
|
|
|
test('Sperre: normale Dateien und Vorlagen bleiben erlaubt', () => {
|
|
for (const name of ['main.js', 'package.json', 'README.md', '.env.example', 'config.sample.json', 'id_rsa.pub', 'credentials.md', 'src/credentials/index.js']) {
|
|
assert.strictEqual(blockedReason(name, {}), null, `${name} darf hochgeladen werden`);
|
|
}
|
|
});
|
|
|
|
test('Sperre: Einstellung kann sie abschalten, Standard ist an', () => {
|
|
assert.ok(blockedReason('credentials.json', undefined));
|
|
assert.ok(blockedReason('credentials.json', { uploadBlockSecrets: true }));
|
|
assert.strictEqual(blockedReason('credentials.json', { uploadBlockSecrets: false }), null);
|
|
});
|
|
|
|
test('partitionBlocked: trennt Einträge und behält die Reihenfolge', () => {
|
|
const items = [
|
|
{ localFile: 'a/main.js', targetPath: 'a/main.js' },
|
|
{ localFile: 'a/data/credentials.json', targetPath: 'a/data/credentials.json' },
|
|
{ localFile: 'a/.env', targetPath: 'a/.env' },
|
|
{ localFile: 'a/README.md', targetPath: 'a/README.md' }
|
|
];
|
|
const { allowed, blocked } = partitionBlocked(items, {});
|
|
assert.deepStrictEqual(allowed.map(i => i.localFile), ['a/main.js', 'a/README.md']);
|
|
assert.deepStrictEqual(blocked.map(b => b.path), ['a/data/credentials.json', 'a/.env']);
|
|
assert.ok(blocked.every(b => b.reason));
|
|
assert.strictEqual(partitionBlocked(items, { uploadBlockSecrets: false }).blocked.length, 0);
|
|
});
|