패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.6.0

fake_firebase_security_rules

Firebase 보안 규칙용 가짜입니다. fake_cloud_firestore 및 mock_firebase_storage에서 사용됩니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
36만
좋아요
1
Pub 점수
140

패키지 설치

flutter pub add fake_firebase_security_rules

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Firebase 보안 규칙의 동작을 시뮬레이션하는 테스트 유틸리티로, 개발자가 실제 Firebase 백엔드에 연결하지 않고도 Firestore 및 Firebase Storage 상호작용을 테스트할 수 있게 해줍니다. fake_cloud_firestore와 mock_firebase_storage와 함께 작동하도록 설계되어 단위 테스트 및 통합 테스트를 위한 일관된 환경을 제공합니다. 이 패키지는 제어 가능한 로컬 설정에서 실제 규칙 적용을 모방함으로써 개발 중 보안 규칙 논리를 검증하는 데 도움을 줍니다.

사용 사례

  • Firestore 읽기/쓰기 권한 테스트
  • 테스트에서 안전한 저장소 접근 시뮬레이션
  • 실시간 Firebase 없이 규칙 로직 검증하기
  • CI/CD 파이프라인과의 통합
  • 오프라인 테스트 세트 개발

주요 기능

  • 실제 Firebase 보안 규칙의 동작과 일치합니다
  • fake_cloud_firestore 및 mock_firebase_storage와 호환됨
  • 경량이며 통합이 쉬움
  • 모든 주요 플랫폼을 지원합니다
  • 정확한 규칙 평가를 제공합니다

적합한 대상

  • Flutter 개발자가 테스트를 작성합니다
  • 생산 환경에서 Firebase를 사용하는 팀
  • 테스트 주도 개발 워크플로
  • 격리된 테스트가 필요한 CI 환경

고려 사항

  • 생산 사용을 위한 것이 아님
  • 완전한 기능을 위해 보조 패키지가 필요합니다
  • 규칙 문법은 실제 Firebase 규칙과 호환되어야 합니다
  • 시뮬레이션에 국한됨—실제 보안을 강제하지 않음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

fake_firebase_security_rules

pub package Tests

This project simulates Firebase Security Rules. It is meant to be used by Fake Cloud Firestore and Firebase Storage Mocks. Given these request inputs:

  • Firebase security rules such as:
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
  }
}
  • Concrete path, access method, eg an update on /databases/some-db/users/abcd,
  • Variables, eg a Map such as {'request': { 'auth': { 'uid': 'efgh' } } },

the library computes whether the request should be allowed or not.

Usage

import 'package:fake_firebase_security_rules/fake_firebase_security_rules.dart';

// https://firebase.google.com/docs/rules/rules-and-auth#leverage_user_information_in_rules
final authUidDescription = '''
service cloud.firestore {
  match /databases/{database}/documents {
    // Make sure the uid of the requesting user matches name of the user
    // document. The wildcard expression {userId} makes the userId variable
    // available in rules.
    match /users/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
  }
}''';

void main(List<String> args) async {
  final securityRules = FakeFirebaseSecurityRules(authUidDescription);
  final uid = 'a57293b';
  final variables = {
    'request': {
      'auth': {'uid': uid}
    }
  };
  // Prints out `true`.
  print(securityRules.isAllowed(
      'databases/some-database/documents/users/$uid', Method.read,
      variables: variables));
  // Prints out `false`.
  print(securityRules.isAllowed(
      'databases/some-database/documents/users/someone-elses-id', Method.read,
      variables: variables));
  // Prints out `false`.
  print(securityRules.isAllowed(
      'databases/some-database/documents/somewhere-else/someone-doc',
      Method.read,
      variables: variables));
}

See the Unit tests for more advanced examples of usage.

Features

Supports:

  • rules declarations used in Firestore and Firebase Storage.
  • recursive match definitions.
  • exhaustive path matching with path variables and wildcards, eg /users/{userId}/{documents=**}.
  • request.auth object populated with uid, custom claims...
  • standard CEL types and methods, eg bool, int, double, String, Map, List, String.match(regexp), a in list... See cel-dart's supported features for an exhaustive list.

Missing:

  • timestamps.
  • durations.
  • custom functions.
  • resource object.
  • request.resource object.
  • exists(), get() functions.

Implementation details

Differences between Firebase Rules CEL and standard CEL
  • Timestamps. Although not implemented in this project yet, Firebase Rules uses its own Timestamp implementation while CEL uses google.protobuf.Timestamp (spec).
How the project works

FirestoreRules.g4 describes a grammar that parses security rules into Matches. A Match contains a path, made up of segments. Some segments might be variables or wildcards. The expression at the right of allow statements is in Common Expression Language (CEL). CEL is a language used by many security projects. See the CEL specs.

  1. Upon initialization, FakeFirebaseSecurityRules parses security rules into a tree of Matches.
  2. When a request comes in, FakeFirebaseSecurityRules finds the first Match and allow statement that corresponds to the given path and whose CEL expression evaluates to true.
Working on the grammar

The fastest way to get your environment up and running is to create a Codespace on the repository, then pip install antlr4-tools. Once this is done, you can run antlr4-parse to try out the rules against some inputs and antlr4 to regenerate the Parser in lib/src/parser/gen.

cd grammar
# Test the grammar on one file.
antlr4-parse FirestoreRules.g4 rulesDefinition -tree -tokens 9_custom_claims.txt
# Test the grammar on all sample files.
./checkAllDescriptions.sh
Generating the parser

If you modify FirestoreRules.g4, you may want to regenerate the parser:

cd grammar
./regenerateParser.sh

카테고리

의존성

의존성 목록 4 개

소스 저장소

이 패키지를 사용하는 프로젝트