프로젝트 소개
요청
Marshlight Parcel 회사에는 서로 관련된 서비스 기능 여섯 개의 검토가 필요합니다. 릴리스 책임자는 다음 검토자가 결과를 재현할 수 있도록 통제를 한데 모아 두기를 원합니다.
데이터
모든 회사, 증빙 식별자, 검토 결과는 가상입니다. 기본 픽스처와 새 픽스처에는 서로 다른 의존성, 네트워크, 정책 레코드가 들어 있습니다. 어떤 요청도 실제 호스트에 도달하지 않습니다.
완료
이어받은 소스 파일에 앞서 한 수정을 모두 유지하세요. 완성한 각 기능은 저장된 악용 요청을 거부하고 지원되는 두 요청을 유지해야 합니다. 최종 소스 파일이 결과물입니다. 여섯 개의 기능 경로가 두 픽스처에서 모두 함께 통과해야 합니다.
Marshlight Parcel 회사가 다음 출시 전에 작은 서비스 하나를 검토해 달라고 요청했습니다. 여섯 단계에 걸쳐 파일 하나에서 작업합니다. 단계마다 다른 기능에 통제를 하나씩 추가하며, 확인을 누를 때마다 이미 고친 모든 경계를 다시 실행합니다. 나중에 수정하면서 앞의 통제를 제거하면 실패합니다.
코드를 바꾸기 전에 의뢰 내용과 현재 기능의 요구 사항을 읽으세요. 일반 요청도 합격 기준에 포함됩니다. 이 픽스처는 시드 데이터와 가상 네트워크만 사용하며, 명시된 제한은 처음부터 끝까지 그대로 적용됩니다. 정상 업무를 지원하고 문서화된 악용을 하나하나 거부하는 서비스로 마무리하세요.
function feature0(request, env) {
const url = String(request.body.url || '');
let parsed;
try { parsed = new URL(url); }
catch { return env.reply(400, { error: 'invalid address' }); }
if (parsed.origin !== "https://images-221.example.test") return env.reply(403, { error: 'policy refused' });
if (!env.seed.allowed.some(approved => new URL(approved).pathname === parsed.pathname) || parsed.search !== "" || parsed.hash !== "" || parsed.username !== "" || parsed.password !== "") return env.reply(403, { error: 'policy refused' });
const response = env.fetchUrl(parsed.href);
return env.reply(response.status, { ok: true, preview: response.body });
}
function feature1(request, env) {
const document = request.body;
return env.reply(200, { ok: true, title: String(document.title) });
}
function feature2(request, env) {
const component = env.db.find("packages", row => row.id === request.body.id);
if (!component) return env.reply(404, { error: "component missing" });
return env.reply(200, { ok: true, id: component.id, revision: component.revision });
}
function feature3(request, env) {
const artifact = env.db.find("artifacts", row => row.id === request.body.id);
if (!artifact) return env.reply(404, { error: "artifact missing" });
return env.reply(200, { ok: true, id: artifact.id, subject: artifact.subject });
}
function feature4(request, env) {
const value = request.body;
return env.reply(200, { ok: true, note: { text: String(value.text) } });
}
function feature5(request, env) {
const order = env.db.find("orders", row => row.id === request.body.id);
if (!order) return env.reply(404, { error: "order missing" });
const amount = request.body.amount;
return env.reply(200, { ok: true, id: order.id, refund: amount, remaining: order.balance - amount });
}
function handle(request, env) {
const input = request.body || {};
const feature = input.feature;
const body = Object.assign({}, input);
delete body.feature;
const localRequest = Object.assign({}, request, { body });
const localEnv = Object.assign({}, env, { seed: env.seed.routes[feature] });
if (feature === 'feature-0') return feature0(localRequest, localEnv);
if (feature === 'feature-1') return feature1(localRequest, localEnv);
if (feature === 'feature-2') return feature2(localRequest, localEnv);
if (feature === 'feature-3') return feature3(localRequest, localEnv);
if (feature === 'feature-4') return feature4(localRequest, localEnv);
if (feature === 'feature-5') return feature5(localRequest, localEnv);
return env.reply(404, { error: 'feature missing' });
}
수정된 핸들러를 읽은 뒤, 같은 원리를 각 연습 문제에 적용하세요.