---
policy: /ce/ca/google/sql/sqlserver-instance-external-scripts-enabled-flag
logic: /ce/ca/google/sql/sqlserver-instance-external-scripts-enabled-flag/prod.logic.yaml
executionTime: 2025-04-24T23:47:34.806436821Z
rows:
  - id: a8ED0
    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: a8E40
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: not(extract('CA10__databaseVersion__c').contains('SQLSERVER'))
      actual: not(extract('CA10__databaseVersion__c').contains('SQLSERVER'))
    runtimeError: {}
  - id: a8ED9
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 201
      actual: 201
    conditionText:
      expected: CA10__databaseFlagsJson__c.asJson().isEmpty()
      actual: CA10__databaseFlagsJson__c.asJson().isEmpty()
    runtimeError: {}
  - id: a8E49
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('caExtract_databaseFlags_external_scripts_enabled_flagValue__c')
        == 'off'
      actual: extract('caExtract_databaseFlags_external_scripts_enabled_flagValue__c')
        == 'off'
    runtimeError: {}
  - id: a8E4999
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/sql/sqlserver-instance-external-scripts-enabled-flag/policy.yaml
    md5Hash: B1F444E4F678C82380B9931253F80204
    content: "---\nnames: \n  full: \"Google Cloud SQL Server Instance external scripts\
      \ enabled Database Flag is not set to off\"\n  contextual: \"SQL Server Instance\
      \ external scripts enabled Database Flag is not set to off\"\ndescription: \"\
      It is recommended to set `external scripts enabled` database flag for Cloud\
      \ SQL SQL Server instance to `off`\"\ntype: COMPLIANCE_POLICY\ncategories:\n\
      \  - \"SECURITY\"\nframeworkMappings:\n  - /frameworks/cis-gcp-v3.0.0/06/03/01\n\
      \  - /frameworks/cloudaware/resource-security/threat-protection\nsimilarPolicies:\n\
      \  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudSQL/disable-external-scripts-enabled-flag.html\"\
      \n      name: \"Disable 'external scripts enabled' Flag for SQL Server Database\
      \ Instances\"\n"
  - path: /ce/ca/google/sql/sqlserver-instance-external-scripts-enabled-flag/prod.logic.yaml
    md5Hash: 62FDEDD42751EF3CFE50416E192F9076
    content: "---\n\ninputType: \"CA10__CaGoogleSqlInstance__c\"\ntestData:\n  - file:\
      \ test-data.json\nimportExtracts:\n  - file: /types/CA10__CaGoogleSqlInstance__c/object.extracts.yaml\n\
      conditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"This is\
      \ not a SQL Server database instance.\"\n    check:\n      NOT:\n        arg:\n\
      \          CONTAINS:\n            arg:\n              EXTRACT: \"CA10__databaseVersion__c\"\
      \n            substring:\n              TEXT: \"SQLSERVER\" \n  - status: \"\
      COMPLIANT\"\n    currentStateMessage: \"external scripts enabled database flag\
      \ is set to off.\"\n    check:\n      IS_EQUAL:\n        left:\n          EXTRACT:\
      \ \"caExtract_databaseFlags_external_scripts_enabled_flagValue__c\"\n      \
      \  right:\n          TEXT: \"off\"\notherwise:\n  status: \"INCOMPLIANT\"\n\
      \  currentStateMessage: \"external scripts enabled database flag isn't set to\
      \ off.\"\n  remediationMessage: \"Set external scripts enabled database flag\
      \ to off.\"\n"
  - path: /ce/ca/google/sql/sqlserver-instance-external-scripts-enabled-flag/test-data.json
    md5Hash: A48E0601A7DF245C9C069AB88895EA19
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T07:34:25Z" },
          "Id": "a8ED0",
          "CA10__disappearanceTime__c": "2023-12-06T13:34:16Z",
          "CA10__databaseVersion__c": "MYSQL_5_6",
          "CA10__databaseFlagsJson__c": "[{\"name\": \"log_duration\", \"value\": \"on\" }]"
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "not(extract('CA10__databaseVersion__c').contains('SQLSERVER'))",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T07:34:25Z" },
          "Id": "a8E40",
          "CA10__disappearanceTime__c": null,
          "CA10__databaseVersion__c": "MYSQL_8_0_26",
          "CA10__databaseFlagsJson__c": ""
        },
        {
          "expectedResult": {
            "status": "UNDETERMINED",
            "conditionIndex": "201",
            "conditionText": "CA10__databaseFlagsJson__c.asJson().isEmpty()",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T07:34:25Z" },
          "Id": "a8ED9",
          "CA10__disappearanceTime__c": null,
          "CA10__databaseVersion__c": "SQLSERVER_2019_STANDARD",
          "CA10__databaseFlagsJson__c": ""
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('caExtract_databaseFlags_external_scripts_enabled_flagValue__c') == 'off'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T07:34:25Z" },
          "Id": "a8E49",
          "CA10__disappearanceTime__c": null,
          "CA10__databaseVersion__c": "SQLSERVER_2019_STANDARD",
          "CA10__databaseFlagsJson__c": "[{\"name\": \"log_duration\", \"value\": \"on\" }, {\"name\" : \"external scripts enabled\",  \"value\" : \"off\" }]"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T07:34:25Z" },
          "Id": "a8E4999",
          "CA10__disappearanceTime__c": null,
          "CA10__databaseVersion__c": "SQLSERVER_2019_STANDARD",
          "CA10__databaseFlagsJson__c": "[{\"name\": \"log_duration\", \"value\": \"on\" }, {\"name\" : \"external scripts enabled\",  \"value\" : \"on\" }]"
        }
      ]
  - path: /types/CA10__CaGoogleSqlInstance__c/object.extracts.yaml
    md5Hash: CF5DA82560FA69E6A48E44B5BF123F0B
    content: "---\nextracts:\n  - name: \"CA10__databaseVersion__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__databaseVersion__c\"\n        undeterminedIf:\n\
      \          isEmpty:  \"Database version should not be empty\"\n  - name: \"\
      CA10__ipv4Enabled__c\"\n    value: \n      FIELD:\n        path: \"CA10__ipv4Enabled__c\"\
      \n        undeterminedIf:\n          isEmpty:  \"Ipv4Enabled should not be empty\"\
      \n  - name: \"caExtract__databaseFlagsJson__c\"\n    value: \n      JSON_FROM:\n\
      \        arg:\n          FIELD:\n            path: CA10__databaseFlagsJson__c\n\
      \            returnType: BYTES\n        undeterminedIf:\n          isInvalid:\
      \ \"Database Flags JSON is invalid.\"\n          isEmpty: \"Database Flags JSON\
      \ is empty.\"\n\n  - name: \"caExtract_databaseFlags_skip_show_database_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'skip_show_database'].value[] |\
      \ [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"caExtract_databaseFlags_local_infile_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'local_infile'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caExtract_databaseFlags_log_error_verbosity_flagValue__c\"\n\
      \    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression:  \"to_string([?name == 'log_error_verbosity'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"caExtract_databaseFlags_log_connections_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_connections'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caExtract_databaseFlags_log_disconnections_flagValue__c\"\n\
      \    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression:  \"to_string([?name == 'log_disconnections'].value[] |\
      \ [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"caExtract_databaseFlags_log_statement_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_statement'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caExtract_databaseFlags_log_min_messages_flagValue__c\"\n  \
      \  value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_min_messages'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caExtract_databaseFlags_log_min_error_statement_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_min_error_statement'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"caExtract_databaseFlags_log_min_duration_statement_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_min_duration_statement'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n\n  - name: \"caExtract_databaseFlags_cloudsql_enable_pgaudit_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'cloudsql.enable_pgaudit'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"caExtract_databaseFlags_external_scripts_enabled_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'external scripts enabled'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"caExtract_databaseFlags_cross_db_ownership_chaining_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'cross db ownership chaining'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"caExtract_databaseFlags_user_connections_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'user connections'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caExtract_databaseFlags_user_options_flagValue__c\"\n    value:\
      \ \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'user options'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caExtract_databaseFlags_remote_access_flagValue__c\"\n    value:\
      \ \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'remote access'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caExtract_databaseFlags_3625_flagValue__c\"\n    value: \n \
      \     JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == '3625'].value[] | [0])\"\n     \
      \   undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caExtract_databaseFlags_contained_database_authentication_flagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caExtract__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'contained database authentication'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"CA10__authorizedNetworksJson__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__authorizedNetworksJson__c\"\n      \
      \  returnType: BYTES\n  - name: \"caJsonFrom_authorizedNetworksJson__c\"\n \
      \   value: \n      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__authorizedNetworksJson__c\"\
      \n        undeterminedIf:\n          isInvalid: \"Authorized Networks JSON is\
      \ invalid.\"  \n  - name: \"caJsonFrom_authorizedNetworksJson_value__c\"\n \
      \   value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom_authorizedNetworksJson__c\"\
      \n        expression: \"to_string([].value)\"\n        undeterminedIf:\n   \
      \       evaluationError: \"The JSON query was failed.\"\n          resultTypeMismatch:\
      \ \"The JSON query did not return a text.\"\n\n  - name: \"CA10__instanceType__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__instanceType__c\"\n     \
      \   undeterminedIf:\n          isEmpty: \"Instance type should not be empty\"\
      \n  - name: \"CA10__backendType__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__backendType__c\"\n        undeterminedIf:\n          isEmpty: \"Backend\
      \ type should not be empty\"\n  - name: \"CA10__backupEnabled__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__backupEnabled__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Backup enabled should not be empty\"\n  - name: \"CA10__backupStartTime__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__backupStartTime__c\"\n  -\
      \ name: \"CA10__sslMode__c\"\n    value: \n      FIELD:\n        path: \"CA10__sslMode__c\"\
      \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" : "a8ED0",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8E40",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "not(extract('CA10__databaseVersion__c').contains('SQLSERVER'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8ED9",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "201",
      "conditionText" : "CA10__databaseFlagsJson__c.asJson().isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8E49",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('caExtract_databaseFlags_external_scripts_enabled_flagValue__c') == 'off'",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8E4999",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleSqlInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__databaseVersion__c STRING,
      CA10__databaseFlagsJson__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T07:34:25Z")
    },
    "Id" : "a8ED0",
    "CA10__disappearanceTime__c" : new Date("2023-12-06T13:34:16Z"),
    "CA10__databaseVersion__c" : "MYSQL_5_6",
    "CA10__databaseFlagsJson__c" : "[{\"name\": \"log_duration\", \"value\": \"on\" }]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T07:34:25Z")
    },
    "Id" : "a8E40",
    "CA10__databaseVersion__c" : "MYSQL_8_0_26",
    "CA10__databaseFlagsJson__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T07:34:25Z")
    },
    "Id" : "a8ED9",
    "CA10__databaseVersion__c" : "SQLSERVER_2019_STANDARD",
    "CA10__databaseFlagsJson__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T07:34:25Z")
    },
    "Id" : "a8E49",
    "CA10__databaseVersion__c" : "SQLSERVER_2019_STANDARD",
    "CA10__databaseFlagsJson__c" : "[{\"name\": \"log_duration\", \"value\": \"on\" }, {\"name\" : \"external scripts enabled\",  \"value\" : \"off\" }]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T07:34:25Z")
    },
    "Id" : "a8E4999",
    "CA10__databaseVersion__c" : "SQLSERVER_2019_STANDARD",
    "CA10__databaseFlagsJson__c" : "[{\"name\": \"log_duration\", \"value\": \"on\" }, {\"name\" : \"external scripts enabled\",  \"value\" : \"on\" }]"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleSqlInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__databaseVersion__c STRING,
          CA10__databaseFlagsJson__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));
          };
      }();
      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__databaseVersion__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__databaseVersion__c.isEmpty()", currentStateMessage: "Database version should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__databaseVersion__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Database Version [obj.CA10__databaseVersion__c]: ' + obj.CA10__databaseVersion__c);
      try {
          if (!TextLib.contains(extract3.call(extract3), 'SQLSERVER')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(extract('CA10__databaseVersion__c').contains('SQLSERVER'))", currentStateMessage: "This is not a SQL Server database instance.", 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 jsonQueryChecked7() {
          var input = extract9.call(extract9);
          var out;
          try {
              out = jmespath.search(input, 'to_string([?name == \'external scripts enabled\'].value[] | [0])');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "extract('caExtract__databaseFlagsJson__c').jsonQueryText('to_string([?name == \\'external scripts enabled\\'].value[] | [0])').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return text type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:204", {cause: {status: 'UNDETERMINED', conditionIndex: 204, conditionText: "extract('caExtract__databaseFlagsJson__c').jsonQueryText('to_string([?name == \\'external scripts enabled\\'].value[] | [0])').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked10() {
          var input = obj.CA10__databaseFlagsJson__c;
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__databaseFlagsJson__c.asJson().isEmpty()", currentStateMessage: "Database Flags 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:202", {cause: {status: 'UNDETERMINED', conditionIndex: 202, conditionText: "CA10__databaseFlagsJson__c.asJson().isInvalid()", currentStateMessage: "Database Flags JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extract9() { if (!this.out) { this.out = jsonChecked10(); } return this.out; };
      function extract6() { if (!this.out) { this.out = jsonQueryChecked7(); } return this.out; };
      references1.push('Database Flags JSON [obj.CA10__databaseFlagsJson__c]: ' + obj.CA10__databaseFlagsJson__c);
      try {
          if (TextLib.equal(extract6.call(extract6), 'off')) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('caExtract_databaseFlags_external_scripts_enabled_flagValue__c') == 'off'", currentStateMessage: "external scripts enabled database flag is set to off.", 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: 300, conditionText: "otherwise", currentStateMessage: "external scripts enabled database flag isn't set to off.", currentStateReferences: references1.join('\n'), remediation: "Set external scripts enabled database flag to off.", 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.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__databaseVersion__c AS CA10__databaseVersion__c,
          sObject.CA10__databaseFlagsJson__c AS CA10__databaseFlagsJson__c,
          process_CA10__CaGoogleSqlInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__databaseVersion__c AS CA10__databaseVersion__c,
                  sObject.CA10__databaseFlagsJson__c AS CA10__databaseFlagsJson__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleSqlInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
