Update AccessBlackListManager interface
Added callback into Unblock method as this method also will save data.
Added IsBlocked method.
Added short explanation of how rules will work.
BUG:25777658
BUG:25776798
Change-Id: I69b4575be261a0d54435bf07d95e6ac11290a1c7
Reviewed-on: https://weave-review.googlesource.com/2275
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/src/access_api_handler.cc b/src/access_api_handler.cc
index e03a548..9fa6df2 100644
--- a/src/access_api_handler.cc
+++ b/src/access_api_handler.cc
@@ -178,13 +178,9 @@
return;
}
- if (!manager_->Unblock(user_id, app_id, &error)) {
- command->Abort(error.get(), nullptr);
- return;
- }
-
- UpdateState();
- command->Complete({}, nullptr);
+ manager_->Unblock(user_id, app_id,
+ base::Bind(&AccessApiHandler::OnCommandDone,
+ weak_ptr_factory_.GetWeakPtr(), cmd));
}
void AccessApiHandler::List(const std::weak_ptr<Command>& cmd) {
diff --git a/src/access_api_handler_unittest.cc b/src/access_api_handler_unittest.cc
index 44c83e2..a142735 100644
--- a/src/access_api_handler_unittest.cc
+++ b/src/access_api_handler_unittest.cc
@@ -29,9 +29,12 @@
const base::Time&,
const DoneCallback&));
MOCK_METHOD3(Unblock,
- bool(const std::vector<uint8_t>&,
+ void(const std::vector<uint8_t>&,
const std::vector<uint8_t>&,
- ErrorPtr*));
+ const DoneCallback&));
+ MOCK_CONST_METHOD2(IsBlocked,
+ bool(const std::vector<uint8_t>&,
+ const std::vector<uint8_t>&));
MOCK_CONST_METHOD0(GetEntries, std::vector<Entry>());
MOCK_CONST_METHOD0(GetSize, size_t());
MOCK_CONST_METHOD0(GetCapacity, size_t());
@@ -203,7 +206,8 @@
TEST_F(AccessApiHandlerTest, Unblock) {
EXPECT_CALL(access_manager_, Unblock(std::vector<uint8_t>{1, 2, 3},
std::vector<uint8_t>{3, 4, 5}, _))
- .WillOnce(Return(true));
+ .WillOnce(WithArgs<2>(
+ Invoke([](const DoneCallback& callback) { callback.Run(nullptr); })));
EXPECT_CALL(access_manager_, GetSize()).WillRepeatedly(Return(4));
AddCommand(R"({
diff --git a/src/access_black_list_manager.h b/src/access_black_list_manager.h
index ed30839..b56226a 100644
--- a/src/access_black_list_manager.h
+++ b/src/access_black_list_manager.h
@@ -14,8 +14,14 @@
class AccessBlackListManager {
public:
struct Entry {
+ // user_id is empty, app_id is empty: block everything.
+ // user_id is not empty, app_id is empty: block if user_id matches.
+ // user_id is empty, app_id is not empty: block if app_id matches.
+ // user_id is not empty, app_id is not empty: block if both match.
std::vector<uint8_t> user_id;
std::vector<uint8_t> app_id;
+
+ // Time after which to discard the rule.
base::Time expiration;
};
virtual ~AccessBlackListManager() = default;
@@ -24,14 +30,27 @@
const std::vector<uint8_t>& app_id,
const base::Time& expiration,
const DoneCallback& callback) = 0;
- virtual bool Unblock(const std::vector<uint8_t>& user_id,
+ virtual void Unblock(const std::vector<uint8_t>& user_id,
const std::vector<uint8_t>& app_id,
- ErrorPtr* error) = 0;
+ const DoneCallback& callback) = 0;
+ virtual bool IsBlocked(const std::vector<uint8_t>& user_id,
+ const std::vector<uint8_t>& app_id) const = 0;
virtual std::vector<Entry> GetEntries() const = 0;
virtual size_t GetSize() const = 0;
virtual size_t GetCapacity() const = 0;
};
+inline bool operator==(const AccessBlackListManager::Entry& l,
+ const AccessBlackListManager::Entry& r) {
+ return l.user_id == r.user_id && l.app_id == r.app_id &&
+ l.expiration == r.expiration;
+}
+
+inline bool operator!=(const AccessBlackListManager::Entry& l,
+ const AccessBlackListManager::Entry& r) {
+ return !(l == r);
+}
+
} // namespace weave
#endif // LIBWEAVE_SRC_ACCESS_BLACK_LIST_H_