File size: 1,027 Bytes
c7d34c1
 
 
b1cfe1b
c7d34c1
 
 
 
 
 
 
 
 
 
 
b1cfe1b
 
 
 
c7d34c1
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { assertArtifactFilepathAllowed } from './agent-file-utils';
import assert from 'node:assert/strict';
import path from 'node:path';
import { describe, it } from 'node:test';

describe('assertArtifactFilepathAllowed', () => {
    it('accepts artifact files under the generated image directory', () => {
        assert.doesNotThrow(() => assertArtifactFilepathAllowed(path.resolve('generated-images', 'image.png')));
    });

    it('rejects artifact file paths outside the generated image directory', () => {
        assert.throws(() => assertArtifactFilepathAllowed(path.resolve('outside-file.png')), /目录之外/);
    });

    it('rejects path traversal attempts under the generated image directory', () => {
        assert.throws(
            () => assertArtifactFilepathAllowed(path.join('generated-images', '..', '..', 'outside-file.png')),
            /目录之外/
        );
        assert.throws(() => assertArtifactFilepathAllowed('generated-images/../../../outside-file.png'), /目录之外/);
    });
});