Commit f073cc2e authored by Victor-Gabriel Savu's avatar Victor-Gabriel Savu Committed by Commit Bot

set a default empty policy_test_server.

Set a default empty policy file for policy_test_server. Only
warn when the file is missing.

Bug: chromium:668719
Change-Id: I474587cdf810716d485c3dca1aefb4f513cbbe22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2215050Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Victor-Gabriel Savu <vsavu@google.com>
Cr-Commit-Position: refs/heads/master@{#776640}
parent a8fc5d75
......@@ -68,6 +68,10 @@ bool IsUnsafeCharacter(char c) {
LocalPolicyTestServer::LocalPolicyTestServer()
: LocalPolicyTestServer(base::FilePath()) {
config_file_ = server_data_dir_.GetPath().Append(kPolicyFileName);
if (!PathExists(config_file_)) {
SetEmptyConfig();
}
}
LocalPolicyTestServer::LocalPolicyTestServer(const base::FilePath& config_file)
......@@ -76,6 +80,10 @@ LocalPolicyTestServer::LocalPolicyTestServer(const base::FilePath& config_file)
base::ScopedAllowBlockingForTesting allow_blocking;
CHECK(server_data_dir_.CreateUniqueTempDir());
client_state_file_ = server_data_dir_.GetPath().Append(kClientStateFileName);
if (!config_file_.empty() && !PathExists(config_file_)) {
SetEmptyConfig();
}
}
LocalPolicyTestServer::LocalPolicyTestServer(
......@@ -288,4 +296,10 @@ std::string LocalPolicyTestServer::GetSelector(const std::string& type,
return selector;
}
void LocalPolicyTestServer::SetEmptyConfig() {
if (!SetConfig(base::Value(base::Value::Type::DICTIONARY))) {
LOG(ERROR) << "Failed to write empty config " << config_file_.value();
}
}
} // namespace policy
......@@ -100,6 +100,8 @@ class LocalPolicyTestServer : public net::LocalTestServer {
std::string GetSelector(const std::string& type,
const std::string& entity_id);
void SetEmptyConfig();
base::FilePath config_file_;
base::FilePath policy_key_;
base::FilePath client_state_file_;
......
......@@ -1394,7 +1394,9 @@ class PolicyTestServer(testserver_base.BrokenPipeHandlerMixIn,
policy = {}
if json is None:
logging.error('No JSON module, cannot parse policy information')
else :
elif not os.path.exists(self.policy_path):
logging.warning('Missing policies file %s' % self.policy_path)
else:
try:
policy = json.loads(open(self.policy_path).read(), strict=False)
except IOError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment