-
Notifications
You must be signed in to change notification settings - Fork 1
/
fake_firebase_security_rules.dart
31 lines (28 loc) · 1.08 KB
/
fake_firebase_security_rules.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import 'package:fake_firebase_security_rules/src/method.dart';
import 'package:fake_firebase_security_rules/src/parser.dart';
import 'package:fake_firebase_security_rules/src/path_match.dart';
import 'package:fake_firebase_security_rules/src/service.dart';
import 'package:logger/logger.dart';
class FakeFirebaseSecurityRules {
FakeFirebaseSecurityRules(String securityRules, {Logger? logger})
: logger = logger ?? Logger() {
service = Parser(logger: this.logger)
.parse(securityRules)
.firstWhere((service) => service.name == 'cloud.firestore');
}
late final Service service;
final Logger logger;
/// Evaluates whether an operation is allowed or not. `path` is the full path
/// from root without a starting '/'.
bool isAllowed(String path, Method method,
{Map<String, dynamic> variables = const {}}) {
assert(!path.startsWith('/'));
for (final match in service.pathMatches) {
if (match.isAllowed(path.concretePathSegments, method,
variables: variables, logger: logger)) {
return true;
}
}
return false;
}
}