---
policy: /ce/ca/aws/s3/bucket-encryption-with-kms
logic: /ce/ca/aws/s3/bucket-encryption-with-kms/prod.logic.yaml
executionTime: 2025-11-17T14:33:44.983064966Z
generationMs: 73
executionMs: 642
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__serverSideEncryptionAlgorithm__c.delegatedTo(CA10__serverSideEncryptionAlgorithm__c).isEmpty()
      actual: CA10__serverSideEncryptionAlgorithm__c.delegatedTo(CA10__serverSideEncryptionAlgorithm__c).isEmpty()
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__serverSideEncryptionAlgorithm__c') == 'AES256'
      actual: extract('CA10__serverSideEncryptionAlgorithm__c') == 'AES256'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: "setOfText(['aws:kms', 'aws:kms:dsse', 'aws:fsx']).contains(extract('CA10__serverSideEncryptionAlgorithm__c'))"
      actual: "setOfText(['aws:kms', 'aws:kms:dsse', 'aws:fsx']).contains(extract('CA10__serverSideEncryptionAlgorithm__c'))"
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__serverSideEncryptionAlgorithm__c') == 'None'
      actual: extract('CA10__serverSideEncryptionAlgorithm__c') == 'None'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/s3/bucket-encryption-with-kms/policy.yaml
    md5Hash: 97923902BD2694002706025D42B84211
    content: "---\nnames:\n  full: \"AWS S3 Bucket is not encrypted with a KMS key\"\
      \n  contextual: \"Bucket is not encrypted with a KMS key\"\ndescription: >\n\
      \  Ensure that Amazon S3 buckets are configured to use Server-Side Encryption\
      \ with \n  AWS SSE-KMS or DSSE-KMS to protect data at rest. Using SSE-KMS or\
      \ DSSE-KMS provides \n  an auditable trail of key usage and allows for centralized\
      \ management of encryption keys.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n\
      \  - \"SECURITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/data-encryption\"\
      \n  - \"/frameworks/aws-well-architected/sec/08/02\"\n  - \"/frameworks/aws-well-architected/sec/08/03\"\
      \n  - \"/frameworks/nist-sp-800-53-r5/sc/12/02\"\n  - \"/frameworks/nist-sp-800-53-r5/cm/03/06\"\
      \n  - \"/frameworks/nist-sp-800-53-r5/sc/13\"\n  - \"/frameworks/nist-sp-800-53-r5/sc/28\"\
      \n  - \"/frameworks/nist-sp-800-53-r5/sc/28/01\"\n  - \"/frameworks/nist-sp-800-53-r5/sc/07/10\"\
      \n  - \"/frameworks/nist-sp-800-53-r5/ca/09/01\"\n  - \"/frameworks/nist-sp-800-53-r5/si/07/06\"\
      \n  - \"/frameworks/nist-sp-800-53-r5/au/09\"\n  - \"/frameworks/pci-dss-v4.0.1/03/05/01\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[S3.17] S3 general purpose\
      \ buckets should be encrypted at rest with AWS KMS keys\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/s3-controls.html#s3-17\""
  - path: /ce/ca/aws/s3/bucket-encryption-with-kms/prod.logic.yaml
    md5Hash: D2609030CA982603DD484B94867D1C2B
    content: |-
      ---
      inputType: "CA10__CaAwsBucket__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsBucket__c/object.extracts.yaml"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The S3 bucket is not encrypted."
          remediationMessage: "Enable Server-Side Encryption with AWS KMS (SSE-KMS) for the bucket."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__serverSideEncryptionAlgorithm__c"
              right:
                TEXT: "None"
        - status: "INCOMPLIANT"
          currentStateMessage: "The S3 bucket is encrypted with Amazon S3 managed key."
          remediationMessage: "Enable Server-Side Encryption with AWS KMS for the bucket."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__serverSideEncryptionAlgorithm__c"
              right:
                TEXT: "AES256"
        - status: "COMPLIANT"
          currentStateMessage: "The S3 Bucket is encrypted with a KMS key."
          check:
            CONTAINS:
              arg:
                SET:
                  itemType: "TEXT"
                  items:
                    - "aws:kms"
                    - "aws:kms:dsse"
                    - "aws:fsx"
              search:
                EXTRACT: "CA10__serverSideEncryptionAlgorithm__c"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /ce/ca/aws/s3/bucket-encryption-with-kms/test-data.json
    md5Hash: 9A6DD93684DBF2599F1F46923F53E475
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-07T07:24:22Z"
              },
              "CA10__disappearanceTime__c": "2025-08-06T13:01:39Z",
              "CA10__serverSideEncryptionAlgorithm__c": "AES256",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "101",
                  "conditionText": "CA10__serverSideEncryptionAlgorithm__c.delegatedTo(CA10__serverSideEncryptionAlgorithm__c).isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-07T07:24:22Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__serverSideEncryptionAlgorithm__c": "",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__serverSideEncryptionAlgorithm__c') == 'AES256'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-07T07:24:22Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__serverSideEncryptionAlgorithm__c": "AES256",
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "setOfText(['aws:kms', 'aws:kms:dsse', 'aws:fsx']).contains(extract('CA10__serverSideEncryptionAlgorithm__c'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-07T07:24:22Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__serverSideEncryptionAlgorithm__c": "aws:kms",
              "Id": "test4"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__serverSideEncryptionAlgorithm__c') == 'None'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-07T07:24:22Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__serverSideEncryptionAlgorithm__c": "None",
              "Id": "test5"
          }
      ]
  - path: /types/CA10__CaAwsBucket__c/object.extracts.yaml
    md5Hash: 735E25ECFC64FFE2D2C1E0F83B2D8FCA
    content: "---\nextracts:\n# Values: yes, no. Not Nullable.\n  - name: \"CA10__objectLockEnabled__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__objectLockEnabled__c\"\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__objectLockEnabled__c\"\n            currentStateMessage: \"Unable to determine\
      \ Object Lock status. Possible permission issue with s3:GetObjectLockConfiguration\"\
      \n          isEmpty: \"Object Lock status is not populated yet\"\n# Nullable.\n\
      \  - name: \"CA10__lifecycleRulesJson__c\"\n    value: \n      FIELD:\n    \
      \    path: \"CA10__lifecycleRulesJson__c\"\n        returnType: BYTES\n    \
      \    # undeterminedIf:\n        #   noAccessDelegate:\n        #     path: \"\
      CA10__lifecycleRulesJson__c\"\n        #     currentStateMessage: \"Unable to\
      \ determine Lifecycle Configuration. Possible permission issue with s3:GetLifecycleConfiguration\"\
      \n# Values: enabled, suspended, off. Not Nullable.\n  - name: \"CA10__versioningStatus__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__versioningStatus__c\"\n \
      \       undeterminedIf:\n          noAccessDelegate:\n            path: \"CA10__versioningStatus__c\"\
      \n            currentStateMessage: \"Unable to determine versioning status.\
      \ Possible permission issue with s3:GetBucketVersioning\"\n          isEmpty:\
      \ \"Status is not populated yet\"\n# Checkbox.\n  - name: \"CA10__versioningMfaDeleteEnabled__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__versioningMfaDeleteEnabled__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__versioningStatus__c\"\n            currentStateMessage: \"Unable to determine\
      \ versioning status. Possible permission issue with s3:GetBucketVersioning\"\
      \n# The field can be empty if server access logging is not enabled\n  - name:\
      \ \"CA10__loggingDestinationBucketName__c\"\n    value: \n      FIELD:\n   \
      \     path: \"CA10__loggingDestinationBucketName__c\"\n        # undeterminedIf:\n\
      \        #   noAccessDelegate:\n        #     path: \"CA10__loggingDestinationBucketName__c\"\
      \n        #     currentStateMessage: \"Unable to determine if server access\
      \ logging is enabled. Possible permission issue with s3:GetBucketLogging\"\n\
      # Cloudaware derives this field from CA10__loggingDestinationBucketName__c\n\
      \  - name: \"CA10__loggingDestinationBucketArn__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__loggingDestinationBucketArn__c\"\n        undeterminedIf:\n\
      \          noAccessDelegate:\n            path: \"CA10__loggingDestinationBucketName__c\"\
      \n            currentStateMessage: \"Unable to determine if server access logging\
      \ is enabled. Possible permission issue with s3:GetBucketLogging\"\n# This is\
      \ a look up on CA10__CaAwsBucket__c derived from CA10__loggingDestinationBucketName__c\n\
      \  - name: \"CA10__loggingDestinationBucket__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__loggingDestinationBucket__c\"\n        undeterminedIf:\n\
      \          noAccessDelegate:\n            path: \"CA10__loggingDestinationBucketName__c\"\
      \n            currentStateMessage: \"Unable to determine if server access logging\
      \ is enabled. Possible permission issue with s3:GetBucketLogging\"\n  - name:\
      \ \"CA10__arn__c\"\n    value: \n      FIELD:\n        path: \"CA10__arn__c\"\
      \n        undeterminedIf:\n          isEmpty: \"Bucket ARN cannot be empty.\
      \ Potential data corruption\"\n  - name: \"caJsonFrom__lifecycleRulesJson__c\"\
      \n    value: \n      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__lifecycleRulesJson__c\"\
      \n        undeterminedIf:\n          isInvalid: \"S3 Bucket Lifecycle Rules\
      \ JSON is invalid.\"\n# Returns BOOLEAN true if number of enabled lifecycle\
      \ rules more than 0 otherwise returns false\n  - name: \"caJsonBoolean__lifecycleRulesJsonStatusEnabled__c\"\
      \n    value: \n      JSON_QUERY_BOOLEAN:\n        arg: \n          EXTRACT:\
      \ \"caJsonFrom__lifecycleRulesJson__c\"\n        expression: \"length([?status=='Enabled'])\
      \ > `0`\"\n        undeterminedIf: \n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ a boolean.\"\n  - name: \"CA10__blockPublicAcls__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__blockPublicAcls__c\"\n        undeterminedIf:\n     \
      \     noAccessDelegate:\n            path: \"CA10__blockPublicAcls__c\"\n  \
      \          currentStateMessage: \"Unable to determine the bucket policy. Possible\
      \ permission issue with s3:GetBucketPublicAccessBlock\"\n  - name: \"CA10__blockPublicPolicy__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__blockPublicPolicy__c\"\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__blockPublicPolicy__c\"\n            currentStateMessage: \"Unable to determine\
      \ the bucket policy. Possible permission issue with s3:GetBucketPublicAccessBlock\"\
      \n  - name: \"CA10__ignorePublicAcls__c\"\n    value: \n      FIELD:\n     \
      \   path: \"CA10__ignorePublicAcls__c\"\n        undeterminedIf:\n         \
      \ noAccessDelegate:\n            path: \"CA10__ignorePublicAcls__c\"\n     \
      \       currentStateMessage: \"Unable to determine the bucket policy. Possible\
      \ permission issue with s3:GetBucketPublicAccessBlock\"\n  - name: \"CA10__restrictPublicBuckets__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__restrictPublicBuckets__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__restrictPublicBuckets__c\"\n            currentStateMessage: \"Unable\
      \ to determine the bucket policy. Possible permission issue with s3:GetBucketPublicAccessBlock\"\
      \n# Nullable.\n  - name: \"CA10__policyDocument__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__policyDocument__c\"\n        returnType: BYTES\n    \
      \    # undeterminedIf:\n        #   noAccessDelegate:\n        #     path: \"\
      CA10__policyDocument__c\"\n        #     currentStateMessage: \"Unable to determine\
      \ the bucket policy. Possible permission issue with s3:GetBucketPolicy\"\n \
      \ - name: \"caJsonFrom__policyDocument__c\"\n    value: \n      JSON_FROM:\n\
      \        arg: \n          EXTRACT: \"CA10__policyDocument__c\"\n        undeterminedIf:\n\
      \          isInvalid: \"S3 Bucket Policy Document JSON is invalid.\"\n# Nullable.\n\
      \  - name: \"CA10__intelligentTieringConfigurationsJson__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__intelligentTieringConfigurationsJson__c\"\
      \n        returnType: BYTES\n  - name: \"caJsonFrom__intelligentTieringConfigurationsJson__c\"\
      \n    value: \n      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__intelligentTieringConfigurationsJson__c\"\
      \n        undeterminedIf:\n          isInvalid: \"S3 Bucket Policy Document\
      \ JSON is invalid.\"\n# Nullable.\n  - name: \"CA10__regionName__c\"\n    value:\n\
      \      FIELD:\n        path: \"CA10__regionName__c\"\n# Nullable.\n  - name:\
      \ \"CA10__intelligentTieringStorageGb__c\"\n    value:\n      FIELD:\n     \
      \   path: \"CA10__intelligentTieringStorageGb__c\"\n# Values: AES256 | aws:fsx\
      \ | aws:kms | aws:kms:dsse | None. Not Nullable.\n  - name: \"CA10__serverSideEncryptionAlgorithm__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__serverSideEncryptionAlgorithm__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__serverSideEncryptionAlgorithm__c\"\n            currentStateMessage: \"\
      Unable to determine Bucket Encryption Algorithm. Possible permissions issue\
      \ with s3:GetEncryptionConfiguration\"\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" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "101",
      "conditionText" : "CA10__serverSideEncryptionAlgorithm__c.delegatedTo(CA10__serverSideEncryptionAlgorithm__c).isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__serverSideEncryptionAlgorithm__c') == 'AES256'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "setOfText(['aws:kms', 'aws:kms:dsse', 'aws:fsx']).contains(extract('CA10__serverSideEncryptionAlgorithm__c'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__serverSideEncryptionAlgorithm__c') == 'None'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsBucket__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__serverSideEncryptionAlgorithm__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-11-07T07:24:22Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-08-06T13:01:39Z"),
    "CA10__serverSideEncryptionAlgorithm__c" : "AES256",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-07T07:24:22Z")
    },
    "CA10__serverSideEncryptionAlgorithm__c" : "",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-07T07:24:22Z")
    },
    "CA10__serverSideEncryptionAlgorithm__c" : "AES256",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-07T07:24:22Z")
    },
    "CA10__serverSideEncryptionAlgorithm__c" : "aws:kms",
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-07T07:24:22Z")
    },
    "CA10__serverSideEncryptionAlgorithm__c" : "None",
    "Id" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsBucket__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__serverSideEncryptionAlgorithm__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
  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 BytesLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg;
      };
      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 CollectionLib = new function () {
      this.parse = function(arg, separator, skipEmpty, skipDuplicates, sort, normalize) {
          if (arg == null) return [];
          let parts = arg.split(separator);
          return this.fromArray(parts, skipEmpty, skipDuplicates, sort, normalize);
      };
      this.fromArray = function(arr, skipEmpty, skipDuplicates, sort, normalize) {
          if (arr == null) return [];
          let result = [];
          let seen = new Set();
          arr.forEach(el => {
              let normalized = normalize ? TextLib.normalize(el) : BytesLib.normalize(el);
              if (!skipEmpty || (normalize ? TextLib.isNotEmpty(el) : BytesLib.isNotEmpty(el))) {
                  if (!skipDuplicates || !seen.has(normalized)) {
                      if (skipDuplicates) seen.add(normalized);
                      result.push(normalized);
                  }
              }
          });
          if (sort) result.sort();
          return result;
      };
      this.equal = function(left, right) {
          left = left == null ? [] : left;
          right = right == null ? [] : right;
          if (left.length !== right.length) return false;
          for (let i = 0; i < left.length; i++) {
              if (left[i] !== right[i]) return false;
          }
          return true;
      };
      this.notEqual = function(left, right) {
          return !this.equal(left, right);
      };
      this.size = function(collection) {
          return collection == null ? 0 : collection.length;
      };
      this.startsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[0] === normalizedSearch;
      };
      this.endsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[collection.length - 1] === normalizedSearch;
      };
      this.contains = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          return collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search));
      };
      this.containsAll = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.every(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
      this.containsAny = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.some(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [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__serverSideEncryptionAlgorithm__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__serverSideEncryptionAlgorithm__c.delegatedTo(CA10__serverSideEncryptionAlgorithm__c).isEmpty()", currentStateMessage: "Unable to determine Bucket Encryption Algorithm. Possible permissions issue with s3:GetEncryptionConfiguration", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__serverSideEncryptionAlgorithm__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Server Side Encryption Algorithm [obj.CA10__serverSideEncryptionAlgorithm__c]: ' + obj.CA10__serverSideEncryptionAlgorithm__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'None')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__serverSideEncryptionAlgorithm__c') == 'None'", currentStateMessage: "The S3 bucket is not encrypted.", currentStateReferences: references1.join('\n'), remediation: "Enable Server-Side Encryption with AWS KMS (SSE-KMS) for the bucket.", 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__serverSideEncryptionAlgorithm__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__serverSideEncryptionAlgorithm__c.delegatedTo(CA10__serverSideEncryptionAlgorithm__c).isEmpty()", currentStateMessage: "Unable to determine Bucket Encryption Algorithm. Possible permissions issue with s3:GetEncryptionConfiguration", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__serverSideEncryptionAlgorithm__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      try {
          if (TextLib.equal(extract6.call(extract6), 'AES256')) {
              return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__serverSideEncryptionAlgorithm__c') == 'AES256'", currentStateMessage: "The S3 bucket is encrypted with Amazon S3 managed key.", currentStateReferences: references1.join('\n'), remediation: "Enable Server-Side Encryption with AWS KMS for the bucket.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[3], conditionIndex:[300..399]
      function fieldChecked10() {
          if (TextLib.isEmpty(obj.CA10__serverSideEncryptionAlgorithm__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10__serverSideEncryptionAlgorithm__c.delegatedTo(CA10__serverSideEncryptionAlgorithm__c).isEmpty()", currentStateMessage: "Unable to determine Bucket Encryption Algorithm. Possible permissions issue with s3:GetEncryptionConfiguration", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__serverSideEncryptionAlgorithm__c;
      }
      function extract9() { if (!this.out) { this.out = fieldChecked10(); } return this.out; };
      try {
          if (CollectionLib.contains(CollectionLib.fromArray(['aws:kms', 'aws:kms:dsse', 'aws:fsx'], true, true, true, true), extract9.call(extract9), true)) {
              return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "setOfText(['aws:kms', 'aws:kms:dsse', 'aws:fsx']).contains(extract('CA10__serverSideEncryptionAlgorithm__c'))", currentStateMessage: "The S3 Bucket is encrypted with a KMS key.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unexpected values 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__serverSideEncryptionAlgorithm__c AS CA10__serverSideEncryptionAlgorithm__c,
          sObject.Id AS Id,
          process_CA10__CaAwsBucket__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__serverSideEncryptionAlgorithm__c AS CA10__serverSideEncryptionAlgorithm__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsBucket__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
