# Description: CSP Checks for CSP Evaluator.

load("//javascript/typescript:build_defs.bzl", "ts_library")
load("//tools/build_defs/js:rules.bzl", "js_library")
load("//testing/karma/builddefs:karma_web_test_suite.bzl", "karma_web_test_suite")
load("//testing/web/build_defs:web.bzl", "custom_browser")

licenses(["notice"])

package_group(
    name = "csp_evaluator",
    packages = [
        "//javascript/security/csp/csp_evaluator/...",
        "//third_party/csp_evaluator/...",
    ],
)

package(default_visibility = [":csp_evaluator"])

js_library(
    name = "all_checks",
    srcs = [],
    exports = [
        ":parser_checks",
        ":security_checks",
        ":strictcsp_checks",
    ],
)

ts_library(
    name = "checker",
    srcs = ["checker.ts"],
    deps = [
        "//third_party/csp_evaluator:csp",
        "//third_party/csp_evaluator:finding",
    ],
)

ts_library(
    name = "parser_checks",
    srcs = ["parser_checks.ts"],
    deps = [
        "//third_party/csp_evaluator:csp",
        "//third_party/csp_evaluator:finding",
    ],
)

ts_library(
    name = "security_checks",
    srcs = ["security_checks.ts"],
    deps = [
        "//third_party/csp_evaluator:csp",
        "//third_party/csp_evaluator:finding",
        "//third_party/csp_evaluator:utils",
        "//third_party/csp_evaluator/allowlist_bypasses:angular",
        "//third_party/csp_evaluator/allowlist_bypasses:flash",
        "//third_party/csp_evaluator/allowlist_bypasses:jsonp",
    ],
)

ts_library(
    name = "strictcsp_checks",
    srcs = [
        "strictcsp_checks.ts",
    ],
    deps = [
        "//third_party/csp_evaluator:csp",
        "//third_party/csp_evaluator:finding",
    ],
)

filegroup(
    name = "js_files",
    srcs = glob(["*.js"]),
)

filegroup(
    name = "test_files",
    testonly = 1,
    srcs = glob([
        "*_test.html",
        "*_test.ts",
        "*_test_dom.html",
    ]),
)

ts_library(
    name = "checks_test_lib",
    testonly = True,
    srcs = [
        "parser_checks_test.ts",
        "security_checks_test.ts",
        "strictcsp_checks_test.ts",
    ],
    deps = [
        ":checker",
        ":parser_checks",
        ":security_checks",
        ":strictcsp_checks",
        "//third_party/csp_evaluator:csp",
        "//third_party/csp_evaluator:finding",
        "//third_party/csp_evaluator:parser",
        "//third_party/javascript/closure/array",
        "//third_party/javascript/closure/string",
        "//third_party/javascript/typings/jasmine",
    ],
)

custom_browser(
    name = "safari-iphone-stable",
    browser = "//testing/web/browsers/mobile/v12_0:safari-iphone",
)

karma_web_test_suite(
    name = "checks_tests",
    browsers = [
        ":safari-iphone-stable",
        "//testing/web/browsers:chrome-linux",
        "//testing/web/browsers:chrome-win7",
        "//testing/web/browsers/v63_0:firefox-linux",
        "//testing/web/browsers/v90_0:firefox-win7",
    ],
    deps = [":checks_test_lib"],
)
