Status AuthzManagerExternalStateMock::_queryVector( const NamespaceString& collectionName, const BSONObj& query, std::vector<BSONObjCollection::iterator>* result) { StatusWithMatchExpression parseResult = MatchExpressionParser::parse(query); if (!parseResult.isOK()) { return parseResult.getStatus(); } MatchExpression* matcher = parseResult.getValue(); NamespaceDocumentMap::iterator mapIt = _documents.find(collectionName); if (mapIt == _documents.end()) return Status(ErrorCodes::NoMatchingDocument, "No collection named " + collectionName.ns()); for (BSONObjCollection::iterator vecIt = mapIt->second.begin(); vecIt != mapIt->second.end(); ++vecIt) { if (matcher->matchesBSON(*vecIt)) { result->push_back(vecIt); } } return Status::OK(); }
Status AuthzManagerExternalStateMock::_findUser(const std::string& usersNamespace, const BSONObj& query, BSONObj* result) const { StatusWithMatchExpression parseResult = MatchExpressionParser::parse(query); if (!parseResult.isOK()) { return parseResult.getStatus(); } MatchExpression* matcher = parseResult.getValue(); unordered_map<std::string, std::vector<BSONObj> >::const_iterator mapIt; for (mapIt = _userDocuments.begin(); mapIt != _userDocuments.end(); ++mapIt) { for (std::vector<BSONObj>::const_iterator vecIt = mapIt->second.begin(); vecIt != mapIt->second.end(); ++vecIt) { if (nsToDatabase(usersNamespace) == mapIt->first && matcher->matchesBSON(*vecIt)) { *result = *vecIt; return Status::OK(); } } } return Status(ErrorCodes::UserNotFound, "User not found"); }