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

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

Issue 11469026: Extending ONC validator's logging. Completing toplevel validation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@add_error_handling_to_validator
Patch Set: Rebased. Created 8 years 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
« no previous file with comments | « chromeos/network/onc/onc_validator.cc ('k') | chromeos/test/data/network/managed_ethernet.onc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/onc/onc_validator_unittest.cc
diff --git a/chromeos/network/onc/onc_validator_unittest.cc b/chromeos/network/onc/onc_validator_unittest.cc
index f02e9cf38268aff78f4324b4dbec916e3a5a82d5..5d543fe761050be74159961b4d5399645759f964 100644
--- a/chromeos/network/onc/onc_validator_unittest.cc
+++ b/chromeos/network/onc/onc_validator_unittest.cc
@@ -5,12 +5,14 @@
#include "chromeos/network/onc/onc_validator.h"
#include <string>
+#include <utility>
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chromeos/network/onc/onc_constants.h"
#include "chromeos/network/onc/onc_signature.h"
#include "chromeos/network/onc/onc_test_utils.h"
+#include "chromeos/network/onc/onc_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
@@ -28,25 +30,60 @@ scoped_ptr<Validator> CreateLiberalValidator(bool managed_onc) {
}
} // namespace
+TEST(ONCValidatorValidTest, EmptyUnencryptedConfiguration) {
+ scoped_ptr<Validator> validator(CreateStrictValidator(true));
+ scoped_ptr<const base::DictionaryValue> original(
+ ReadDictionaryFromJson(kEmptyUnencryptedConfiguration));
+
+ Validator::Result result;
+ scoped_ptr<const base::DictionaryValue> repaired(
+ validator->ValidateAndRepairObject(&kToplevelConfigurationSignature,
+ *original, &result));
+ EXPECT_EQ(Validator::VALID, result);
+ EXPECT_TRUE(test_utils::Equals(original.get(), repaired.get()));
+}
+
// This test case is about validating valid ONC objects.
-TEST(ONCValidatorValidTest, ValidPolicyOnc) {
+class ONCValidatorValidTest
+ : public ::testing::TestWithParam<
+ std::pair<std::string, const OncValueSignature*> > {
+ protected:
+ std::string GetFilename() const {
+ return GetParam().first;
+ }
+
+ const OncValueSignature* GetSignature() const {
+ return GetParam().second;
+ }
+};
+
+TEST_P(ONCValidatorValidTest, ValidPolicyOnc) {
scoped_ptr<Validator> validator(CreateStrictValidator(true));
- scoped_ptr<const base::DictionaryValue> network;
- scoped_ptr<base::DictionaryValue> repaired;
-
- network = test_utils::ReadTestDictionary("policy.onc");
- repaired = validator->ValidateAndRepairObject(
- &kNetworkConfigurationSignature,
- *network);
- EXPECT_TRUE(test_utils::Equals(network.get(), repaired.get()));
-
- network = test_utils::ReadTestDictionary("valid.onc");
- repaired = validator->ValidateAndRepairObject(
- &kNetworkConfigurationSignature,
- *network);
- EXPECT_TRUE(test_utils::Equals(network.get(), repaired.get()));
+ scoped_ptr<const base::DictionaryValue> original(
+ test_utils::ReadTestDictionary(GetFilename()));
+
+ Validator::Result result;
+ scoped_ptr<const base::DictionaryValue> repaired(
+ validator->ValidateAndRepairObject(GetSignature(), *original, &result));
+ EXPECT_EQ(Validator::VALID, result);
+ EXPECT_TRUE(test_utils::Equals(original.get(), repaired.get()));
}
+INSTANTIATE_TEST_CASE_P(
+ ONCValidatorValidTest,
+ ONCValidatorValidTest,
+ ::testing::Values(std::make_pair("managed_toplevel.onc",
+ &kToplevelConfigurationSignature),
+ std::make_pair("encrypted.onc",
+ &kToplevelConfigurationSignature),
+ std::make_pair("managed_vpn.onc",
+ &kNetworkConfigurationSignature),
+ std::make_pair("managed_ethernet.onc",
+ &kNetworkConfigurationSignature),
+ // Ignore recommended arrays in unmanaged ONC:
+ std::make_pair("recommended_in_unmanaged.onc",
+ &kNetworkConfigurationSignature)));
+
// Validate invalid ONC objects and check the resulting repaired object. This
// test fixture loads a test json file into |invalid_| containing several test
// objects which can be accessed by their path. The test boolean parameter
@@ -71,11 +108,14 @@ class ONCValidatorInvalidTest : public ::testing::TestWithParam<bool> {
const base::DictionaryValue* object = NULL;
ASSERT_TRUE(invalid_->GetDictionary(path_to_object, &object));
+ Validator::Result result;
scoped_ptr<base::DictionaryValue> actual_repaired =
- validator->ValidateAndRepairObject(signature, *object);
+ validator->ValidateAndRepairObject(signature, *object, &result);
if (GetParam() || path_to_repaired == "") {
+ EXPECT_EQ(Validator::INVALID, result);
EXPECT_EQ(NULL, actual_repaired.get());
} else {
+ EXPECT_EQ(Validator::VALID_WITH_WARNINGS, result);
const base::DictionaryValue* expected_repaired = NULL;
invalid_->GetDictionary(path_to_repaired, &expected_repaired);
EXPECT_TRUE(test_utils::Equals(expected_repaired, actual_repaired.get()));
« no previous file with comments | « chromeos/network/onc/onc_validator.cc ('k') | chromeos/test/data/network/managed_ethernet.onc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698