---
policy: /ce/ca/azure/storage/table-logging-for-read-write-delete-requests
logic: /ce/ca/azure/storage/table-logging-for-read-write-delete-requests/prod.logic.yaml
executionTime: 2025-05-10T12:03:20.59039378Z
rows:
  - id: test1
    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: test2
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 101
      actual: 101
    conditionText:
      expected: CA10__tableLoggingReadState__c.delegatedTo(CA10__tableLoggingReadState__c).isEmpty()
      actual: CA10__tableLoggingReadState__c.delegatedTo(CA10__tableLoggingReadState__c).isEmpty()
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__tableLoggingReadState__c') == 'Disabled' || extract('CA10__tableLoggingWriteState__c')
        == 'Disabled' || extract('CA10__tableLoggingDeleteState__c') == 'Disabled'
      actual: extract('CA10__tableLoggingReadState__c') == 'Disabled' || extract('CA10__tableLoggingWriteState__c')
        == 'Disabled' || extract('CA10__tableLoggingDeleteState__c') == 'Disabled'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__tableLoggingReadState__c') == 'Enabled' && extract('CA10__tableLoggingWriteState__c')
        == 'Enabled' && extract('CA10__tableLoggingDeleteState__c') == 'Enabled'
      actual: extract('CA10__tableLoggingReadState__c') == 'Enabled' && extract('CA10__tableLoggingWriteState__c')
        == 'Enabled' && extract('CA10__tableLoggingDeleteState__c') == 'Enabled'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/storage/table-logging-for-read-write-delete-requests/policy.yaml
    md5Hash: 30EA9D96328E22C4B65878313E8755AF
    content: |
      ---
      names:
        full: "Azure Storage Table Logging is not enabled for Read, Write, and Delete requests"
        contextual: "Table Logging is not enabled for Read, Write, and Delete requests"
      description: "Azure Table storage is a service that stores structured NoSQL data in\
        \ the cloud, providing a key/attribute store with a schema-less design. Storage\
        \ Logging happens server-side and allows details for both successful and failed\
        \ requests to be recorded in the storage account. These logs allow users to   see\
        \ the details of read, write, and delete operations against the tables."
      type: COMPLIANCE_POLICY
      categories:
        - RELIABILITY
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v2.1.0/03/14"
        - "/frameworks/cis-azure-v3.0.0/04/14"
        - "/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration"
      similarPolicies:
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/azure/StorageAccounts/storage-table-service-logging.html
            name: Enable Logging for Azure Storage Table Service
  - path: /ce/ca/azure/storage/table-logging-for-read-write-delete-requests/prod.logic.yaml
    md5Hash: 25A762EF601429EBC49FC691B2BD1F6B
    content: "---\ninputType: \"CA10__CaAzureStorageAccount__c\"\ntestData:\n  - file:\
      \ \"test-data.json\"\nimportExtracts:\n  - file: \"/types/CA10__CaAzureStorageAccount__c/object.extracts.yaml\"\
      \nconditions:\n  - status: \"COMPLIANT\"\n    currentStateMessage: \"Storage\
      \ Logging for Table Service is enabled.\"\n    check:\n      AND:\n        args:\n\
      \          - IS_EQUAL:\n              left:\n                EXTRACT: \"CA10__tableLoggingReadState__c\"\
      \n              right: \n                TEXT: \"Enabled\"\n          - IS_EQUAL:\n\
      \              left:\n                EXTRACT: \"CA10__tableLoggingWriteState__c\"\
      \n              right: \n                TEXT: \"Enabled\"\n          - IS_EQUAL:\n\
      \              left:\n                EXTRACT: \"CA10__tableLoggingDeleteState__c\"\
      \n              right: \n                TEXT: \"Enabled\"\n  - status: \"INCOMPLIANT\"\
      \n    currentStateMessage: \"Storage Logging for Table Service is disabled.\"\
      \n    remediationMessage: \"Consider enabling Storage Logging for read, write,\
      \ and delete requests.\"    \n    check:\n      OR:\n        args:\n       \
      \   - IS_EQUAL:\n              left:\n                EXTRACT: \"CA10__tableLoggingReadState__c\"\
      \n              right: \n                TEXT: \"Disabled\"\n          - IS_EQUAL:\n\
      \              left:\n                EXTRACT: \"CA10__tableLoggingWriteState__c\"\
      \n              right: \n                TEXT: \"Disabled\"\n          - IS_EQUAL:\n\
      \              left:\n                EXTRACT: \"CA10__tableLoggingDeleteState__c\"\
      \n              right: \n                TEXT: \"Disabled\"\notherwise:\n  status:\
      \ \"UNDETERMINED\"\n  currentStateMessage: \"Unexpected value in the field.\""
  - path: /types/CA10__CaAzureStorageAccount__c/object.extracts.yaml
    md5Hash: 2E0979CA85C35CDB555F32B262F6942F
    content: "---\nextracts:\n# This is a checkbox. Not nullable. Can't have no access,\
      \ retrieved via Microsoft.Storage/storageAccounts\n  - name: \"CA10__secureTransferRequired__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__secureTransferRequired__c\"\
      \n# Values: Enabled, Disabled. Not Nullable. Can't have no access, retrieved\
      \ via Microsoft.Storage/storageAccounts\n  - name: \"CA10__requireInfrastructureEncryptionState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__requireInfrastructureEncryptionState__c\"\
      \n        undeterminedIf:\n          isEmpty: \"Corrupted data. Require Infrastructure\
      \ Encryption setting cannot be empty.\"\n# Values: Enabled, Disabled. Not Nullable.\
      \ Can't have no access, retrieved via Microsoft.Storage/storageAccounts\n  -\
      \ name: \"CA10__publicNetworkAccessState__c\"\n    value: \n      FIELD:\n \
      \       path: \"CA10__publicNetworkAccessState__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. Public Network Access cannot be empty.\"\
      \n# Values: Allow, Deny. Not nullable. Can't have no access, retrieved via Microsoft.Storage/storageAccounts.\n\
      \  - name: \"CA10__networkAclsDefaultAction__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__networkAclsDefaultAction__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. Default Network Action cannot be empty.\"\
      \n# Values: any combination of Logging|Metrics|AzureServices or None. Not nullable.\
      \ \n# Can't have no access, retrieved via Microsoft.Storage/storageAccounts.\n\
      \  - name: \"CA10__networkAclsBypass__c\"\n    value: \n      FIELD:\n     \
      \   path: \"CA10__networkAclsBypass__c\"\n        undeterminedIf:\n        \
      \  isEmpty: \"Corrupted data. Network Bypass cannot be empty.\"\n# Values TLS1_0,\
      \ TLS1_1, TLS1_2. Not nullable. Can't have no access, retrieved via Microsoft.Storage/storageAccounts.\n\
      \  - name: \"CA10__minimumTlsVersion__c\"\n    value: \n      FIELD:\n     \
      \   path: \"CA10__minimumTlsVersion__c\"\n        undeterminedIf:\n        \
      \  isEmpty: \"Corrupted data. TLS Version cannot be empty.\"\n# Values: Allow,\
      \ Deny, null (Old storage accounts can have null, which means that the account\
      \ can still have replication). \n# Nullable. Can't have no access, retrieved\
      \ via Microsoft.Storage/storageAccounts.\n  - name: \"CA10__crossTenantReplication__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__crossTenantReplication__c\"\
      \n# Values: Allow, Deny. Not nullable. Can't have no access, retrieved via Microsoft.Storage/storageAccounts.\n\
      \  - name: \"CA10__blobPublicAccess__c\"\n    value: \n      FIELD:\n      \
      \  path: \"CA10__blobPublicAccess__c\"\n        undeterminedIf:\n          isEmpty:\
      \ \"Corrupted data. Allow Blob Anonymous Access cannot be empty.\"\n# Values\
      \ Enabled, Disabled. Not Nullable\n  - name: \"CA10__blobLoggingReadState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__blobLoggingReadState__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__blobLoggingReadState__c\"\n            currentStateMessage: \"Unable to\
      \ determine Blob Container Logging Read property. Possible permission issue\
      \ with Microsoft.Storage/storageAccounts/blobServices/containers/read\"\n  \
      \        isEmpty: \"Storage Blob Logging is not populated yet.\"\n# Values Enabled,\
      \ Disabled. Not Nullable\n  - name: \"CA10__blobLoggingWriteState__c\"\n   \
      \ value: \n      FIELD:\n        path: \"CA10__blobLoggingWriteState__c\"\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__blobLoggingWriteState__c\"\n            currentStateMessage: \"Unable\
      \ to determine Blob Container Logging Write property. Possible permission issue\
      \ with Microsoft.Storage/storageAccounts/blobServices/containers/read\"\n  \
      \        isEmpty: \"Storage Blob Logging is not populated yet.\"\n # Values\
      \ Enabled, Disabled. Not Nullable\n  - name: \"CA10__blobLoggingDeleteState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__blobLoggingDeleteState__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__blobLoggingDeleteState__c\"\n            currentStateMessage: \"Unable\
      \ to determine Blob Container Logging Delete property. Possible permission issue\
      \ with Microsoft.Storage/storageAccounts/blobServices/containers/read\"\n  \
      \        isEmpty: \"Storage Blob Logging is not populated yet.\"\n# Values Enabled,\
      \ Disabled. Not Nullable\n  - name: \"CA10__queueLoggingReadState__c\"\n   \
      \ value: \n      FIELD:\n        path: \"CA10__queueLoggingReadState__c\"\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__queueLoggingReadState__c\"\n            currentStateMessage: \"Unable\
      \ to determine Queue Logging Read property. Possible permission issue with Microsoft.Storage/storageAccounts/queueServices/queues/read\"\
      \n          isEmpty: \"Storage Queue Logging is not populated yet.\"\n# Values\
      \ Enabled, Disabled. Not Nullable\n  - name: \"CA10__queueLoggingWriteState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__queueLoggingWriteState__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__queueLoggingWriteState__c\"\n            currentStateMessage: \"Unable\
      \ to determine Queue Logging Write property. Possible permission issue with\
      \ Microsoft.Storage/storageAccounts/queueServices/queues/read\"\n          isEmpty:\
      \ \"Storage Queue Logging is not populated yet.\"\n# Values Enabled, Disabled.\
      \ Not Nullable\n  - name: \"CA10__queueLoggingDeleteState__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__queueLoggingDeleteState__c\"\n        undeterminedIf:\n\
      \          noAccessDelegate:\n            path: \"CA10__queueLoggingDeleteState__c\"\
      \n            currentStateMessage: \"Unable to determine Queue Logging Delete\
      \ property. Possible permission issue with Microsoft.Storage/storageAccounts/queueServices/queues/read\"\
      \n          isEmpty: \"Storage Queue Logging is not populated yet.\"\n# Values\
      \ Enabled, Disabled. Not Nullable\n  - name: \"CA10__tableLoggingReadState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__tableLoggingReadState__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__tableLoggingReadState__c\"\n            currentStateMessage: \"Unable\
      \ to determine Table Logging Read property. Possible permission issue with Microsoft.Storage/storageAccounts/tableServices/tables/read\"\
      \n          isEmpty: \"Storage Table Logging is not populated yet.\"\n# Values\
      \ Enabled, Disabled. Not Nullable\n  - name: \"CA10__tableLoggingWriteState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__tableLoggingWriteState__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__tableLoggingWriteState__c\"\n            currentStateMessage: \"Unable\
      \ to determine Table Logging Write property. Possible permission issue with\
      \ Microsoft.Storage/storageAccounts/tableServices/tables/read\"\n          isEmpty:\
      \ \"Storage Table Logging is not populated yet.\"\n# Values Enabled, Disabled.\
      \ Not Nullable\n  - name: \"CA10__tableLoggingDeleteState__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__tableLoggingDeleteState__c\"\n        undeterminedIf:\n\
      \          noAccessDelegate:\n            path: \"CA10__tableLoggingDeleteState__c\"\
      \n            currentStateMessage: \"Unable to determine Table Logging Delete\
      \ property. Possible permission issue with Microsoft.Storage/storageAccounts/tableServices/tables/read\"\
      \n          isEmpty: \"Storage Table Logging is not populated yet.\"\n# Values\
      \ Microsoft.Storage, Microsoft.Keyvault. Not Nullable. Can't have no access,\
      \ retrieved via Microsoft.Storage/storageAccounts\n  - name: \"CA10__encryptionKeySource__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__encryptionKeySource__c\"\n\
      \        undeterminedIf:\n          isEmpty: \"Corrupted data. Encryption Key\
      \ Source cannot be empty.\"\n# Nullable. Can't have no access, retrieved via\
      \ Microsoft.Storage/storageAccounts\n  - name: \"CA10__encryptionKeyVaultUri__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__encryptionKeyVaultUri__c\"\
      \n# Nullable. \n  - name: \"CA10__blobRetentionPolicyDays__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__blobRetentionPolicyDays__c\"\n# Values:\
      \ Enabled, Disabled. Nullable. \n  - name: \"CA10__blobRetentionPolicyState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__blobRetentionPolicyState__c\"\
      \n# Nullable. \n  - name: \"CA10__containerRetentionPolicyDays__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__containerRetentionPolicyDays__c\"\n\
      # Values: Enabled, Disabled. Nullable. \n  - name: \"CA10__containerRetentionPolicyState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__containerRetentionPolicyState__c\"\
      \n# Nullable. Text field.\n  - name: \"CA10__skuName__c\"\n    value:\n    \
      \  FIELD:\n        path: \"CA10__skuName__c\"\n"
  - path: /ce/ca/azure/storage/table-logging-for-read-write-delete-requests/test-data.json
    md5Hash: 9AF196E50AD3FAB123BE4E3929ECE22C
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-12T19:31:46Z"
              },
              "Id": "test1",
              "RecordTypeId": "recordType",
              "CA10__disappearanceTime__c": "2024-06-12T19:31:46Z",
              "CA10__tableLoggingReadState__c": "Enabled",
              "CA10__tableLoggingWriteState__c": "Enabled",
              "CA10__tableLoggingDeleteState__c": "Enabled",
              "RecordType": {
                  "DeveloperName": "StorageAccount",
                  "Id": "test1_1"
              }
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "101",
                  "conditionText": "CA10__tableLoggingReadState__c.delegatedTo(CA10__tableLoggingReadState__c).isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-12T19:31:46Z"
              },
              "Id": "test2",
              "RecordTypeId": "recordType",
              "CA10__disappearanceTime__c": null,
              "CA10__tableLoggingReadState__c": "",
              "CA10__tableLoggingWriteState__c": "",
              "CA10__tableLoggingDeleteState__c": "",
              "RecordType": {
                  "DeveloperName": "StorageAccount",
                  "Id": "test2_1"
              }
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__tableLoggingReadState__c') == 'Disabled' || extract('CA10__tableLoggingWriteState__c') == 'Disabled' || extract('CA10__tableLoggingDeleteState__c') == 'Disabled'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-12T19:31:46Z"
              },
              "Id": "test3",
              "RecordTypeId": "recordType",
              "CA10__disappearanceTime__c": null,
              "CA10__tableLoggingReadState__c": "Disabled",
              "CA10__tableLoggingWriteState__c": "Disabled",
              "CA10__tableLoggingDeleteState__c": "Disabled",
              "RecordType": {
                  "DeveloperName": "StorageAccount",
                  "Id": "test3_1"
              }
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__tableLoggingReadState__c') == 'Enabled' && extract('CA10__tableLoggingWriteState__c') == 'Enabled' && extract('CA10__tableLoggingDeleteState__c') == 'Enabled'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-12T19:31:46Z"
              },
              "Id": "test4",
              "RecordTypeId": "recordType",
              "CA10__disappearanceTime__c": null,
              "CA10__tableLoggingReadState__c": "Enabled",
              "CA10__tableLoggingWriteState__c": "Enabled",
              "CA10__tableLoggingDeleteState__c": "Enabled",
              "RecordType": {
                  "DeveloperName": "StorageAccount",
                  "Id": "test4_1"
              }
          }
      ]
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" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "101",
      "conditionText" : "CA10__tableLoggingReadState__c.delegatedTo(CA10__tableLoggingReadState__c).isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__tableLoggingReadState__c') == 'Disabled' || extract('CA10__tableLoggingWriteState__c') == 'Disabled' || extract('CA10__tableLoggingDeleteState__c') == 'Disabled'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__tableLoggingReadState__c') == 'Enabled' && extract('CA10__tableLoggingWriteState__c') == 'Enabled' && extract('CA10__tableLoggingDeleteState__c') == 'Enabled'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureStorageAccount__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      RecordTypeId STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__tableLoggingReadState__c STRING,
      CA10__tableLoggingWriteState__c STRING,
      CA10__tableLoggingDeleteState__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-12T19:31:46Z")
    },
    "Id" : "test1",
    "RecordTypeId" : "recordType",
    "CA10__disappearanceTime__c" : new Date("2024-06-12T19:31:46Z"),
    "CA10__tableLoggingReadState__c" : "Enabled",
    "CA10__tableLoggingWriteState__c" : "Enabled",
    "CA10__tableLoggingDeleteState__c" : "Enabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-12T19:31:46Z")
    },
    "Id" : "test2",
    "RecordTypeId" : "recordType",
    "CA10__tableLoggingReadState__c" : "",
    "CA10__tableLoggingWriteState__c" : "",
    "CA10__tableLoggingDeleteState__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-12T19:31:46Z")
    },
    "Id" : "test3",
    "RecordTypeId" : "recordType",
    "CA10__tableLoggingReadState__c" : "Disabled",
    "CA10__tableLoggingWriteState__c" : "Disabled",
    "CA10__tableLoggingDeleteState__c" : "Disabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-12T19:31:46Z")
    },
    "Id" : "test4",
    "RecordTypeId" : "recordType",
    "CA10__tableLoggingReadState__c" : "Enabled",
    "CA10__tableLoggingWriteState__c" : "Enabled",
    "CA10__tableLoggingDeleteState__c" : "Enabled"
  } ];
  """;

  CREATE TEMP FUNCTION mock_RecordType()
  RETURNS ARRAY<STRUCT<
      DeveloperName STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-12T19:31:46Z")
    },
    "DeveloperName" : "StorageAccount",
    "Id" : "test1_1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-12T19:31:46Z")
    },
    "DeveloperName" : "StorageAccount",
    "Id" : "test2_1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-12T19:31:46Z")
    },
    "DeveloperName" : "StorageAccount",
    "Id" : "test3_1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-12T19:31:46Z")
    },
    "DeveloperName" : "StorageAccount",
    "Id" : "test4_1"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureStorageAccount__c(
      obj STRUCT<
          Id STRING,
          RecordTypeId STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__tableLoggingReadState__c STRING,
          CA10__tableLoggingWriteState__c STRING,
          CA10__tableLoggingDeleteState__c STRING,
          RecordType STRUCT<
              DeveloperName STRING,
              Id 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 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 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};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__tableLoggingReadState__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__tableLoggingReadState__c.delegatedTo(CA10__tableLoggingReadState__c).isEmpty()", currentStateMessage: "Unable to determine Table Logging Read property. Possible permission issue with Microsoft.Storage/storageAccounts/tableServices/tables/read", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__tableLoggingReadState__c)) {
              throw new Error("UNDETERMINED condition:102", {cause: {status: 'UNDETERMINED', conditionIndex: 102, conditionText: "CA10__tableLoggingReadState__c.isEmpty()", currentStateMessage: "Storage Table Logging is not populated yet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__tableLoggingReadState__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      function fieldChecked7() {
          if (TextLib.isEmpty(obj.CA10__tableLoggingWriteState__c)) {
              throw new Error("UNDETERMINED condition:103", {cause: {status: 'UNDETERMINED', conditionIndex: 103, conditionText: "CA10__tableLoggingWriteState__c.delegatedTo(CA10__tableLoggingWriteState__c).isEmpty()", currentStateMessage: "Unable to determine Table Logging Write property. Possible permission issue with Microsoft.Storage/storageAccounts/tableServices/tables/read", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__tableLoggingWriteState__c)) {
              throw new Error("UNDETERMINED condition:104", {cause: {status: 'UNDETERMINED', conditionIndex: 104, conditionText: "CA10__tableLoggingWriteState__c.isEmpty()", currentStateMessage: "Storage Table Logging is not populated yet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__tableLoggingWriteState__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      function fieldChecked10() {
          if (TextLib.isEmpty(obj.CA10__tableLoggingDeleteState__c)) {
              throw new Error("UNDETERMINED condition:105", {cause: {status: 'UNDETERMINED', conditionIndex: 105, conditionText: "CA10__tableLoggingDeleteState__c.delegatedTo(CA10__tableLoggingDeleteState__c).isEmpty()", currentStateMessage: "Unable to determine Table Logging Delete property. Possible permission issue with Microsoft.Storage/storageAccounts/tableServices/tables/read", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__tableLoggingDeleteState__c)) {
              throw new Error("UNDETERMINED condition:106", {cause: {status: 'UNDETERMINED', conditionIndex: 106, conditionText: "CA10__tableLoggingDeleteState__c.isEmpty()", currentStateMessage: "Storage Table Logging is not populated yet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__tableLoggingDeleteState__c;
      }
      function extract9() { if (!this.out) { this.out = fieldChecked10(); } return this.out; };
      references1.push('Table Logging: Read State [obj.CA10__tableLoggingReadState__c]: ' + obj.CA10__tableLoggingReadState__c);
      references1.push('Table Logging: Write State [obj.CA10__tableLoggingWriteState__c]: ' + obj.CA10__tableLoggingWriteState__c);
      references1.push('Table Logging: Delete State [obj.CA10__tableLoggingDeleteState__c]: ' + obj.CA10__tableLoggingDeleteState__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'Enabled') && TextLib.equal(extract6.call(extract6), 'Enabled') && TextLib.equal(extract9.call(extract9), 'Enabled')) {
              return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__tableLoggingReadState__c') == 'Enabled' && extract('CA10__tableLoggingWriteState__c') == 'Enabled' && extract('CA10__tableLoggingDeleteState__c') == 'Enabled'", currentStateMessage: "Storage Logging for Table Service is enabled.", 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 fieldChecked13() {
          if (TextLib.isEmpty(obj.CA10__tableLoggingReadState__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__tableLoggingReadState__c.delegatedTo(CA10__tableLoggingReadState__c).isEmpty()", currentStateMessage: "Unable to determine Table Logging Read property. Possible permission issue with Microsoft.Storage/storageAccounts/tableServices/tables/read", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__tableLoggingReadState__c)) {
              throw new Error("UNDETERMINED condition:202", {cause: {status: 'UNDETERMINED', conditionIndex: 202, conditionText: "CA10__tableLoggingReadState__c.isEmpty()", currentStateMessage: "Storage Table Logging is not populated yet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__tableLoggingReadState__c;
      }
      function extract12() { if (!this.out) { this.out = fieldChecked13(); } return this.out; };
      function fieldChecked16() {
          if (TextLib.isEmpty(obj.CA10__tableLoggingWriteState__c)) {
              throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "CA10__tableLoggingWriteState__c.delegatedTo(CA10__tableLoggingWriteState__c).isEmpty()", currentStateMessage: "Unable to determine Table Logging Write property. Possible permission issue with Microsoft.Storage/storageAccounts/tableServices/tables/read", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__tableLoggingWriteState__c)) {
              throw new Error("UNDETERMINED condition:204", {cause: {status: 'UNDETERMINED', conditionIndex: 204, conditionText: "CA10__tableLoggingWriteState__c.isEmpty()", currentStateMessage: "Storage Table Logging is not populated yet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__tableLoggingWriteState__c;
      }
      function extract15() { if (!this.out) { this.out = fieldChecked16(); } return this.out; };
      function fieldChecked19() {
          if (TextLib.isEmpty(obj.CA10__tableLoggingDeleteState__c)) {
              throw new Error("UNDETERMINED condition:205", {cause: {status: 'UNDETERMINED', conditionIndex: 205, conditionText: "CA10__tableLoggingDeleteState__c.delegatedTo(CA10__tableLoggingDeleteState__c).isEmpty()", currentStateMessage: "Unable to determine Table Logging Delete property. Possible permission issue with Microsoft.Storage/storageAccounts/tableServices/tables/read", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__tableLoggingDeleteState__c)) {
              throw new Error("UNDETERMINED condition:206", {cause: {status: 'UNDETERMINED', conditionIndex: 206, conditionText: "CA10__tableLoggingDeleteState__c.isEmpty()", currentStateMessage: "Storage Table Logging is not populated yet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__tableLoggingDeleteState__c;
      }
      function extract18() { if (!this.out) { this.out = fieldChecked19(); } return this.out; };
      try {
          if (TextLib.equal(extract12.call(extract12), 'Disabled') || TextLib.equal(extract15.call(extract15), 'Disabled') || TextLib.equal(extract18.call(extract18), 'Disabled')) {
              return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__tableLoggingReadState__c') == 'Disabled' || extract('CA10__tableLoggingWriteState__c') == 'Disabled' || extract('CA10__tableLoggingDeleteState__c') == 'Disabled'", currentStateMessage: "Storage Logging for Table Service is disabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling Storage Logging for read, write, and delete requests.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'UNDETERMINED', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Unexpected value in the field.", 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.Id AS Id,
          sObject.RecordTypeId AS RecordTypeId,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__tableLoggingReadState__c AS CA10__tableLoggingReadState__c,
          sObject.CA10__tableLoggingWriteState__c AS CA10__tableLoggingWriteState__c,
          sObject.CA10__tableLoggingDeleteState__c AS CA10__tableLoggingDeleteState__c,
          STRUCT (
              `RecordType`.DeveloperName AS DeveloperName,
              `RecordType`.Id AS Id
          ) AS RecordType,
          process_CA10__CaAzureStorageAccount__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.RecordTypeId AS RecordTypeId,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__tableLoggingReadState__c AS CA10__tableLoggingReadState__c,
                  sObject.CA10__tableLoggingWriteState__c AS CA10__tableLoggingWriteState__c,
                  sObject.CA10__tableLoggingDeleteState__c AS CA10__tableLoggingDeleteState__c,
                  STRUCT (
                      `RecordType`.DeveloperName AS DeveloperName,
                      `RecordType`.Id AS Id
                  ) AS RecordType
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureStorageAccount__c()) AS sObject
      LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType`
          ON sObject.RecordTypeId = `RecordType`.Id
  ) sObject ON sObject.Id = expectedResult.Id;
