Files
Aislo/resources/tester/test_54_22_security.py
T
eomsangdonandClaude Opus 5.5 11c75f022a refactor(767-1): 안 쓰는 지면 필터 · 서피스 지움 — 필터 넷(CSF · 격자 최저 · PMF · RANSAC) · 표현 셋(TIN + Taubin 평활 · NURBS · meshfree) · 수치지형도 비교 방식 다섯 · 안 부르는 길 정리
- 필터 = 업체 분류 · 점진 TIN · 둘의 다듬기 판만 · 분석 허용 목록 = Ground 등록부(available_filters) 한 벌
- 표현 = DTM · implicit 만 · 평활 = DTM 만 · config 기본 목록 · PRECOMPUTE · 설정 사전 맞춤(설정 지문 바뀜 — 768 에서 다시 지음)
- 등고선 = 격자 · 굳힌 격자만(삼각망 굽기 · 외곽 맞춤 · implicit RBF 폴백 걷음) · 표본기 · 경로 찾기 tin · nurbs · meshfree 갈래 걷음
- 수치지형도 = 라플라스만(TIN 둘 · TPS · ANUDEM형 · 다중해상도 걷음) · B04 단추 하나
- 안 부르는 길 — B04 JSON 점군 GET · ground-stats GET + TS · B07 옛 계획평면도(라이다) 짓기 · lidar_source · LIDAR_ID · plan_lidar 종류 이름 · SOURCE_FILTER_LABELS · MODEL_METHODS(py) · MESH_* 설정
- 옛 manifest 의 지운 갈래 줄은 DB 로 되살리지 않음 · 옛 csf 행은 미리보기 · 등고선 그대로 열림 · 지운 이름 요청 = 400
- 낡은 글 — Ground · Pipeline 머리 · WF1 「없으면 csf」 · B07 음영 기본 「csf」 → 빈 값 · 등고선 폴백 「csf」 → 404 · B04 3D 보기 처음값 · B05 Schema · B06 Prebuild · 씨닝 설명
- 시험 지움 2 — test_b04_contour_raster · test_b04_contour_equivalence(지운 삼각망 굽기 · 없는 프로젝트를 봐 건너뛰던 것)
- 시험 덜어냄 — test_b04_ground_filters CSF · 격자 최저 네 경우(지운 필터)
- 시험 고침 — 허용 목록 · 형 검사에 걸린 csf · tin · grid_min_z · meshfree · tin_sheet 견본을 ptd · implicit · laplace 로(54_22 · 238_1 · 443 · 342_2 · 346_3 · 351_1 · 442_2 · 271 + helper · 344_1 · 133_1 · 343_2 · 637 · 754_1 · 763_1 깨진 tin → 깨진 implicit · 763_3 · b05 둘 · b06 · sheet_surface TIN(도엽선) 경우 지움) · 이름만 바꿈(273_2 · 343_1 · 343_3 · 624_1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 16:35:12 +09:00

110 lines
4.2 KiB
Python

"""54-22 보안 — H1 구조물 id 경로 넘기 · H2 지면 필터 · 표현 이름 경로 넘기.
못박는 것
- H1: 구조물 저장 `structure_id` 는 안전 이름만(어기면 검사 실패 = 422) · 복사본 맞춤은
규칙 밖 · `base` 밖 폴더를 지우지도 쓰지도 않음.
- H2: `filter_key` · `method` 는 허용 목록만(스키마) · 파일 이름 만드는 곳에서도 한 번 더.
"""
from __future__ import annotations
from pathlib import Path
import pytest
from pydantic import ValidationError
from B05_Profile.B05_Profile_Engine_Skeleton import load_or_build_skeleton
from B05_Profile.B05_Profile_Engine_Solver import _load_dtm_grid, _source_npz_paths
from B05_Profile.B05_Profile_Schema import RouteConfirmRequest, RouteSolveRequest
from B05_Profile.B05_Profile_Structures_Schema import StructureInstance
from common_util.common_util_surface_sampler import build_surface_sampler, check_surface_keys
from M02_MasterTemplete import M02_Item_Snapshot as snap
BAD_IDS = ["../../..", "..", "a/b", "a\\b", "C:/Windows", "/etc", ".hidden", "", "x" * 65]
BAD_KEYS = ["../other/dtm_ptd", "ptd/../../x", "C:/x", "", "PTD", "csf"]
def _structure(structure_id):
return StructureInstance(
structure_id=structure_id, type_id="x", placement="point", chainage_m=1
)
@pytest.mark.parametrize("bad", BAD_IDS)
def test_H1_악성_id_거절(bad):
with pytest.raises(ValidationError):
_structure(bad)
@pytest.mark.parametrize("good", [None, "0c3d99cc5d8f49139c871d662537da42", "abc_1-2", "s1__g1"])
def test_H1_정상_id_통과(good):
assert _structure(good).structure_id == good
def test_H1_safe_folder(tmp_path):
base = tmp_path / "templates" / "structures"
base.mkdir(parents=True)
assert snap.safe_folder(base, "abc123") == base / "abc123"
assert snap.safe_folder(base, "pipe@40.0__gin") == base / "pipe@40.0__gin"
for bad in BAD_IDS[:-1] + [str(tmp_path)]: # 길이는 스키마 몫
assert snap.safe_folder(base, bad) is None
def test_H1_맞춤이_base_밖을_안_건드림(tmp_path, monkeypatch):
root = tmp_path / "proj"
base = snap.structures_dir(root)
base.mkdir(parents=True)
victim = root / "victim" # base / "../../victim"
victim.mkdir()
(victim / "keep.txt").write_text("살아야 함", encoding="utf-8")
item = {"layer": "master", "owner": "", "key": "k"}
monkeypatch.setattr(
snap, "assignments", lambda _root: {"../../victim": item, str(victim): item, "ok1": item}
)
def fake_write(target: Path, *_args):
target.mkdir(parents=True, exist_ok=True)
return {}
monkeypatch.setattr(snap, "write_snapshot", fake_write)
result = snap.sync_snapshots(root)
assert (victim / "keep.txt").is_file()
assert set(result["못만듦"]) == {"../../victim", str(victim)}
assert result["만듦"] == ["ok1"]
assert result["지움"] == []
@pytest.mark.parametrize("bad", BAD_KEYS)
def test_H2_스키마_허용_목록(bad):
body = {"bp": {"x": 0, "y": 0}, "ep": {"x": 1, "y": 1}}
with pytest.raises(ValidationError):
RouteSolveRequest(filter_key=bad, **body)
with pytest.raises(ValidationError):
RouteSolveRequest(filter_key="ptd", method=bad, **body)
with pytest.raises(ValidationError):
RouteConfirmRequest(filter_key=bad)
with pytest.raises(ValidationError):
RouteConfirmRequest(method=bad)
def test_H2_스키마_정상값_통과():
assert RouteConfirmRequest(filter_key="ptd_refine", method="implicit").method == "implicit"
assert RouteConfirmRequest().filter_key is None
@pytest.mark.parametrize("bad", BAD_KEYS)
def test_H2_파일_이름_만드는_곳(bad, tmp_path):
with pytest.raises(ValueError):
check_surface_keys(bad)
with pytest.raises(ValueError):
check_surface_keys("ptd", bad)
with pytest.raises(ValueError):
build_surface_sampler(tmp_path, bad, "dtm", False)
with pytest.raises(ValueError):
_load_dtm_grid(tmp_path, bad, False)
with pytest.raises(ValueError):
_source_npz_paths(tmp_path, "ptd", bad, False)
with pytest.raises(ValueError):
load_or_build_skeleton(tmp_path, bad, "dtm", False)
check_surface_keys("classification", "implicit")