Firestore · Storage 보안 규칙 · 인덱스 · 보안 규칙 테스트 · 개발 서버 구성 스크립트
This commit is contained in:
@@ -34,6 +34,38 @@ export async function createTestEnvironment() {
|
||||
});
|
||||
}
|
||||
|
||||
function storageAddress() {
|
||||
const value = process.env.FIREBASE_STORAGE_EMULATOR_HOST ?? '127.0.0.1:9199';
|
||||
const separator = value.lastIndexOf(':');
|
||||
|
||||
if (separator < 1) {
|
||||
throw new Error(`Invalid FIREBASE_STORAGE_EMULATOR_HOST: ${value}`);
|
||||
}
|
||||
|
||||
const host = value.slice(0, separator);
|
||||
const port = Number(value.slice(separator + 1));
|
||||
|
||||
if (!Number.isInteger(port)) {
|
||||
throw new Error(`Invalid Storage emulator port: ${value}`);
|
||||
}
|
||||
|
||||
return { host, port };
|
||||
}
|
||||
|
||||
/// Storage 규칙 전용 환경. Firestore 와 나눠 둔 이유는 에뮬레이터가 서로 다른
|
||||
/// 포트에 뜨고, 한쪽만 켠 실행에서도 남은 하나가 돌아야 하기 때문이다.
|
||||
export async function createStorageTestEnvironment() {
|
||||
const rules = readFileSync(new URL('../../storage.rules', import.meta.url), 'utf8');
|
||||
|
||||
return initializeTestEnvironment({
|
||||
projectId,
|
||||
storage: {
|
||||
...storageAddress(),
|
||||
rules,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function seedDocuments(testEnvironment, documents) {
|
||||
await testEnvironment.withSecurityRulesDisabled(async (context) => {
|
||||
const firestore = context.firestore();
|
||||
|
||||
Reference in New Issue
Block a user