first commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
buildRelativeImagePath,
|
||||
isPrivateAddress,
|
||||
resolveImagePath,
|
||||
} from '../src/services/image-storage.service.js';
|
||||
|
||||
test('이미지는 recipe ID 기준 상대 경로로만 저장한다', () => {
|
||||
assert.equal(
|
||||
buildRelativeImagePath('0879bf0f-2b64-49fc-a13f-b11b56031993'),
|
||||
'recipes/0879bf0f-2b64-49fc-a13f-b11b56031993/cover.webp',
|
||||
);
|
||||
assert.throws(() => buildRelativeImagePath('../outside'), /recipe ID/);
|
||||
});
|
||||
|
||||
test('동일한 이미지 상대경로를 Windows와 Linux 파일 경로로 해석한다', () => {
|
||||
const relativePath = 'recipes/recipe-1/cover.webp';
|
||||
|
||||
assert.equal(
|
||||
resolveImagePath('D:\\project\\our_recipe_atlas\\data\\images', relativePath, path.win32),
|
||||
'D:\\project\\our_recipe_atlas\\data\\images\\recipes\\recipe-1\\cover.webp',
|
||||
);
|
||||
assert.equal(
|
||||
resolveImagePath('/mnt/recipe-ssd/our_recipe_atlas/images', relativePath, path.posix),
|
||||
'/mnt/recipe-ssd/our_recipe_atlas/images/recipes/recipe-1/cover.webp',
|
||||
);
|
||||
});
|
||||
|
||||
test('SSRF에 사용될 수 있는 사설 및 loopback 주소를 판별한다', () => {
|
||||
assert.equal(isPrivateAddress('127.0.0.1'), true);
|
||||
assert.equal(isPrivateAddress('192.168.0.250'), true);
|
||||
assert.equal(isPrivateAddress('::1'), true);
|
||||
assert.equal(isPrivateAddress('8.8.8.8'), false);
|
||||
});
|
||||
Reference in New Issue
Block a user