Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Unified Diff: chromeos/network/onc/onc_validator.cc

Issue 13957012: Adding a NetworkProfileHandler used by ManagedNetworkConfigurationHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromeos/network/onc/onc_validator.cc
diff --git a/chromeos/network/onc/onc_validator.cc b/chromeos/network/onc/onc_validator.cc
index 43ccf7dfaaaf3debc44467acd02a9827ba385d17..23af30ab2f95700fc19271525a547b8833f6ce38 100644
--- a/chromeos/network/onc/onc_validator.cc
+++ b/chromeos/network/onc/onc_validator.cc
@@ -92,7 +92,7 @@ scoped_ptr<base::Value> Validator::MapValue(
const base::Value& onc_value,
bool* error) {
if (onc_value.GetType() != signature.onc_type) {
- LOG(ERROR) << ErrorHeader() << "Found value '" << onc_value
+ LOG(ERROR) << MessageHeader() << "Found value '" << onc_value
<< "' of type '" << ValueTypeToString(onc_value.GetType())
<< "', but type '" << ValueTypeToString(signature.onc_type)
<< "' is required.";
@@ -168,8 +168,8 @@ scoped_ptr<base::Value> Validator::MapField(
if (current_field_unknown) {
error_or_warning_found_ = *found_unknown_field = true;
- std::string message = MessageHeader(error_on_unknown_field_)
- + "Field name '" + field_name + "' is unknown.";
+ std::string message = MessageHeader() + "Field name '" + field_name +
+ "' is unknown.";
if (error_on_unknown_field_)
LOG(ERROR) << message;
else
@@ -250,7 +250,7 @@ bool Validator::ValidateRecommendedField(
if (!managed_onc_) {
error_or_warning_found_ = true;
- LOG(WARNING) << WarningHeader() << "Found the field '" << onc::kRecommended
+ LOG(WARNING) << MessageHeader() << "Found the field '" << onc::kRecommended
<< "' in an unmanaged ONC. Removing it.";
return true;
}
@@ -281,9 +281,8 @@ bool Validator::ValidateRecommendedField(
if (found_error) {
error_or_warning_found_ = true;
path_.push_back(onc::kRecommended);
- std::string message = MessageHeader(error_on_wrong_recommended_) +
- "The " + error_cause + " field '" + field_name +
- "' cannot be recommended.";
+ std::string message = MessageHeader() + "The " + error_cause +
+ " field '" + field_name + "' cannot be recommended.";
path_.pop_back();
if (error_on_wrong_recommended_) {
LOG(ERROR) << message;
@@ -330,7 +329,7 @@ bool Validator::FieldExistsAndHasNoValidValue(
std::string valid_values_str =
"[" + JoinStringRange(valid_values, it, ", ") + "]";
path_.push_back(field_name);
- LOG(ERROR) << ErrorHeader() << "Found value '" << actual_value <<
+ LOG(ERROR) << MessageHeader() << "Found value '" << actual_value <<
"', but expected one of the values " << valid_values_str;
path_.pop_back();
return true;
@@ -347,7 +346,7 @@ bool Validator::FieldExistsAndIsNotInRange(const base::DictionaryValue& object,
}
error_or_warning_found_ = true;
path_.push_back(field_name);
- LOG(ERROR) << ErrorHeader() << "Found value '" << actual_value
+ LOG(ERROR) << MessageHeader() << "Found value '" << actual_value
<< "', but expected a value in the range [" << lower_bound
<< ", " << upper_bound << "] (boundaries inclusive)";
path_.pop_back();
@@ -364,7 +363,7 @@ bool Validator::FieldExistsAndIsEmpty(const base::DictionaryValue& object,
error_or_warning_found_ = true;
path_.push_back(field_name);
- LOG(ERROR) << ErrorHeader() << "Found an empty string, but expected a "
+ LOG(ERROR) << MessageHeader() << "Found an empty string, but expected a "
<< "non-empty string.";
path_.pop_back();
return true;
@@ -375,8 +374,12 @@ bool Validator::RequireField(const base::DictionaryValue& dict,
if (dict.HasKey(field_name))
return true;
error_or_warning_found_ = true;
- LOG(ERROR) << ErrorHeader() << "The required field '" << field_name
- << "' is missing.";
+ std::string message = MessageHeader() + "The required field '" + field_name +
+ "' is missing.";
+ if (error_on_missing_field_)
+ LOG(ERROR) << message;
+ else
+ LOG(WARNING) << message;
return false;
}
@@ -386,7 +389,7 @@ bool Validator::CertPatternInDevicePolicy(const std::string& cert_type) {
if (cert_type == certificate::kPattern &&
onc_source_ == ONC_SOURCE_DEVICE_POLICY) {
error_or_warning_found_ = true;
- LOG(ERROR) << ErrorHeader() << "Client certificate patterns are "
+ LOG(ERROR) << MessageHeader() << "Client certificate patterns are "
<< "prohibited in ONC device policies.";
return true;
}
@@ -414,9 +417,9 @@ bool Validator::ValidateToplevelConfiguration(
!result->HasKey(kNetworkConfigurations) &&
!result->HasKey(kCertificates)) {
error_or_warning_found_ = true;
- std::string message = MessageHeader(error_on_missing_field_) +
- "Neither the field '" + kNetworkConfigurations + "' nor '" +
- kCertificates + "is present, but at least one is required.";
+ std::string message = MessageHeader() + "Neither the field '" +
+ kNetworkConfigurations + "' nor '" + kCertificates +
+ "is present, but at least one is required.";
if (error_on_missing_field_)
LOG(ERROR) << message;
else
@@ -459,7 +462,7 @@ bool Validator::ValidateNetworkConfiguration(
type != network_type::kWiFi &&
type != network_type::kEthernet) {
error_or_warning_found_ = true;
- LOG(ERROR) << ErrorHeader() << "Networks of type '"
+ LOG(ERROR) << MessageHeader() << "Networks of type '"
<< type << "' are prohibited in ONC device policies.";
return false;
}
@@ -659,9 +662,9 @@ bool Validator::ValidateCertificatePattern(
!result->HasKey(kIssuerCARef)) {
error_or_warning_found_ = true;
allRequiredExist = false;
- std::string message = MessageHeader(error_on_missing_field_) +
- "None of the fields '" + kSubject + "', '" + kIssuer + "', and '" +
- kIssuerCARef + "' is present, but at least one is required.";
+ std::string message = MessageHeader() + "None of the fields '" + kSubject +
+ "', '" + kIssuer + "', and '" + kIssuerCARef +
+ "' is present, but at least one is required.";
if (error_on_missing_field_)
LOG(ERROR) << message;
else
@@ -751,7 +754,7 @@ bool Validator::ValidateCertificate(
if (onc_source_ == ONC_SOURCE_DEVICE_POLICY &&
(type == kServer || type == kAuthority)) {
error_or_warning_found_ = true;
- LOG(ERROR) << ErrorHeader() << "Server and authority certificates are "
+ LOG(ERROR) << MessageHeader() << "Server and authority certificates are "
<< "prohibited in ONC device policies.";
return false;
}
@@ -772,15 +775,7 @@ bool Validator::ValidateCertificate(
return !error_on_missing_field_ || allRequiredExist;
}
-std::string Validator::WarningHeader() {
- return MessageHeader(false);
-}
-
-std::string Validator::ErrorHeader() {
- return MessageHeader(true);
-}
-
-std::string Validator::MessageHeader(bool is_error) {
+std::string Validator::MessageHeader() {
std::string path = path_.empty() ? "toplevel" : JoinString(path_, ".");
std::string message = "At " + path + ": ";
return message;
« no previous file with comments | « chromeos/network/onc/onc_validator.h ('k') | chromeos/test/data/network/policy/shill_policy_on_unconfigured_wifi1.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698