1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/ash/components/network/onc/onc_normalizer.h"
#include "base/values.h"
#include "chromeos/components/onc/onc_signature.h"
#include "chromeos/components/onc/onc_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ash::onc {
namespace test_utils = ::chromeos::onc::test_utils;
// Validate that StaticIPConfig IPAddress and dependent fields will be removed
// if IPAddressConfigType is not 'Static'.
TEST(ONCNormalizerTest, RemoveUnnecessaryAddressStaticIPConfigFields) {
Normalizer normalizer(true);
base::Value::Dict data =
test_utils::ReadTestDictionary("settings_with_normalization.json");
const base::Value::Dict* original =
data.FindDict("unnecessary-address-staticipconfig");
const base::Value::Dict* expected_normalized =
data.FindDict("unnecessary-address-staticipconfig-normalized");
base::Value::Dict actual_normalized = normalizer.NormalizeObject(
&chromeos::onc::kNetworkConfigurationSignature, *original);
EXPECT_TRUE(test_utils::Equals(expected_normalized, &actual_normalized));
}
// Validate that StaticIPConfig fields other than NameServers and IPAddress &
// friends will be retained even without static
// {NameServers,IPAddress}ConfigType.
TEST(ONCNormalizerTest, RetainExtraStaticIPConfigFields) {
Normalizer normalizer(true);
base::Value::Dict data =
test_utils::ReadTestDictionary("settings_with_normalization.json");
const base::Value::Dict* original =
data.FindDict("unnecessary-address-staticipconfig");
const base::Value::Dict* expected_normalized =
data.FindDict("unnecessary-address-staticipconfig-normalized");
base::Value::Dict actual_normalized = normalizer.NormalizeObject(
&chromeos::onc::kNetworkConfigurationSignature, *original);
EXPECT_TRUE(test_utils::Equals(expected_normalized, &actual_normalized));
}
// Validate that irrelevant fields of the StaticIPConfig dictionary will be
// removed.
TEST(ONCNormalizerTest, RemoveStaticIPConfigFields) {
Normalizer normalizer(true);
base::Value::Dict data =
test_utils::ReadTestDictionary("settings_with_normalization.json");
const base::Value::Dict* original =
data.FindDict("irrelevant-staticipconfig-fields");
const base::Value::Dict* expected_normalized =
data.FindDict("irrelevant-staticipconfig-fields-normalized");
base::Value::Dict actual_normalized = normalizer.NormalizeObject(
&chromeos::onc::kNetworkConfigurationSignature, *original);
EXPECT_TRUE(test_utils::Equals(expected_normalized, &actual_normalized));
}
// Validate that StatticIPConfig.NameServers is removed when
// NameServersConfigType is 'DHCP'.
TEST(ONCNormalizerTest, RemoveNameServers) {
Normalizer normalizer(true);
base::Value::Dict data =
test_utils::ReadTestDictionary("settings_with_normalization.json");
const base::Value::Dict* original = data.FindDict("irrelevant-nameservers");
const base::Value::Dict* expected_normalized =
data.FindDict("irrelevant-nameservers-normalized");
base::Value::Dict actual_normalized = normalizer.NormalizeObject(
&chromeos::onc::kNetworkConfigurationSignature, *original);
EXPECT_TRUE(test_utils::Equals(expected_normalized, &actual_normalized));
}
// Validate that IPConfig related fields are removed when IPAddressConfigType
// is 'Static', but some required fields are missing.
TEST(ONCNormalizerTest, RemoveIPFieldsForIncompleteConfig) {
Normalizer normalizer(true);
base::Value::Dict data =
test_utils::ReadTestDictionary("settings_with_normalization.json");
const base::Value::Dict* original = data.FindDict("missing-ip-fields");
const base::Value::Dict* expected_normalized =
data.FindDict("missing-ip-fields-normalized");
base::Value::Dict actual_normalized = normalizer.NormalizeObject(
&chromeos::onc::kNetworkConfigurationSignature, *original);
EXPECT_TRUE(test_utils::Equals(expected_normalized, &actual_normalized));
}
// This test case is about validating valid ONC objects.
TEST(ONCNormalizerTest, NormalizeNetworkConfigurationEthernetAndVPN) {
Normalizer normalizer(true);
base::Value::Dict data =
test_utils::ReadTestDictionary("settings_with_normalization.json");
const base::Value::Dict* original = data.FindDict("ethernet-and-vpn");
const base::Value::Dict* expected_normalized =
data.FindDict("ethernet-and-vpn-normalized");
base::Value::Dict actual_normalized = normalizer.NormalizeObject(
&chromeos::onc::kNetworkConfigurationSignature, *original);
EXPECT_TRUE(test_utils::Equals(expected_normalized, &actual_normalized));
}
// This test case is about validating valid ONC objects.
TEST(ONCNormalizerTest, NormalizeNetworkConfigurationWifi) {
Normalizer normalizer(true);
base::Value::Dict data =
test_utils::ReadTestDictionary("settings_with_normalization.json");
const base::Value::Dict* original = data.FindDict("wifi");
const base::Value::Dict* expected_normalized =
data.FindDict("wifi-normalized");
base::Value::Dict actual_normalized = normalizer.NormalizeObject(
&chromeos::onc::kNetworkConfigurationSignature, *original);
EXPECT_TRUE(test_utils::Equals(expected_normalized, &actual_normalized));
}
} // namespace ash::onc
|