AddTo will return AddToTypeProxy for convenience
Change-Id: If86496af0c68af31a3e0c618b0fae861975a4ebf
Reviewed-on: https://weave-review.googlesource.com/2321
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/src/privet/auth_manager.cc b/src/privet/auth_manager.cc
index 0753a2b..66d04c4 100644
--- a/src/privet/auth_manager.cc
+++ b/src/privet/auth_manager.cc
@@ -65,14 +65,13 @@
ErrorPtr* error) {
UwMacaroonCaveatType caveat_type{};
if (!uw_macaroon_caveat_get_type_(&caveat, &caveat_type)) {
- Error::AddTo(error, FROM_HERE, kInvalidTokenError, "Unable to get type");
- return false;
+ return Error::AddTo(error, FROM_HERE, kInvalidTokenError,
+ "Unable to get type");
}
if (caveat_type != type) {
- Error::AddTo(error, FROM_HERE, kInvalidTokenError,
- "Unexpected caveat type");
- return false;
+ return Error::AddTo(error, FROM_HERE, kInvalidTokenError,
+ "Unexpected caveat type");
}
return true;
@@ -86,8 +85,8 @@
return false;
if (!uw_macaroon_caveat_get_value_uint_(&caveat, value)) {
- Error::AddTo(error, FROM_HERE, kInvalidTokenError, "Unable to read caveat");
- return false;
+ return Error::AddTo(error, FROM_HERE, kInvalidTokenError,
+ "Unable to read caveat");
}
return true;
@@ -103,8 +102,8 @@
const uint8_t* start{nullptr};
size_t size{0};
if (!uw_macaroon_caveat_get_value_str_(&caveat, &start, &size)) {
- Error::AddTo(error, FROM_HERE, kInvalidTokenError, "Unable to read caveat");
- return false;
+ return Error::AddTo(error, FROM_HERE, kInvalidTokenError,
+ "Unable to read caveat");
}
value->assign(reinterpret_cast<const char*>(start), size);
@@ -144,8 +143,8 @@
buffer->resize(kMaxMacaroonSize);
if (!uw_macaroon_load_(token.data(), token.size(), buffer->data(),
buffer->size(), macaroon)) {
- Error::AddTo(error, FROM_HERE, kInvalidTokenError, "Invalid token format");
- return false;
+ return Error::AddTo(error, FROM_HERE, kInvalidTokenError,
+ "Invalid token format");
}
return true;
}
@@ -155,9 +154,8 @@
ErrorPtr* error) {
CHECK_EQ(kSha256OutputSize, secret.size());
if (!uw_macaroon_verify_(&macaroon, secret.data(), secret.size())) {
- Error::AddTo(error, FROM_HERE, "invalid_signature",
- "Invalid token signature");
- return false;
+ return Error::AddTo(error, FROM_HERE, "invalid_signature",
+ "Invalid token signature");
}
return true;
}
@@ -271,23 +269,20 @@
&user_id, error) ||
!ReadCaveat(macaroon.caveats[2], kUwMacaroonCaveatTypeExpiration,
&expiration, error)) {
- Error::AddTo(error, FROM_HERE, errors::kInvalidAuthorization,
- "Invalid token");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidAuthorization,
+ "Invalid token");
}
AuthScope auth_scope{FromMacaroonScope(scope)};
if (auth_scope == AuthScope::kNone) {
- Error::AddTo(error, FROM_HERE, errors::kInvalidAuthorization,
- "Invalid token data");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidAuthorization,
+ "Invalid token data");
}
base::Time time{base::Time::FromTimeT(expiration)};
if (time < clock_->Now()) {
- Error::AddTo(error, FROM_HERE, errors::kAuthorizationExpired,
- "Token is expired");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kAuthorizationExpired,
+ "Token is expired");
}
if (user_info)
@@ -329,8 +324,7 @@
return auth.first->IsValidAuthToken(token, nullptr);
});
if (claim == pending_claims_.end()) {
- Error::AddTo(error, FROM_HERE, errors::kNotFound, "Unknown claim");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kNotFound, "Unknown claim");
}
SetAuthSecret(claim->first->GetAuthSecret(), claim->second);
@@ -358,8 +352,8 @@
UwMacaroon macaroon{};
if (!LoadMacaroon(token, &buffer, &macaroon, error) ||
!VerifyMacaroon(auth_secret_, macaroon, error)) {
- Error::AddTo(error, FROM_HERE, errors::kInvalidAuthCode, "Invalid token");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidAuthCode,
+ "Invalid token");
}
return true;
}
diff --git a/src/privet/cloud_delegate.cc b/src/privet/cloud_delegate.cc
index 0eb04e0..5f31fee 100644
--- a/src/privet/cloud_delegate.cc
+++ b/src/privet/cloud_delegate.cc
@@ -320,9 +320,8 @@
return true;
}
- Error::AddTo(error, FROM_HERE, errors::kAccessDenied,
- "Need to be owner of the command.");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kAccessDenied,
+ "Need to be owner of the command.");
}
provider::TaskRunner* task_runner_{nullptr};
diff --git a/src/privet/privet_handler_unittest.cc b/src/privet/privet_handler_unittest.cc
index a353a0f..fa79e77 100644
--- a/src/privet/privet_handler_unittest.cc
+++ b/src/privet/privet_handler_unittest.cc
@@ -197,11 +197,9 @@
TEST_F(PrivetHandlerTest, ExpiredAuth) {
auth_header_ = "Privet 123";
EXPECT_CALL(security_, ParseAccessToken(_, _, _))
- .WillRepeatedly(DoAll(WithArgs<2>(Invoke([](ErrorPtr* error) {
- Error::AddTo(error, FROM_HERE,
- "authorizationExpired", "");
- })),
- Return(false)));
+ .WillRepeatedly(WithArgs<2>(Invoke([](ErrorPtr* error) {
+ return Error::AddTo(error, FROM_HERE, "authorizationExpired", "");
+ })));
EXPECT_PRED2(IsEqualError, CodeWithReason(403, "authorizationExpired"),
HandleRequest("/privet/info", "{}"));
}
@@ -379,10 +377,10 @@
TEST_F(PrivetHandlerTest, AuthErrorInvalidAuthCode) {
auto set_error = [](ErrorPtr* error) {
- Error::AddTo(error, FROM_HERE, "invalidAuthCode", "");
+ return Error::AddTo(error, FROM_HERE, "invalidAuthCode", "");
};
EXPECT_CALL(security_, CreateAccessToken(_, "testToken", _, _, _, _, _))
- .WillRepeatedly(DoAll(WithArgs<6>(Invoke(set_error)), Return(false)));
+ .WillRepeatedly(WithArgs<6>(Invoke(set_error)));
const char kInput[] = R"({
'mode': 'pairing',
'requestedScope': 'user',
@@ -601,10 +599,9 @@
}
})";
auto set_error = [](const std::string&, const std::string&, ErrorPtr* error) {
- Error::AddTo(error, FROM_HERE, "deviceBusy", "");
+ return Error::AddTo(error, FROM_HERE, "deviceBusy", "");
};
- EXPECT_CALL(wifi_, ConfigureCredentials(_, _, _))
- .WillOnce(DoAll(Invoke(set_error), Return(false)));
+ EXPECT_CALL(wifi_, ConfigureCredentials(_, _, _)).WillOnce(Invoke(set_error));
EXPECT_PRED2(IsEqualError, CodeWithReason(503, "deviceBusy"),
HandleRequest("/privet/v3/setup/start", kInput));
@@ -641,10 +638,9 @@
})";
auto set_error = [](const std::string&, const std::string&, ErrorPtr* error) {
- Error::AddTo(error, FROM_HERE, "deviceBusy", "");
+ return Error::AddTo(error, FROM_HERE, "deviceBusy", "");
};
- EXPECT_CALL(cloud_, Setup(_, _, _))
- .WillOnce(DoAll(Invoke(set_error), Return(false)));
+ EXPECT_CALL(cloud_, Setup(_, _, _)).WillOnce(Invoke(set_error));
EXPECT_PRED2(IsEqualError, CodeWithReason(503, "deviceBusy"),
HandleRequest("/privet/v3/setup/start", kInput));
@@ -857,8 +853,7 @@
"{'path':'comp1.comp2', 'filter':['traits', 'components']}"));
auto error_handler = [](ErrorPtr* error) -> const base::DictionaryValue* {
- Error::AddTo(error, FROM_HERE, "componentNotFound", "");
- return nullptr;
+ return Error::AddTo(error, FROM_HERE, "componentNotFound", "");
};
EXPECT_CALL(cloud_, FindComponent("comp7", _))
.WillOnce(WithArgs<1>(Invoke(error_handler)));
diff --git a/src/privet/security_manager.cc b/src/privet/security_manager.cc
index 7a3533a..358876d 100644
--- a/src/privet/security_manager.cc
+++ b/src/privet/security_manager.cc
@@ -51,9 +51,8 @@
case crypto::P224EncryptedKeyExchange::kResultPending:
return true;
case crypto::P224EncryptedKeyExchange::kResultFailed:
- Error::AddTo(error, FROM_HERE, errors::kInvalidClientCommitment,
- spake_.error());
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidClientCommitment,
+ spake_.error());
default:
LOG(FATAL) << "SecurityManager uses only one round trip";
}
@@ -139,9 +138,8 @@
base::TimeDelta* access_token_ttl,
ErrorPtr* error) {
auto disabled_mode = [](ErrorPtr* error) {
- Error::AddTo(error, FROM_HERE, errors::kInvalidAuthMode,
- "Mode is not available");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidAuthMode,
+ "Mode is not available");
};
switch (auth_type) {
@@ -154,9 +152,8 @@
if (!IsPairingAuthSupported())
return disabled_mode(error);
if (!IsValidPairingCode(auth_code)) {
- Error::AddTo(error, FROM_HERE, errors::kInvalidAuthCode,
- "Invalid authCode");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidAuthCode,
+ "Invalid authCode");
}
return CreateAccessTokenImpl(auth_type, desired_scope, access_token,
access_token_scope, access_token_ttl);
@@ -170,9 +167,8 @@
error);
}
- Error::AddTo(error, FROM_HERE, errors::kInvalidAuthMode,
- "Unsupported auth mode");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidAuthMode,
+ "Unsupported auth mode");
}
bool SecurityManager::CreateAccessToken(AuthType auth_type,
@@ -290,9 +286,8 @@
const auto& pairing_modes = GetSettings().pairing_modes;
if (std::find(pairing_modes.begin(), pairing_modes.end(), mode) ==
pairing_modes.end()) {
- Error::AddTo(error, FROM_HERE, errors::kInvalidParams,
- "Pairing mode is not enabled");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidParams,
+ "Pairing mode is not enabled");
}
std::string code;
@@ -305,9 +300,8 @@
code = base::StringPrintf("%04i", base::RandInt(0, 9999));
break;
default:
- Error::AddTo(error, FROM_HERE, errors::kInvalidParams,
- "Unsupported pairing mode");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidParams,
+ "Unsupported pairing mode");
}
std::unique_ptr<KeyExchanger> spake;
@@ -322,9 +316,8 @@
}
// Fall through...
default:
- Error::AddTo(error, FROM_HERE, errors::kInvalidParams,
- "Unsupported crypto");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kInvalidParams,
+ "Unsupported crypto");
}
// Allow only a single session at a time for now.
@@ -382,9 +375,8 @@
if (!session->second->ProcessMessage(
std::string(commitment.begin(), commitment.end()), error)) {
ClosePendingSession(session_id);
- Error::AddTo(error, FROM_HERE, errors::kCommitmentMismatch,
- "Pairing code or crypto implementation mismatch");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kCommitmentMismatch,
+ "Pairing code or crypto implementation mismatch");
}
const std::string& key = session->second->GetKey();
@@ -440,9 +432,8 @@
return true;
if (block_pairing_until_ > auth_manager_->Now()) {
- Error::AddTo(error, FROM_HERE, errors::kDeviceBusy,
- "Too many pairing attempts");
- return false;
+ return Error::AddTo(error, FROM_HERE, errors::kDeviceBusy,
+ "Too many pairing attempts");
}
if (++pairing_attemts_ >= kMaxAllowedPairingAttemts) {