#include "extensions/common/csp_validator.h"
#include <stddef.h>
#include <string_view>
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/install_warning.h"
#include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
ErrorUtils;
InstallWarning;
Manifest;
ContentSecurityPolicyIsLegal;
ContentSecurityPolicyIsSandboxed;
GetSandboxedPageCSPDisallowingRemoteSources;
OPTIONS_ALLOW_INSECURE_OBJECT_SRC;
OPTIONS_ALLOW_UNSAFE_EVAL;
OPTIONS_NONE;
SanitizeContentSecurityPolicy;
namespace {
std::string InsecureValueWarning(
const std::string& directive,
const std::string& value,
const std::string& manifest_key =
extensions::manifest_keys::kContentSecurityPolicy) { … }
std::string MissingSecureSrcWarning(const std::string& manifest_key,
const std::string& directive) { … }
bool CSPEquals(const std::string& csp1, const std::string& csp2) { … }
struct SanitizedCSPResult { … };
SanitizedCSPResult SanitizeCSP(const std::string& policy, int options) { … }
SanitizedCSPResult SanitizeSandboxPageCSP(const std::string& policy) { … }
testing::AssertionResult CheckCSP(
const SanitizedCSPResult& actual,
const std::string& expected_csp,
const std::vector<std::string>& expected_warnings) { … }
testing::AssertionResult CheckCSP(const SanitizedCSPResult& actual) { … }
testing::AssertionResult CheckCSP(const SanitizedCSPResult& actual,
const std::string& expected_csp) { … }
testing::AssertionResult CheckCSP(const SanitizedCSPResult& actual,
const std::string& expected_csp,
const std::string& warning1) { … }
testing::AssertionResult CheckCSP(const SanitizedCSPResult& actual,
const std::string& expected_csp,
const std::string& warning1,
const std::string& warning2) { … }
testing::AssertionResult CheckCSP(const SanitizedCSPResult& actual,
const std::string& expected_csp,
const std::string& warning1,
const std::string& warning2,
const std::string& warning3) { … }
}
TEST(ExtensionCSPValidator, IsLegal) { … }
TEST(ExtensionCSPValidator, IsSecure) { … }
TEST(ExtensionCSPValidator, IsSandboxed) { … }
TEST(ExtensionCSPValidator, EffectiveSandboxedPageCSP) { … }
namespace extensions {
namespace csp_validator {
void PrintTo(const CSPParser::Directive& directive, ::std::ostream* os) { … }
}
}
TEST(ExtensionCSPValidator, ParseCSP) { … }
TEST(ExtensionCSPValidator, DoesCSPDisallowRemoteCode) { … }