| 291 | const char kToken[] = "admin"; |
| 292 | |
| 293 | ABSL_ATTRIBUTE_NOINLINE |
| 294 | bool NativeCheck(absl::btree_map<std::string, std::string>& attributes, |
| 295 | const absl::flat_hash_set<std::string>& denylists, |
| 296 | const absl::flat_hash_set<std::string>& allowlists) { |
| 297 | auto& ip = attributes["ip"]; |
| 298 | auto& path = attributes["path"]; |
| 299 | auto& token = attributes["token"]; |
| 300 | if (denylists.find(ip) != denylists.end()) { |
| 301 | return false; |
| 302 | } |
| 303 | if (absl::StartsWith(path, "v1")) { |
| 304 | if (token == "v1" || token == "v2" || token == "admin") { |
| 305 | return true; |
| 306 | } |
| 307 | } else if (absl::StartsWith(path, "v2")) { |
| 308 | if (token == "v2" || token == "admin") { |
| 309 | return true; |
| 310 | } |
| 311 | } else if (absl::StartsWith(path, "/admin")) { |
| 312 | if (token == "admin") { |
| 313 | if (allowlists.find(ip) != allowlists.end()) { |
| 314 | return true; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | return false; |
| 319 | } |
| 320 | |
| 321 | void BM_PolicyNative(benchmark::State& state) { |
| 322 | const auto denylists = |