---
policy: /ce/ca/google/vpc/network-mongodb-access
logic: /ce/ca/google/vpc/network-mongodb-access/prod.logic.yaml
executionTime: 2025-10-25T12:02:58.983417873Z
generationMs: 82
executionMs: 718
rows:
  - id: a4b0e1
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: a4b0e12
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: a4b0e13
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: a4b0e14
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: a4b0e16
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__Google_GCE_Firewall_Rules__r.has(INCOMPLIANT)
      actual: CA10__Google_GCE_Firewall_Rules__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: a4b0e17
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__Google_GCE_Firewall_Rules__r.has(INCOMPLIANT)
      actual: CA10__Google_GCE_Firewall_Rules__r.has(INCOMPLIANT)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/vpc/network-mongodb-access/policy.yaml
    md5Hash: CA67F4FB1B1E0B907FBA2F3E367F9F5D
    content: "---\nnames: \n  full: \"Google GCE Network allows unrestricted traffic\
      \ to MongoDB\"\n  contextual: \"GCE Network has Firewall Rules which allow unrestricted\
      \ MongoDB access from the Internet\"\ndescription: \"GCP Firewall Rules should\
      \ not allow unrestricted ingress traffic from\\\n  \\ the internet (0.0.0.0/0)\
      \ to MongoDB ports (TCP 27017-27019).\"\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n\
      \  - \"SECURITY\"\nframeworkMappings:\n  - \"/frameworks/nist-sp-800-53-r4/sc/07\"\
      \n  - \"/frameworks/pci-dss-v3.2.1/01/02/01\"\n  - \"/frameworks/iso-iec-27001-2013/13/01/01\"\
      \n  - \"/frameworks/cloudaware/resource-security/public-and-anonymous-access\""
  - path: /ce/ca/google/vpc/network-mongodb-access/prod.logic.yaml
    md5Hash: DF887C9BEF48856C733D95E3FDA65087
    content: |-
      ---

      inputType: "CA10__CaGoogleGceNetwork__c"
      testData:
        - file: test-data.json
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The Network has GCE Firewall Rules which allow unrestricted MongoDB access."
          remediationMessage: "Modify the firewall rule to remove unrestricted access."
          check:
            RELATED_LIST_HAS:
              status: "INCOMPLIANT"
              relationshipName: "CA10__Google_GCE_Firewall_Rules__r"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "MongoDB access is restricted from the internet."
      relatedLists:
        - relationshipName: "CA10__Google_GCE_Firewall_Rules__r"
          importExtracts:
            - file: /types/CA10__CaGoogleGceFirewallRule__c/object.extracts.yaml
          conditions:
            - status: "INAPPLICABLE"
              currentStateMessage: "This is not an ingress security firewall rule."
              check:
                NOT_EQUAL:
                  left:
                    EXTRACT: "CA10__direction__c"
                  right:
                    TEXT: "INGRESS"
            - status: "INAPPLICABLE"
              currentStateMessage: "This security firewall rule does not allow unrestricted access."
              check:
                AND:
                  args:
                    - NOT_EQUAL:
                        left:
                          EXTRACT: "CA10__sourceRanges__c"
                        right:
                          TEXT: "0.0.0.0/0"
                    - NOT_EQUAL:
                        left:
                          EXTRACT: "CA10__sourceRanges__c"
                        right:
                          TEXT: "::/0"
            - status: "INCOMPLIANT"
              currentStateMessage: "This firewall rule is unrestricted."
              remediationMessage: "Modify the firewall rule."
              check:
                GREATER_THAN:
                  left:
                    JSON_QUERY_NUMBER:
                      arg:
                        EXTRACT: "caJsonFrom__allowedProtocolsPortsJson__c"
                      expression: "length(ports[?(protocol=='tcp' && (startPort=='27017' || endPort=='27017' || startPort=='27018' || endPort=='27018' || startPort=='27019' || endPort=='27019' || (startPort<'27017' && endPort>'27019')))])"
                      undeterminedIf:
                        evaluationError: "The JSON query failed."
                        resultTypeMismatch: "The JSON query did not return number type."
                  right:
                    NUMBER: 0.0
          otherwise:
            status: "COMPLIANT"
            currentStateMessage: "This firewall rule does not allow unrestricted traffic to MongoDB ports."
  - path: /ce/ca/google/vpc/network-mongodb-access/test-data.json
    md5Hash: A18A174B1EE88B89CA97D2E6DFAD7534
    content: |
      [
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-28T20:26:50Z" },
          "Id": "a4b0e1",
          "CA10__disappearanceTime__c": null,
          "CA10__Google_GCE_Firewall_Rules__r": [
            {
              "Id": "a4V0e1",
              "CA10__disappearanceTime__c": null,
              "CA10__sourceRanges__c": "0.0.0.0/0",
              "CA10__direction__c": "INGRESS",
              "CA10__allowedProtocolsPortsJson__c": "{\"ports\":[{\"protocol\":\"tcp\",\"startPort\":\"30000\",\"endPort\":\"32767\"}]}",
              "CA10__gceNetwork__c": "a4b0e1"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-28T20:26:50Z" },
          "Id": "a4b0e12",
          "CA10__disappearanceTime__c": null,
          "CA10__Google_GCE_Firewall_Rules__r": [
            {
              "Id": "a4V0e12",
              "CA10__disappearanceTime__c": null,
              "CA10__sourceRanges__c": "0.0.0.0/0",
              "CA10__direction__c": "INGRESS",
              "CA10__allowedProtocolsPortsJson__c": "{\"ports\":[{\"protocol\":\"tcp\",\"startPort\":\"11\",\"endPort\":\"11\"},{\"protocol\":\"tcp\",\"startPort\":\"16379\",\"endPort\":\"16379\"}]}",
              "CA10__gceNetwork__c": "a4b0e12"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-28T20:26:50Z" },
          "Id": "a4b0e13",
          "CA10__disappearanceTime__c": null,
          "CA10__Google_GCE_Firewall_Rules__r": [
              {
                  "Id": "a4V0e13",
                  "CA10__disappearanceTime__c": null,
                  "CA10__sourceRanges__c": "10.128.0.0/9",
                  "CA10__direction__c": "INGRESS",
                  "CA10__allowedProtocolsPortsJson__c": "{\"ports\":[{\"protocol\":\"all\"}]}",
                  "CA10__gceNetwork__c": "a4b0e13"
              }
          ]
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-28T20:26:50Z" },
          "Id": "a4b0e14",
          "CA10__disappearanceTime__c": null,
          "CA10__Google_GCE_Firewall_Rules__r": [
              {
                  "Id": "a4V0e41",
                  "CA10__disappearanceTime__c": null,
                  "CA10__sourceRanges__c": "0.0.0.0/0",
                  "CA10__direction__c": "INGRESS",
                  "CA10__allowedProtocolsPortsJson__c": "{\"ports\":[{\"protocol\":\"icmp\"}]}",
                  "CA10__gceNetwork__c": "a4b0e14"
              }
          ]
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "CA10__Google_GCE_Firewall_Rules__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-28T20:26:50Z" },
          "Id": "a4b0e16",
          "CA10__disappearanceTime__c": null,
          "CA10__Google_GCE_Firewall_Rules__r": [
            {
              "Id": "a4V0e16",
              "CA10__disappearanceTime__c": null,
              "CA10__sourceRanges__c": "0.0.0.0/0",
              "CA10__direction__c": "INGRESS",
              "CA10__allowedProtocolsPortsJson__c": "{\"ports\":[{\"protocol\":\"tcp\",\"startPort\":\"10\",\"endPort\":\"27017\"}]}",
              "CA10__gceNetwork__c": "a4b0e16"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "CA10__Google_GCE_Firewall_Rules__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-28T20:26:50Z" },
          "Id": "a4b0e17",
          "CA10__disappearanceTime__c": null,
          "CA10__Google_GCE_Firewall_Rules__r": [
            {
              "Id": "a4V0e17",
              "CA10__disappearanceTime__c": null,
              "CA10__sourceRanges__c": "0.0.0.0/0",
              "CA10__direction__c": "INGRESS",
              "CA10__allowedProtocolsPortsJson__c": "{\"ports\":[{\"protocol\":\"tcp\",\"startPort\":\"27017\",\"endPort\":\"27019\"}]}",
              "CA10__gceNetwork__c": "a4b0e17"
            }
          ]
        }
      ]
  - path: /types/CA10__CaGoogleGceFirewallRule__c/object.extracts.yaml
    md5Hash: AE08F20196B487A130FB166DA77692D3
    content: "---\nextracts:\n  - name: \"CA10__direction__c\"\n    value: \n    \
      \  FIELD:\n        path: \"CA10__direction__c\"\n        undeterminedIf:\n \
      \        isEmpty: \"Direction is not populated yet.\"\n  - name: \"CA10__sourceRanges__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__sourceRanges__c\"\n     \
      \   undeterminedIf:\n          isEmpty: \"Source ranges are not populated yet.\"\
      \n  - name: \"CA10__allowedProtocolsPorts__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__allowedProtocolsPorts__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Allowed protocol ports are not populated yet.\"\n# 22\
      \ port variants: tcp: 22 / tcp: 22, 80 / tcp: 1-65535\n  - name: \"caJsonFrom__allowedProtocolsPortsJson__c\"\
      \n    value:\n      JSON_FROM:\n        arg:\n          FIELD: \n          \
      \  path: \"CA10__allowedProtocolsPortsJson__c\"\n            returnType: BYTES\n\
      \        undeterminedIf:\n          isInvalid: \"Allowed protocol ports JSON\
      \ is invalid.\"\n          isEmpty: \"Allowed protocol ports JSON is empty.\"\
      \n  - name: \"caJsonFrom__deniedProtocolsPortsJson__c\"\n    value:\n      JSON_FROM:\n\
      \        arg:\n          FIELD: \n            path: \"CA10__deniedProtocolsPortsJson__c\"\
      \n            returnType: BYTES\n        undeterminedIf:\n          isInvalid:\
      \ \"Denied protocol ports JSON is invalid.\"\n          isEmpty: \"Denied protocol\
      \ ports JSON is empty.\"\n  - name: \"CA10__destinationRanges__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__destinationRanges__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Destination ranges are not populated yet.\"\n  - name:\
      \ \"CA10__logState__c\"\n    value: \n      FIELD:\n        path: \"CA10__logState__c\"\
      \n        undeterminedIf:\n         isEmpty: \"Logging status undetermined.\"\
      \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" : "a4b0e1",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4b0e12",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4b0e13",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4b0e14",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4b0e16",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Google_GCE_Firewall_Rules__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4b0e17",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Google_GCE_Firewall_Rules__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceNetwork__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "Id" : "a4b0e1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "Id" : "a4b0e12"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "Id" : "a4b0e13"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "Id" : "a4b0e14"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "Id" : "a4b0e16"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "Id" : "a4b0e17"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceFirewallRule__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__direction__c STRING,
      CA10__sourceRanges__c STRING,
      CA10__allowedProtocolsPortsJson__c STRING,
      CA10__gceNetwork__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "CA10__direction__c" : "INGRESS",
    "CA10__sourceRanges__c" : "0.0.0.0/0",
    "CA10__allowedProtocolsPortsJson__c" : "{\"ports\":[{\"protocol\":\"tcp\",\"startPort\":\"30000\",\"endPort\":\"32767\"}]}",
    "CA10__gceNetwork__c" : "a4b0e1",
    "Id" : "a4V0e1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "CA10__direction__c" : "INGRESS",
    "CA10__sourceRanges__c" : "0.0.0.0/0",
    "CA10__allowedProtocolsPortsJson__c" : "{\"ports\":[{\"protocol\":\"tcp\",\"startPort\":\"11\",\"endPort\":\"11\"},{\"protocol\":\"tcp\",\"startPort\":\"16379\",\"endPort\":\"16379\"}]}",
    "CA10__gceNetwork__c" : "a4b0e12",
    "Id" : "a4V0e12"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "CA10__direction__c" : "INGRESS",
    "CA10__sourceRanges__c" : "10.128.0.0/9",
    "CA10__allowedProtocolsPortsJson__c" : "{\"ports\":[{\"protocol\":\"all\"}]}",
    "CA10__gceNetwork__c" : "a4b0e13",
    "Id" : "a4V0e13"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "CA10__direction__c" : "INGRESS",
    "CA10__sourceRanges__c" : "0.0.0.0/0",
    "CA10__allowedProtocolsPortsJson__c" : "{\"ports\":[{\"protocol\":\"icmp\"}]}",
    "CA10__gceNetwork__c" : "a4b0e14",
    "Id" : "a4V0e41"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "CA10__direction__c" : "INGRESS",
    "CA10__sourceRanges__c" : "0.0.0.0/0",
    "CA10__allowedProtocolsPortsJson__c" : "{\"ports\":[{\"protocol\":\"tcp\",\"startPort\":\"10\",\"endPort\":\"27017\"}]}",
    "CA10__gceNetwork__c" : "a4b0e16",
    "Id" : "a4V0e16"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-28T20:26:50Z")
    },
    "CA10__direction__c" : "INGRESS",
    "CA10__sourceRanges__c" : "0.0.0.0/0",
    "CA10__allowedProtocolsPortsJson__c" : "{\"ports\":[{\"protocol\":\"tcp\",\"startPort\":\"27017\",\"endPort\":\"27019\"}]}",
    "CA10__gceNetwork__c" : "a4b0e17",
    "Id" : "a4V0e17"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleGceNetwork__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          Id STRING,
          CA10__Google_GCE_Firewall_Rules__r ARRAY<STRUCT<
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__direction__c STRING,
              CA10__sourceRanges__c STRING,
              CA10__allowedProtocolsPortsJson__c STRING,
              CA10__gceNetwork__c STRING,
              Id 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 Google [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_CA10__Google_GCE_Firewall_Rules__r_INCOMPLIANT2 = 0;
      if (obj.CA10__Google_GCE_Firewall_Rules__r != null) {
          for (var i3 = 0; i3 < obj.CA10__Google_GCE_Firewall_Rules__r.length; i3++) {
              if (typeof(obj.CA10__Google_GCE_Firewall_Rules__r[i3].status) !== 'undefined') {
                  if (obj.CA10__Google_GCE_Firewall_Rules__r[i3].status == 'INCOMPLIANT') {
                      count_CA10__Google_GCE_Firewall_Rules__r_INCOMPLIANT2 += obj.CA10__Google_GCE_Firewall_Rules__r[i3].count;
                  }
              } else  {
                  if (obj.CA10__Google_GCE_Firewall_Rules__r[i3].result.status == 'INCOMPLIANT') {
                      count_CA10__Google_GCE_Firewall_Rules__r_INCOMPLIANT2 += 1;
                  }
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__Google_GCE_Firewall_Rules__r] ' + (count_CA10__Google_GCE_Firewall_Rules__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__Google_GCE_Firewall_Rules__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__Google_GCE_Firewall_Rules__r.has(INCOMPLIANT)", currentStateMessage: "The Network has GCE Firewall Rules which allow unrestricted MongoDB access.", currentStateReferences: references1.join('\n'), remediation: "Modify the firewall rule to remove unrestricted access.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "MongoDB access is restricted from the internet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Google_GCE_Firewall_Rules__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__direction__c STRING,
          CA10__sourceRanges__c STRING,
          CA10__allowedProtocolsPortsJson__c STRING,
          CA10__gceNetwork__c STRING,
          Id 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 Google [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};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__direction__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__direction__c.isEmpty()", currentStateMessage: "Direction is not populated yet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__direction__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Direction [obj.CA10__direction__c]: ' + obj.CA10__direction__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'INGRESS')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__direction__c') != 'INGRESS'", currentStateMessage: "This is not an ingress security firewall rule.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function fieldChecked7() {
          if (TextLib.isEmpty(obj.CA10__sourceRanges__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__sourceRanges__c.isEmpty()", currentStateMessage: "Source ranges are not populated yet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__sourceRanges__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      references1.push('Source Ranges [obj.CA10__sourceRanges__c]: ' + obj.CA10__sourceRanges__c);
      try {
          if (TextLib.notEqual(extract6.call(extract6), '0.0.0.0/0') && TextLib.notEqual(extract6.call(extract6), '::/0')) {
              return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__sourceRanges__c') != '0.0.0.0/0' && extract('CA10__sourceRanges__c') != '::/0'", currentStateMessage: "This security firewall rule does not allow unrestricted access.", 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 comparison9() {
          var comparisonLeft15 = jsonQueryChecked10();
          return comparisonLeft15 != null && 0.0 != null && comparisonLeft15 > 0.0;
      }
      function jsonQueryChecked10() {
          var input = extract12.call(extract12);
          var out;
          try {
              out = jmespath.search(input, 'length(ports[?(protocol==\'tcp\' && (startPort==\'27017\' || endPort==\'27017\' || startPort==\'27018\' || endPort==\'27018\' || startPort==\'27019\' || endPort==\'27019\' || (startPort<\'27017\' && endPort>\'27019\')))])');
          if (out != null && typeof out != 'number') {
              throw new Error("UNDETERMINED condition:303", {cause: {status: 'UNDETERMINED', conditionIndex: 303, conditionText: "extract('caJsonFrom__allowedProtocolsPortsJson__c').jsonQueryText('length(ports[?(protocol==\\'tcp\\' && (startPort==\\'27017\\' || endPort==\\'27017\\' || startPort==\\'27018\\' || endPort==\\'27018\\' || startPort==\\'27019\\' || endPort==\\'27019\\' || (startPort<\\'27017\\' && endPort>\\'27019\\')))])').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return number type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:304", {cause: {status: 'UNDETERMINED', conditionIndex: 304, conditionText: "extract('caJsonFrom__allowedProtocolsPortsJson__c').jsonQueryText('length(ports[?(protocol==\\'tcp\\' && (startPort==\\'27017\\' || endPort==\\'27017\\' || startPort==\\'27018\\' || endPort==\\'27018\\' || startPort==\\'27019\\' || endPort==\\'27019\\' || (startPort<\\'27017\\' && endPort>\\'27019\\')))])').isEvaluationFailed()", currentStateMessage: "The JSON query failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked13() {
          var input = obj.CA10__allowedProtocolsPortsJson__c;
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10__allowedProtocolsPortsJson__c.asJson().isEmpty()", currentStateMessage: "Allowed protocol ports JSON is empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:302", {cause: {status: 'UNDETERMINED', conditionIndex: 302, conditionText: "CA10__allowedProtocolsPortsJson__c.asJson().isInvalid()", currentStateMessage: "Allowed protocol ports JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extract12() { if (!this.out) { this.out = jsonChecked13(); } return this.out; };
      references1.push('Allowed Protocols / Ports JSON [obj.CA10__allowedProtocolsPortsJson__c]: ' + obj.CA10__allowedProtocolsPortsJson__c);
      try {
          if (comparison9()) {
              return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('caJsonFrom__allowedProtocolsPortsJson__c').jsonQueryText('length(ports[?(protocol==\\'tcp\\' && (startPort==\\'27017\\' || endPort==\\'27017\\' || startPort==\\'27018\\' || endPort==\\'27018\\' || startPort==\\'27019\\' || endPort==\\'27019\\' || (startPort<\\'27017\\' && endPort>\\'27019\\')))])') > number(0.0)", currentStateMessage: "This firewall rule is unrestricted.", currentStateReferences: references1.join('\n'), remediation: "Modify the firewall rule.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "This firewall rule does not allow unrestricted traffic to MongoDB ports.", currentStateReferences: references1.join('\n'), remediation: null, 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,
          `CA10__Google_GCE_Firewall_Rules__r`.arr AS CA10__Google_GCE_Firewall_Rules__r,
          process_CA10__CaGoogleGceNetwork__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.Id AS Id,
                  `CA10__Google_GCE_Firewall_Rules__r`.arr AS CA10__Google_GCE_Firewall_Rules__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleGceNetwork__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__gceNetwork__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__direction__c AS CA10__direction__c,
                      sObject.CA10__sourceRanges__c AS CA10__sourceRanges__c,
                      sObject.CA10__allowedProtocolsPortsJson__c AS CA10__allowedProtocolsPortsJson__c,
                      sObject.CA10__gceNetwork__c AS CA10__gceNetwork__c,
                      sObject.Id AS Id,
                      process_CA10__Google_GCE_Firewall_Rules__r(
                          STRUCT(
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__direction__c AS CA10__direction__c,
                              sObject.CA10__sourceRanges__c AS CA10__sourceRanges__c,
                              sObject.CA10__allowedProtocolsPortsJson__c AS CA10__allowedProtocolsPortsJson__c,
                              sObject.CA10__gceNetwork__c AS CA10__gceNetwork__c,
                              sObject.Id AS Id
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaGoogleGceFirewallRule__c()) AS sObject
          GROUP BY sObject.CA10__gceNetwork__c
      ) AS `CA10__Google_GCE_Firewall_Rules__r`
          ON sObject.Id = `CA10__Google_GCE_Firewall_Rules__r`.CA10__gceNetwork__c
  ) sObject ON sObject.Id = expectedResult.Id;
