---
policy: /ce/ca/azure/application-gateway/gateway-waf-bot-protection
logic: /ce/ca/azure/application-gateway/gateway-waf-bot-protection/prod.logic.yaml
executionTime: 2025-12-17T01:31:02.431530131Z
generationMs: 67
executionMs: 668
rows:
  - id: '001'
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(INCOMPLIANT)
      actual: CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(INCOMPLIANT)
      actual: CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(COMPLIANT)
      actual: CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(COMPLIANT)
    runtimeError: {}
  - id: '005'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(COMPLIANT)
      actual: CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(COMPLIANT)
    runtimeError: {}
  - id: '006'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/application-gateway/gateway-waf-bot-protection/policy.yaml
    md5Hash: 6E75907DC0108B181618D33601AE2317
    content: |
      ---
      names:
        full: "Azure Application Gateway WAF policy bot protection is not enabled"
        contextual: "Application Gateway WAF policy bot protection is not enabled"
      description: "Enable bot protection on the Web Application Firewall to block or log requests from\
        \ known malicious IP addresses identified through the Microsoft Threat Intelligence feed."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v5.0.0/07/15"
        - "/frameworks/cloudaware/resource-security/threat-protection"
  - path: /ce/ca/azure/application-gateway/gateway-waf-bot-protection/prod.logic.yaml
    md5Hash: D004AA68DD6B69E68C3FA14083F352F3
    content: |
      ---
      inputType: "CA10__CaAzureApplicationGateway__c"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The Application Gateway WAF Policy does not use the Bot Manager Rule Set."
          remediationMessage: "Configure the Gateway WAF Policy to use the Bot Manager Rule Set."
          check:
            RELATED_LIST_HAS:
              status: "INCOMPLIANT"
              relationshipName: "CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r"
        - status: "COMPLIANT"
          currentStateMessage: "The Application Gateway has a WAF Policy that uses the Bot Manager Rule Set."
          check:
            RELATED_LIST_HAS:
              status: "COMPLIANT"
              relationshipName: "CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r"
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "The Application Gateway has no WAF Policy."
        remediationMessage: "Configure a WAF Policy for the Application Gateway."
      relatedLists:
        - relationshipName: "CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r"
          importExtracts:
            - file: /types/CA10Z1__CaAzureApplicationGatewayWafPolicy__c/object.extracts.yaml
          conditions:
          # Microsoft_BotManagerRuleSet not exist
            - status: "INCOMPLIANT"
              currentStateMessage: "Ensure a managed rule set with ruleSetType of Microsoft_BotManagerRuleSet is returned."
              remediationMessage: "Create managed rule set."
              check:
                LESS_THAN:
                  left:
                    EXTRACT: "CA10Z1__wafPolicy__r.caJsonFrom__managedRulesDefinitionMicrosoftBotManagerRuleSetCount__c"
                  right:
                    NUMBER: 1.0
          # ruleGroupOverrides is empty
            - status: "COMPLIANT"
              currentStateMessage: "The ruleGroupOverrides is empty"
              check:
                IS_EQUAL:
                  left:
                    EXTRACT: "CA10Z1__wafPolicy__r.caJsonFrom__managedRulesDefinitionMicrosoftBotManagerRuleSetRuleGroupOverridesCount__c"
                  right:
                    NUMBER: 0.0
          # no ruleGroupOverrides for ruleGroupName BadBots with state Disabled are returned
            - status: "COMPLIANT"
              currentStateMessage: "There're no ruleGroupOverrides for the BadBots rule group name in Disabled state."
              check:
                IS_EQUAL:
                  left:
                    EXTRACT: "CA10Z1__wafPolicy__r.caJsonFrom__managedRulesDefinitionMicrosoftBotManagerRuleSetRuleGroupOverridesBadBotsRulesDisabledExist__c"
                  right:
                    BOOLEAN: false
          otherwise:
            status: "INCOMPLIANT"
            currentStateMessage: "The ruleGroupOverrides for the BadBots rule group name in Disabled state are returned."
            remediationMessage: "Enable the Bad Bots rule group."
  - path: /ce/ca/azure/application-gateway/gateway-waf-bot-protection/test-data.json
    md5Hash: 10785A38D6F9425AEECBC3F79FA2B840
    content: "[\n  {\n    \"expectedResult\": {\n      \"status\": \"DISAPPEARED\"\
      ,\n      \"conditionIndex\": \"99\",\n      \"conditionText\": \"isDisappeared(CA10__disappearanceTime__c)\"\
      ,\n      \"runtimeError\": null\n    },\n    \"context\": { \"snapshotTime\"\
      : \"2025-11-19T21:25:23Z\" },\n    \"CA10__disappearanceTime__c\": \"2025-11-14T15:07:38Z\"\
      ,\n    \"Id\": \"001\",\n    \"CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r\"\
      : []\n  },\n  {\n    \"expectedResult\": {\n      \"status\": \"INCOMPLIANT\"\
      ,\n      \"conditionIndex\": \"199\",\n      \"conditionText\": \"CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(INCOMPLIANT)\"\
      ,\n      \"runtimeError\": null\n    },\n    \"context\": { \"snapshotTime\"\
      : \"2025-11-19T21:25:23Z\" },\n    \"CA10__disappearanceTime__c\": null,\n \
      \   \"Id\": \"002\",\n    \"CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r\"\
      : [\n      {\n        \"CA10Z1__disappearanceTime__c\": null,\n        \"CA10Z1__wafPolicy__c\"\
      : \"waf002\",\n        \"CA10Z1__wafPolicyId__c\": \"/subscriptions/1/resourcegroups/r/providers/microsoft.network/applicationgatewaywebapplicationfirewallpolicies/002\"\
      ,\n        \"CA10Z1__applicationGateway__c\": \"002\",\n        \"Id\": \"waflink002\"\
      ,\n        \"CA10Z1__wafPolicy__r\": {\n          \"Id\": \"waf002\",\n    \
      \      \"CA10Z1__disappearanceTime__c\": null,\n          \"CA10Z1__managedRulesDefinition__c\"\
      : \"{\\\"exclusions\\\":[],\\\"managedRuleSets\\\":[{\\\"ruleSetType\\\":\\\"\
      OWASP\\\",\\\"ruleSetVersion\\\":\\\"3.1\\\",\\\"ruleGroupOverrides\\\":[]}]}\"\
      \n        }\n      }\n    ]\n  },\n  {\n    \"expectedResult\": {\n      \"\
      status\": \"INCOMPLIANT\",\n      \"conditionIndex\": \"199\",\n      \"conditionText\"\
      : \"CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(INCOMPLIANT)\",\n    \
      \  \"runtimeError\": null\n    },\n    \"context\": { \"snapshotTime\": \"2025-11-19T21:25:23Z\"\
      \ },\n    \"CA10__disappearanceTime__c\": null,\n    \"Id\": \"003\",\n    \"\
      CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r\": [\n      {\n        \"CA10Z1__disappearanceTime__c\"\
      : null,\n        \"CA10Z1__wafPolicy__c\": \"waf003\",\n        \"CA10Z1__wafPolicyId__c\"\
      : \"/subscriptions/1/resourcegroups/r/providers/microsoft.network/applicationgatewaywebapplicationfirewallpolicies/003\"\
      ,\n        \"CA10Z1__applicationGateway__c\": \"003\",\n        \"Id\": \"waflink003\"\
      ,\n        \"CA10Z1__wafPolicy__r\": {\n          \"Id\": \"waf003\",\n    \
      \      \"CA10Z1__disappearanceTime__c\": null,\n          \"CA10Z1__managedRulesDefinition__c\"\
      : \"{\\\"exclusions\\\":[],\\\"managedRuleSets\\\":[{\\\"ruleSetType\\\":\\\"\
      Microsoft_BotManagerRuleSet\\\",\\\"ruleSetVersion\\\":\\\"1.0\\\",\\\"ruleGroupOverrides\\\
      \":[{\\\"ruleGroupName\\\":\\\"BadBots\\\",\\\"rules\\\":[{\\\"ruleId\\\":\\\
      \"100100\\\",\\\"state\\\":\\\"Disabled\\\",\\\"action\\\":\\\"LOG\\\"},{\\\"\
      ruleId\\\":\\\"100200\\\",\\\"state\\\":\\\"Disabled\\\",\\\"action\\\":\\\"\
      LOG\\\"}]},{\\\"ruleGroupName\\\":\\\"GoodBots\\\",\\\"rules\\\":[{\\\"ruleId\\\
      \":\\\"200100\\\",\\\"state\\\":\\\"Disabled\\\",\\\"action\\\":\\\"ALLOW\\\"\
      },{\\\"ruleId\\\":\\\"200200\\\",\\\"state\\\":\\\"Disabled\\\",\\\"action\\\
      \":\\\"LOG\\\"}]},{\\\"ruleGroupName\\\":\\\"UnknownBots\\\",\\\"rules\\\":[{\\\
      \"ruleId\\\":\\\"300100\\\",\\\"state\\\":\\\"Disabled\\\",\\\"action\\\":\\\
      \"LOG\\\"},{\\\"ruleId\\\":\\\"300700\\\",\\\"state\\\":\\\"Disabled\\\",\\\"\
      action\\\":\\\"LOG\\\"},{\\\"ruleId\\\":\\\"300600\\\",\\\"state\\\":\\\"Disabled\\\
      \",\\\"action\\\":\\\"LOG\\\"},{\\\"ruleId\\\":\\\"300500\\\",\\\"state\\\"\
      :\\\"Disabled\\\",\\\"action\\\":\\\"LOG\\\"},{\\\"ruleId\\\":\\\"300300\\\"\
      ,\\\"state\\\":\\\"Disabled\\\",\\\"action\\\":\\\"LOG\\\"},{\\\"ruleId\\\"\
      :\\\"300400\\\",\\\"state\\\":\\\"Disabled\\\",\\\"action\\\":\\\"LOG\\\"}]}]}]}\"\
      \n        }\n      }\n    ]\n  },\n  {\n    \"expectedResult\": {\n      \"\
      status\": \"COMPLIANT\",\n      \"conditionIndex\": \"299\",\n      \"conditionText\"\
      : \"CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(COMPLIANT)\",\n      \"\
      runtimeError\": null\n    },\n    \"context\": { \"snapshotTime\": \"2025-11-19T21:25:23Z\"\
      \ },\n    \"CA10__disappearanceTime__c\": null,\n    \"Id\": \"004\",\n    \"\
      CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r\": [\n      {\n        \"CA10Z1__disappearanceTime__c\"\
      : null,\n        \"CA10Z1__wafPolicy__c\": \"waf004\",\n        \"CA10Z1__wafPolicyId__c\"\
      : \"/subscriptions/1/resourcegroups/r/providers/microsoft.network/applicationgatewaywebapplicationfirewallpolicies/004\"\
      ,\n        \"CA10Z1__applicationGateway__c\": \"004\",\n        \"Id\": \"waflink004\"\
      ,\n        \"CA10Z1__wafPolicy__r\": {\n          \"Id\": \"waf004\",\n    \
      \      \"CA10Z1__disappearanceTime__c\": null,\n          \"CA10Z1__managedRulesDefinition__c\"\
      : \"{\\\"exclusions\\\":[],\\\"managedRuleSets\\\":[{\\\"ruleSetType\\\":\\\"\
      Microsoft_BotManagerRuleSet\\\",\\\"ruleSetVersion\\\":\\\"1.0\\\",\\\"ruleGroupOverrides\\\
      \":[]}]}\"        \n        }\n      }\n    ]\n  },\n  {\n    \"expectedResult\"\
      : {\n      \"status\": \"COMPLIANT\",\n      \"conditionIndex\": \"299\",\n\
      \      \"conditionText\": \"CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(COMPLIANT)\"\
      ,\n      \"runtimeError\": null\n    },\n    \"context\": { \"snapshotTime\"\
      : \"2025-11-19T21:25:23Z\" },\n    \"CA10__disappearanceTime__c\": null,\n \
      \   \"Id\": \"005\",\n    \"CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r\"\
      : [\n      {\n        \"CA10Z1__disappearanceTime__c\": null,\n        \"CA10Z1__wafPolicy__c\"\
      : \"waf005\",\n        \"CA10Z1__wafPolicyId__c\": \"/subscriptions/1/resourcegroups/r/providers/microsoft.network/applicationgatewaywebapplicationfirewallpolicies/005\"\
      ,\n        \"CA10Z1__applicationGateway__c\": \"005\",\n        \"Id\": \"waflink005\"\
      ,\n        \"CA10Z1__wafPolicy__r\": {\n          \"Id\": \"waf005\",\n    \
      \      \"CA10Z1__disappearanceTime__c\": null,\n          \"CA10Z1__managedRulesDefinition__c\"\
      : \"{\\\"exclusions\\\":[],\\\"managedRuleSets\\\":[{\\\"ruleSetType\\\":\\\"\
      Microsoft_BotManagerRuleSet\\\",\\\"ruleSetVersion\\\":\\\"1.1\\\",\\\"ruleGroupOverrides\\\
      \":[{\\\"ruleGroupName\\\":\\\"UnknownBots\\\",\\\"rules\\\":[{\\\"ruleId\\\"\
      :\\\"300700\\\",\\\"state\\\":\\\"Enabled\\\",\\\"action\\\":\\\"LOG\\\"}]}]}]}\"\
      \        }\n      }\n    ]\n  },\n  {\n    \"expectedResult\": {\n      \"status\"\
      : \"INCOMPLIANT\",\n      \"conditionIndex\": \"300\",\n      \"conditionText\"\
      : \"otherwise\",\n      \"runtimeError\": null\n    },\n    \"context\": { \"\
      snapshotTime\": \"2025-11-19T21:25:23Z\" },\n    \"CA10__disappearanceTime__c\"\
      : null,\n    \"Id\": \"006\",\n    \"CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r\"\
      : []\n  }\n]\n\n\n\n"
  - path: /types/CA10Z1__CaAzureApplicationGatewayWafPolicy__c/object.extracts.yaml
    md5Hash: 1203B501EE9251441BCA934785DC7D22
    content: "---\nextracts:\n# TEST\n  - name: \"CA10Z1__name__c\"\n    value:\n\
      \      FIELD:\n        path: \"CA10Z1__name__c\"\n\n# Nullable. Text.\n  - name:\
      \ \"CA10Z1__policySettings__c\"\n    value:\n      FIELD:\n        path: \"\
      CA10Z1__policySettings__c\"\n        returnType: BYTES\n# Nullable.\n  - name:\
      \ \"caJsonFrom__policySettings__c\"\n    value:\n      JSON_FROM:\n        arg:\n\
      \          EXTRACT: \"CA10Z1__policySettings__c\"\n        undeterminedIf:\n\
      \          isInvalid: \"Policy Settings JSON is invalid\"\n# Number. RequestBodyCheck\
      \ status.\n  - name: \"caJsonBoolean__policySettingsRequestBodyCheck__c\"\n\
      \    value: \n      JSON_QUERY_BOOLEAN:\n        arg: \n          EXTRACT: \"\
      caJsonFrom__policySettings__c\"\n        expression: \"requestBodyCheck\"\n\
      \        undeterminedIf: \n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return a boolean type.\"\
      \n# Nullable. Text.\n  - name: \"CA10Z1__managedRulesDefinition__c\"\n    value:\n\
      \      FIELD:\n        path: \"CA10Z1__managedRulesDefinition__c\"\n       \
      \ returnType: BYTES\n# Nullable.\n  - name: \"caJsonFrom__managedRulesDefinition__c\"\
      \n    value:\n      JSON_FROM:\n        arg:\n          EXTRACT: \"CA10Z1__managedRulesDefinition__c\"\
      \n        undeterminedIf:\n          isInvalid: \"Managed Rules Definition JSON\
      \ is invalid\"\n# Namber of \"MicrosoftBotManagerRuleSet\".\n  - name: \"caJsonFrom__managedRulesDefinitionMicrosoftBotManagerRuleSetCount__c\"\
      \n    value: \n      JSON_QUERY_NUMBER:\n        arg: \n          EXTRACT: \"\
      caJsonFrom__managedRulesDefinition__c\"\n        expression: \"length(managedRuleSets[?ruleSetType\
      \ == 'Microsoft_BotManagerRuleSet'])\"\n        undeterminedIf: \n         \
      \ evaluationError: \"The JSON query has failed.\"\n          resultTypeMismatch:\
      \ \"The JSON query did not return a number type.\"\n# Number of \"ruleGroupOverrides\"\
      \n  - name: \"caJsonFrom__managedRulesDefinitionMicrosoftBotManagerRuleSetRuleGroupOverridesCount__c\"\
      \n    value: \n      JSON_QUERY_NUMBER:\n        arg: \n          EXTRACT: \"\
      caJsonFrom__managedRulesDefinition__c\"\n        expression: \"length(managedRuleSets[?ruleSetType\
      \ == 'Microsoft_BotManagerRuleSet'].ruleGroupOverrides[])\"\n        undeterminedIf:\
      \ \n          evaluationError: \"The JSON query has failed.\"\n          resultTypeMismatch:\
      \ \"The JSON query did not return a number type.\" \n# Boolean. ruleGroupOverrides\
      \ for ruleGroupName \"BadBots\" with state Disabled\n  - name: \"caJsonFrom__managedRulesDefinitionMicrosoftBotManagerRuleSetRuleGroupOverridesBadBotsRulesDisabledExist__c\"\
      \n    value: \n      JSON_QUERY_BOOLEAN:\n        arg: \n          EXTRACT:\
      \ \"caJsonFrom__managedRulesDefinition__c\"\n        expression: \"managedRuleSets[?ruleSetType\
      \ == 'Microsoft_BotManagerRuleSet'].ruleGroupOverrides[] | contains([?ruleGroupName\
      \ == 'BadBots'].rules[].state, 'Disabled')\"\n        undeterminedIf: \n   \
      \       evaluationError: \"The JSON query has failed.\"\n          resultTypeMismatch:\
      \ \"The JSON query did not return a boolean type.\"\n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "001",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "005",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "006",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureApplicationGateway__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-11-14T15:07:38Z"),
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "Id" : "003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "Id" : "004"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "Id" : "005"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "Id" : "006"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10Z1__CaAzureAppGatewayWafPolicyLink__c()
  RETURNS ARRAY<STRUCT<
      CA10Z1__disappearanceTime__c TIMESTAMP,
      CA10Z1__wafPolicy__c STRING,
      CA10Z1__wafPolicyId__c STRING,
      CA10Z1__applicationGateway__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "CA10Z1__wafPolicy__c" : "waf002",
    "CA10Z1__wafPolicyId__c" : "/subscriptions/1/resourcegroups/r/providers/microsoft.network/applicationgatewaywebapplicationfirewallpolicies/002",
    "CA10Z1__applicationGateway__c" : "002",
    "Id" : "waflink002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "CA10Z1__wafPolicy__c" : "waf003",
    "CA10Z1__wafPolicyId__c" : "/subscriptions/1/resourcegroups/r/providers/microsoft.network/applicationgatewaywebapplicationfirewallpolicies/003",
    "CA10Z1__applicationGateway__c" : "003",
    "Id" : "waflink003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "CA10Z1__wafPolicy__c" : "waf004",
    "CA10Z1__wafPolicyId__c" : "/subscriptions/1/resourcegroups/r/providers/microsoft.network/applicationgatewaywebapplicationfirewallpolicies/004",
    "CA10Z1__applicationGateway__c" : "004",
    "Id" : "waflink004"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "CA10Z1__wafPolicy__c" : "waf005",
    "CA10Z1__wafPolicyId__c" : "/subscriptions/1/resourcegroups/r/providers/microsoft.network/applicationgatewaywebapplicationfirewallpolicies/005",
    "CA10Z1__applicationGateway__c" : "005",
    "Id" : "waflink005"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10Z1__CaAzureApplicationGatewayWafPolicy__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10Z1__disappearanceTime__c TIMESTAMP,
      CA10Z1__managedRulesDefinition__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "Id" : "waf002",
    "CA10Z1__managedRulesDefinition__c" : "{\"exclusions\":[],\"managedRuleSets\":[{\"ruleSetType\":\"OWASP\",\"ruleSetVersion\":\"3.1\",\"ruleGroupOverrides\":[]}]}"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "Id" : "waf003",
    "CA10Z1__managedRulesDefinition__c" : "{\"exclusions\":[],\"managedRuleSets\":[{\"ruleSetType\":\"Microsoft_BotManagerRuleSet\",\"ruleSetVersion\":\"1.0\",\"ruleGroupOverrides\":[{\"ruleGroupName\":\"BadBots\",\"rules\":[{\"ruleId\":\"100100\",\"state\":\"Disabled\",\"action\":\"LOG\"},{\"ruleId\":\"100200\",\"state\":\"Disabled\",\"action\":\"LOG\"}]},{\"ruleGroupName\":\"GoodBots\",\"rules\":[{\"ruleId\":\"200100\",\"state\":\"Disabled\",\"action\":\"ALLOW\"},{\"ruleId\":\"200200\",\"state\":\"Disabled\",\"action\":\"LOG\"}]},{\"ruleGroupName\":\"UnknownBots\",\"rules\":[{\"ruleId\":\"300100\",\"state\":\"Disabled\",\"action\":\"LOG\"},{\"ruleId\":\"300700\",\"state\":\"Disabled\",\"action\":\"LOG\"},{\"ruleId\":\"300600\",\"state\":\"Disabled\",\"action\":\"LOG\"},{\"ruleId\":\"300500\",\"state\":\"Disabled\",\"action\":\"LOG\"},{\"ruleId\":\"300300\",\"state\":\"Disabled\",\"action\":\"LOG\"},{\"ruleId\":\"300400\",\"state\":\"Disabled\",\"action\":\"LOG\"}]}]}]}"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "Id" : "waf004",
    "CA10Z1__managedRulesDefinition__c" : "{\"exclusions\":[],\"managedRuleSets\":[{\"ruleSetType\":\"Microsoft_BotManagerRuleSet\",\"ruleSetVersion\":\"1.0\",\"ruleGroupOverrides\":[]}]}"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-19T21:25:23Z")
    },
    "Id" : "waf005",
    "CA10Z1__managedRulesDefinition__c" : "{\"exclusions\":[],\"managedRuleSets\":[{\"ruleSetType\":\"Microsoft_BotManagerRuleSet\",\"ruleSetVersion\":\"1.1\",\"ruleGroupOverrides\":[{\"ruleGroupName\":\"UnknownBots\",\"rules\":[{\"ruleId\":\"300700\",\"state\":\"Enabled\",\"action\":\"LOG\"}]}]}]}"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureApplicationGateway__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          Id STRING,
          CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r ARRAY<STRUCT<
              CA10Z1__disappearanceTime__c TIMESTAMP,
              CA10Z1__wafPolicy__c STRING,
              CA10Z1__wafPolicyId__c STRING,
              CA10Z1__applicationGateway__c STRING,
              Id STRING,
              CA10Z1__wafPolicy__r STRUCT<
                  Id STRING,
                  CA10Z1__disappearanceTime__c TIMESTAMP,
                  CA10Z1__managedRulesDefinition__c STRING
              >,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Azure [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r_INCOMPLIANT2 = 0;
      if (obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r != null) {
          for (var i3 = 0; i3 < obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.length; i3++) {
              if (typeof(obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r[i3].status) !== 'undefined') {
                  if (obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r[i3].status == 'INCOMPLIANT') {
                      count_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r_INCOMPLIANT2 += obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r[i3].count;
                  }
              } else  {
                  if (obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r[i3].result.status == 'INCOMPLIANT') {
                      count_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r_INCOMPLIANT2 += 1;
                  }
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r] ' + (count_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(INCOMPLIANT)", currentStateMessage: "The Application Gateway WAF Policy does not use the Bot Manager Rule Set.", currentStateReferences: references1.join('\n'), remediation: "Configure the Gateway WAF Policy to use the Bot Manager Rule Set.", runtimeError: null};
      }
      var count_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r_COMPLIANT4 = 0;
      if (obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r != null) {
          for (var i5 = 0; i5 < obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.length; i5++) {
              if (typeof(obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r[i5].status) !== 'undefined') {
                  if (obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r[i5].status == 'COMPLIANT') {
                      count_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r_COMPLIANT4 += obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r[i5].count;
                  }
              } else  {
                  if (obj.CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r[i5].result.status == 'COMPLIANT') {
                      count_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r_COMPLIANT4 += 1;
                  }
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      if (count_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r_COMPLIANT4 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r.has(COMPLIANT)", currentStateMessage: "The Application Gateway has a WAF Policy that uses the Bot Manager Rule Set.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The Application Gateway has no WAF Policy.", currentStateReferences: references1.join('\n'), remediation: "Configure a WAF Policy for the Application Gateway.", runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r(
      obj STRUCT<
          CA10Z1__disappearanceTime__c TIMESTAMP,
          CA10Z1__wafPolicy__c STRING,
          CA10Z1__wafPolicyId__c STRING,
          CA10Z1__applicationGateway__c STRING,
          Id STRING,
          CA10Z1__wafPolicy__r STRUCT<
              Id STRING,
              CA10Z1__disappearanceTime__c TIMESTAMP,
              CA10Z1__managedRulesDefinition__c STRING
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  OPTIONS (library=['gs://compliance-platform-public/jmespath.min.js'])
  AS r"""
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Azure [CA10Z1__disappearanceTime__c]: ' + obj.CA10Z1__disappearanceTime__c);
      if (obj.CA10Z1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10Z1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function comparison2() {
          var comparisonLeft12 = extractChecked3();
          return comparisonLeft12 != null && 1.0 != null && comparisonLeft12 < 1.0;
      }
      function extractChecked3() {
          if (TextLib.isEmpty(obj.CA10Z1__wafPolicyId__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "extractCheck(obj.CA10Z1__wafPolicyId__c)", currentStateMessage: "Related object via CA10Z1__wafPolicyId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10Z1__wafPolicy__c)) {
              throw new Error("UNDETERMINED condition:102", {cause: {status: 'UNDETERMINED', conditionIndex: 102, conditionText: "extractCheck(obj.CA10Z1__wafPolicy__c)", currentStateMessage: "Related object via CA10Z1__wafPolicy__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10Z1__wafPolicy__r.CA10Z1__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:103", {cause: {status: 'UNDETERMINED', conditionIndex: 103, conditionText: "extractCheck(obj.CA10Z1__wafPolicy__r.CA10Z1__disappearanceTime__c)", currentStateMessage: "Related object via CA10Z1__wafPolicy__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract4.call(extract4);
      }
      function jsonQueryChecked5() {
          var input = extract7.call(extract7);
          var out;
          try {
              out = jmespath.search(input, 'length(managedRuleSets[?ruleSetType == \'Microsoft_BotManagerRuleSet\'])');
          if (out != null && typeof out != 'number') {
              throw new Error("UNDETERMINED condition:105", {cause: {status: 'UNDETERMINED', conditionIndex: 105, conditionText: "extract('caJsonFrom__managedRulesDefinition__c').jsonQueryText('length(managedRuleSets[?ruleSetType == \\'Microsoft_BotManagerRuleSet\\'])').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return a number type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:106", {cause: {status: 'UNDETERMINED', conditionIndex: 106, conditionText: "extract('caJsonFrom__managedRulesDefinition__c').jsonQueryText('length(managedRuleSets[?ruleSetType == \\'Microsoft_BotManagerRuleSet\\'])').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked8() {
          var input = extract10.call(extract10);
          input = TextLib.isEmpty(input) ? null : input;
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:104", {cause: {status: 'UNDETERMINED', conditionIndex: 104, conditionText: "extract('CA10Z1__managedRulesDefinition__c').asJson().isInvalid()", currentStateMessage: "Managed Rules Definition JSON is invalid", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extract10() { if (!this.out) { this.out = obj.CA10Z1__wafPolicy__r.CA10Z1__managedRulesDefinition__c; } return this.out; };
      function extract7() { if (!this.out) { this.out = jsonChecked8(); } return this.out; };
      function extract4() { if (!this.out) { this.out = jsonQueryChecked5(); } return this.out; };
      references1.push('Managed Rules Definition [obj.CA10Z1__wafPolicy__r.CA10Z1__managedRulesDefinition__c]: ' + obj.CA10Z1__wafPolicy__r.CA10Z1__managedRulesDefinition__c);
      try {
          if (comparison2()) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10Z1__wafPolicy__r.caJsonFrom__managedRulesDefinitionMicrosoftBotManagerRuleSetCount__c') < number(1.0)", currentStateMessage: "Ensure a managed rule set with ruleSetType of Microsoft_BotManagerRuleSet is returned.", currentStateReferences: references1.join('\n'), remediation: "Create managed rule set.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function extractChecked13() {
          if (TextLib.isEmpty(obj.CA10Z1__wafPolicyId__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "extractCheck(obj.CA10Z1__wafPolicyId__c)", currentStateMessage: "Related object via CA10Z1__wafPolicyId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10Z1__wafPolicy__c)) {
              throw new Error("UNDETERMINED condition:202", {cause: {status: 'UNDETERMINED', conditionIndex: 202, conditionText: "extractCheck(obj.CA10Z1__wafPolicy__c)", currentStateMessage: "Related object via CA10Z1__wafPolicy__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10Z1__wafPolicy__r.CA10Z1__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "extractCheck(obj.CA10Z1__wafPolicy__r.CA10Z1__disappearanceTime__c)", currentStateMessage: "Related object via CA10Z1__wafPolicy__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract14.call(extract14);
      }
      function jsonQueryChecked15() {
          var input = extract17.call(extract17);
          var out;
          try {
              out = jmespath.search(input, 'length(managedRuleSets[?ruleSetType == \'Microsoft_BotManagerRuleSet\'].ruleGroupOverrides[])');
          if (out != null && typeof out != 'number') {
              throw new Error("UNDETERMINED condition:205", {cause: {status: 'UNDETERMINED', conditionIndex: 205, conditionText: "extract('caJsonFrom__managedRulesDefinition__c').jsonQueryText('length(managedRuleSets[?ruleSetType == \\'Microsoft_BotManagerRuleSet\\'].ruleGroupOverrides[])').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return a number type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:206", {cause: {status: 'UNDETERMINED', conditionIndex: 206, conditionText: "extract('caJsonFrom__managedRulesDefinition__c').jsonQueryText('length(managedRuleSets[?ruleSetType == \\'Microsoft_BotManagerRuleSet\\'].ruleGroupOverrides[])').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked18() {
          var input = extract20.call(extract20);
          input = TextLib.isEmpty(input) ? null : input;
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:204", {cause: {status: 'UNDETERMINED', conditionIndex: 204, conditionText: "extract('CA10Z1__managedRulesDefinition__c').asJson().isInvalid()", currentStateMessage: "Managed Rules Definition JSON is invalid", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extract20() { if (!this.out) { this.out = obj.CA10Z1__wafPolicy__r.CA10Z1__managedRulesDefinition__c; } return this.out; };
      function extract17() { if (!this.out) { this.out = jsonChecked18(); } return this.out; };
      function extract14() { if (!this.out) { this.out = jsonQueryChecked15(); } return this.out; };
      try {
          if (extractChecked13() == 0.0) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10Z1__wafPolicy__r.caJsonFrom__managedRulesDefinitionMicrosoftBotManagerRuleSetRuleGroupOverridesCount__c') == number(0.0)", currentStateMessage: "The ruleGroupOverrides is empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[3], conditionIndex:[300..399]
      function extractChecked22() {
          if (TextLib.isEmpty(obj.CA10Z1__wafPolicyId__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "extractCheck(obj.CA10Z1__wafPolicyId__c)", currentStateMessage: "Related object via CA10Z1__wafPolicyId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10Z1__wafPolicy__c)) {
              throw new Error("UNDETERMINED condition:302", {cause: {status: 'UNDETERMINED', conditionIndex: 302, conditionText: "extractCheck(obj.CA10Z1__wafPolicy__c)", currentStateMessage: "Related object via CA10Z1__wafPolicy__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10Z1__wafPolicy__r.CA10Z1__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:303", {cause: {status: 'UNDETERMINED', conditionIndex: 303, conditionText: "extractCheck(obj.CA10Z1__wafPolicy__r.CA10Z1__disappearanceTime__c)", currentStateMessage: "Related object via CA10Z1__wafPolicy__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract23.call(extract23);
      }
      function jsonQueryChecked24() {
          var input = extract26.call(extract26);
          var out;
          try {
              out = jmespath.search(input, 'managedRuleSets[?ruleSetType == \'Microsoft_BotManagerRuleSet\'].ruleGroupOverrides[] | contains([?ruleGroupName == \'BadBots\'].rules[].state, \'Disabled\')');
          if (out != null && typeof out != 'boolean') {
              throw new Error("UNDETERMINED condition:305", {cause: {status: 'UNDETERMINED', conditionIndex: 305, conditionText: "extract('caJsonFrom__managedRulesDefinition__c').jsonQueryText('managedRuleSets[?ruleSetType == \\'Microsoft_BotManagerRuleSet\\'].ruleGroupOverrides[] | contains([?ruleGroupName == \\'BadBots\\'].rules[].state, \\'Disabled\\')').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return a boolean type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:306", {cause: {status: 'UNDETERMINED', conditionIndex: 306, conditionText: "extract('caJsonFrom__managedRulesDefinition__c').jsonQueryText('managedRuleSets[?ruleSetType == \\'Microsoft_BotManagerRuleSet\\'].ruleGroupOverrides[] | contains([?ruleGroupName == \\'BadBots\\'].rules[].state, \\'Disabled\\')').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked27() {
          var input = extract29.call(extract29);
          input = TextLib.isEmpty(input) ? null : input;
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:304", {cause: {status: 'UNDETERMINED', conditionIndex: 304, conditionText: "extract('CA10Z1__managedRulesDefinition__c').asJson().isInvalid()", currentStateMessage: "Managed Rules Definition JSON is invalid", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extract29() { if (!this.out) { this.out = obj.CA10Z1__wafPolicy__r.CA10Z1__managedRulesDefinition__c; } return this.out; };
      function extract26() { if (!this.out) { this.out = jsonChecked27(); } return this.out; };
      function extract23() { if (!this.out) { this.out = jsonQueryChecked24(); } return this.out; };
      try {
          if (extractChecked22() == false) {
              return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10Z1__wafPolicy__r.caJsonFrom__managedRulesDefinitionMicrosoftBotManagerRuleSetRuleGroupOverridesBadBotsRulesDisabledExist__c') == false", currentStateMessage: "There're no ruleGroupOverrides for the BadBots rule group name in Disabled state.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INCOMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "The ruleGroupOverrides for the BadBots rule group name in Disabled state are returned.", currentStateReferences: references1.join('\n'), remediation: "Enable the Bad Bots rule group.", runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.Id AS Id,
          `CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r`.arr AS CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r,
          process_CA10__CaAzureApplicationGateway__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.Id AS Id,
                  `CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r`.arr AS CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureApplicationGateway__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10Z1__applicationGateway__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                      sObject.CA10Z1__wafPolicy__c AS CA10Z1__wafPolicy__c,
                      sObject.CA10Z1__wafPolicyId__c AS CA10Z1__wafPolicyId__c,
                      sObject.CA10Z1__applicationGateway__c AS CA10Z1__applicationGateway__c,
                      sObject.Id AS Id,
                      STRUCT (
                          `CA10Z1__wafPolicy__r`.Id AS Id,
                          `CA10Z1__wafPolicy__r`.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                          `CA10Z1__wafPolicy__r`.CA10Z1__managedRulesDefinition__c AS CA10Z1__managedRulesDefinition__c
                      ) AS CA10Z1__wafPolicy__r,
                      process_CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r(
                          STRUCT(
                              sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                              sObject.CA10Z1__wafPolicy__c AS CA10Z1__wafPolicy__c,
                              sObject.CA10Z1__wafPolicyId__c AS CA10Z1__wafPolicyId__c,
                              sObject.CA10Z1__applicationGateway__c AS CA10Z1__applicationGateway__c,
                              sObject.Id AS Id,
                              STRUCT (
                                  `CA10Z1__wafPolicy__r`.Id AS Id,
                                  `CA10Z1__wafPolicy__r`.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                                  `CA10Z1__wafPolicy__r`.CA10Z1__managedRulesDefinition__c AS CA10Z1__managedRulesDefinition__c
                              ) AS CA10Z1__wafPolicy__r
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10Z1__CaAzureAppGatewayWafPolicyLink__c()) AS sObject
          LEFT JOIN UNNEST(mock_CA10Z1__CaAzureApplicationGatewayWafPolicy__c()) AS `CA10Z1__wafPolicy__r`
              ON sObject.CA10Z1__wafPolicy__c = `CA10Z1__wafPolicy__r`.Id
          GROUP BY sObject.CA10Z1__applicationGateway__c
      ) AS `CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r`
          ON sObject.Id = `CA10Z1__Azure_App_Gateway_WAF_Policy_Links__r`.CA10Z1__applicationGateway__c
  ) sObject ON sObject.Id = expectedResult.Id;
