---
policy: /ce/ca/aws/s3/bucket-public-policy
logic: /ce/ca/aws/s3/bucket-public-policy/prod.logic.yaml
executionTime: 2025-11-20T13:28:59.335004485Z
generationMs: 62
executionMs: 646
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: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__policyIsPublic__c') != 'Yes'
      actual: extract('CA10__policyIsPublic__c') != 'Yes'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__blockPublicPolicy__c') == 'Yes'
      actual: extract('CA10__blockPublicPolicy__c') == 'Yes'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject,\
        \ s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])"
      actual: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject,\
        \ s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])"
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject,\
        \ s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])"
      actual: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject,\
        \ s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])"
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:ListBucket,\
        \ s3:GetObject, s3:GetObjectVersion])"
      actual: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:ListBucket,\
        \ s3:GetObject, s3:GetObjectVersion])"
    runtimeError: {}
  - id: test7
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 500
      actual: 500
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test8
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject,\
        \ s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])"
      actual: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject,\
        \ s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])"
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/s3/bucket-public-policy/policy.yaml
    md5Hash: B62FF81E400345859A590AA6997A1ABD
    content: "---\nnames:\n  full: \"AWS S3 Bucket Policy allows public read or write\
      \ access\"\n  contextual: \"Bucket Policy allows public read or write access\"\
      \ndescription: >\n  S3 bucket policies should not grant public read or write\
      \ permissions. Allowing \n  principals like '*' (everyone) can lead to unintended\
      \ data exposure, \n  modification, or deletion, posing a significant security\
      \ risk.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/resource-security/public-and-anonymous-access\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/s3/02\"\n  - \"/frameworks/aws-fsbp-v1.0.0/s3/03\"\
      \n  - \"/frameworks/aws-well-architected/sec/08/04\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[S3.2] S3 general purpose buckets should block public read access\"\
      \n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/s3-controls.html#s3-2\"\
      \n    - name: \"[S3.3] S3 general purpose buckets should block public write\
      \ access\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/s3-controls.html#s3-3\""
  - path: /ce/ca/aws/s3/bucket-public-policy/prod.logic.yaml
    md5Hash: BDEBE5D7D804919A894AB2E4D20DB9C2
    content: |
      ---
      inputType: "CA10__CaAwsBucket__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsBucket__c/object.extracts.yaml"
      conditions:
        - status: "COMPLIANT"
          currentStateMessage: "The bucket policy is not public."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: CA10__policyIsPublic__c
              right:
                TEXT: "Yes"
        - status: "COMPLIANT"
          currentStateMessage: "The Bucket policy is public but the block public policy configuration is enabled."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__blockPublicPolicy__c
              right:
                TEXT: "Yes"
        - status: "INCOMPLIANT"
          currentStateMessage: "The bucket policy grants public write access to the bucket data."
          remediationMessage: "Consider removing the public write access from the bucket."
          check:
            AWS_POLICY_ALLOWS:
              widestAcceptableAccessLevel: "EXTERNAL_PRINCIPAL"
              policyExtField: "CA10__policyDocumentExt__c"
              actions:
                - "s3:PutObject"
                - "s3:DeleteObject"
                - "s3:DeleteObjectVersion"
                - "s3:PutObjectAcl"
                - "s3:PutBucketAcl"
                - "s3:PutBucketPolicy"
        - status: "INCOMPLIANT"
          currentStateMessage: "The bucket policy grants public read access to the bucket data."
          remediationMessage: "Consider removing the public read access from the bucket."
          check:
            AWS_POLICY_ALLOWS:
              widestAcceptableAccessLevel: "EXTERNAL_PRINCIPAL"
              policyExtField: "CA10__policyDocumentExt__c"
              actions:
                - "s3:ListBucket"
                - "s3:GetObject"
                - "s3:GetObjectVersion"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The Bucket policy does not grant public read or write access to the bucket data."
  - path: /ce/ca/aws/s3/bucket-public-policy/test-data.json
    md5Hash: BB67B151D64F1FE0A0DC4B70CCC95169
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-17T13:19:58Z"
              },
              "CA10__disappearanceTime__c": "2025-08-06T13:01:39Z",
              "CA10__policyIsPublic__c": "No Policy",
              "CA10__blockPublicPolicy__c": "Yes",
              "CA10__policyDocumentExt__c": "",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__policyIsPublic__c') != 'Yes'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-17T13:19:58Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__policyIsPublic__c": "No Policy",
              "CA10__blockPublicPolicy__c": "Yes",
              "CA10__policyDocumentExt__c": "",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__blockPublicPolicy__c') == 'Yes'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-17T13:19:58Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__policyIsPublic__c": "Yes",
              "CA10__blockPublicPolicy__c": "Yes",
              "CA10__policyDocumentExt__c": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:PutObject\",\"s3:GetObject\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject, s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-17T13:19:58Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__policyIsPublic__c": "Yes",
              "CA10__blockPublicPolicy__c": "No",
              "CA10__policyDocumentExt__c": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:Put*\",\"s3:Get*\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
              "Id": "test4"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject, s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-17T13:19:58Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__policyIsPublic__c": "Yes",
              "CA10__blockPublicPolicy__c": "No",
              "CA10__policyDocumentExt__c": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:Put*\",\"s3:Delete*\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
              "Id": "test5"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:ListBucket, s3:GetObject, s3:GetObjectVersion])",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-17T13:19:58Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__policyIsPublic__c": "Yes",
              "CA10__blockPublicPolicy__c": "No",
              "CA10__policyDocumentExt__c": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:List*\",\"s3:Get*\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
              "Id": "test6"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "500",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-17T13:19:58Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__policyIsPublic__c": "Yes",
              "CA10__blockPublicPolicy__c": "No",
              "CA10__policyDocumentExt__c": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::id:role/iam-role\"},\"Action\":[\"s3:List*\",\"s3:Get*\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"EXTERNAL_PRINCIPAL\",\"reason\":\"\"}}]}",
              "Id": "test7"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject, s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-11-17T13:19:58Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__policyIsPublic__c": "Yes",
              "CA10__blockPublicPolicy__c": "No",
              "CA10__policyDocumentExt__c": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
              "Id": "test8"
          }
      ]
  - path: /types/CA10__CaAwsBucket__c/object.extracts.yaml
    md5Hash: F56AFA293B0B19D4F39C1EBB70F4C56F
    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  - name: \"CA10__accessControlPolicy__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__accessControlPolicy__c\"\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__accessControlPolicy__c\"\n            currentStateMessage: \"Unable to\
      \ determine the bucket ACL. Possible permission issue with s3:GetBucketAcl\"\
      \n  - name: \"caJsonFrom__accessControlPolicy__c\"\n    value: \n      JSON_FROM:\n\
      \        arg:\n          EXTRACT: \"CA10__accessControlPolicy__c\"\n       \
      \ undeterminedIf:\n          isInvalid: \"The Access Control Policy JSON is\
      \ invalid.\"\n  - name: \"CA10__accessControlGrants__c\"\n    value: \n    \
      \  FIELD:\n        path: \"CA10__accessControlGrants__c\"\n        undeterminedIf:\n\
      \          noAccessDelegate:\n            path: \"CA10__accessControlGrants__c\"\
      \n            currentStateMessage: \"Unable to determine the bucket ACL. Possible\
      \ permission issue with s3:GetBucketAcl\"\n  - name: \"CA10__policyIsPublic__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__policyIsPublic__c\"\n   \
      \     undeterminedIf:\n          noAccessDelegate:\n            path: \"CA10__policyIsPublic__c\"\
      \n            currentStateMessage: \"Unable to determine the bucket policy status.\
      \ Possible permission issue with s3:GetBucketPolicyStatus\"\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" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__policyIsPublic__c') != 'Yes'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__blockPublicPolicy__c') == 'Yes'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject, s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject, s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:ListBucket, s3:GetObject, s3:GetObjectVersion])",
      "runtimeError" : null
    }
  }, {
    "Id" : "test7",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "500",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test8",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject, s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsBucket__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__policyIsPublic__c STRING,
      CA10__blockPublicPolicy__c STRING,
      CA10__policyDocumentExt__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-11-17T13:19:58Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-08-06T13:01:39Z"),
    "CA10__policyIsPublic__c" : "No Policy",
    "CA10__blockPublicPolicy__c" : "Yes",
    "CA10__policyDocumentExt__c" : "",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-17T13:19:58Z")
    },
    "CA10__policyIsPublic__c" : "No Policy",
    "CA10__blockPublicPolicy__c" : "Yes",
    "CA10__policyDocumentExt__c" : "",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-17T13:19:58Z")
    },
    "CA10__policyIsPublic__c" : "Yes",
    "CA10__blockPublicPolicy__c" : "Yes",
    "CA10__policyDocumentExt__c" : "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:PutObject\",\"s3:GetObject\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-17T13:19:58Z")
    },
    "CA10__policyIsPublic__c" : "Yes",
    "CA10__blockPublicPolicy__c" : "No",
    "CA10__policyDocumentExt__c" : "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:Put*\",\"s3:Get*\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-17T13:19:58Z")
    },
    "CA10__policyIsPublic__c" : "Yes",
    "CA10__blockPublicPolicy__c" : "No",
    "CA10__policyDocumentExt__c" : "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:Put*\",\"s3:Delete*\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
    "Id" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-17T13:19:58Z")
    },
    "CA10__policyIsPublic__c" : "Yes",
    "CA10__blockPublicPolicy__c" : "No",
    "CA10__policyDocumentExt__c" : "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:List*\",\"s3:Get*\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
    "Id" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-17T13:19:58Z")
    },
    "CA10__policyIsPublic__c" : "Yes",
    "CA10__blockPublicPolicy__c" : "No",
    "CA10__policyDocumentExt__c" : "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::id:role/iam-role\"},\"Action\":[\"s3:List*\",\"s3:Get*\"],\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"EXTERNAL_PRINCIPAL\",\"reason\":\"\"}}]}",
    "Id" : "test7"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-17T13:19:58Z")
    },
    "CA10__policyIsPublic__c" : "Yes",
    "CA10__blockPublicPolicy__c" : "No",
    "CA10__policyDocumentExt__c" : "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":[\"*\"],\"AnalyzedResult\":{\"accessLevel\":\"ANONYMOUS_PRINCIPAL\",\"reason\":\"All principals '*' do not restrict access\"}}]}",
    "Id" : "test8"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsBucket__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__policyIsPublic__c STRING,
          CA10__blockPublicPolicy__c STRING,
          CA10__policyDocumentExt__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 AwsPolicyAllows = new function () {
      function accessLevelOrdinal(accessLevel) {
          if (accessLevel === 'NOBODY') {
              return 0;
          } else if (accessLevel === 'SAME_ACCOUNT') {
              return 1;
          } else if (accessLevel === 'SAME_ORG') {
              return 2;
          } else if (accessLevel === 'TRUSTED_PRINCIPAL') {
              return 3;
          } else if (accessLevel === 'AWS_SERVICE') {
              return 4;
          } else if (accessLevel === 'EXTERNAL_PRINCIPAL') {
              return 5;
          } else if (accessLevel === 'ANONYMOUS_PRINCIPAL') {
              return 6;
          } else {
              return 7;
          }
      }
      function ensureArray(obj) {
          if (obj == null) {
              return [];
          } else if (Array.isArray(obj)) {
              return obj;
          } else {
              return [obj];
          }
      }
      function arrayExec(obj, func) {
          if (obj == null) {
              return false;
          } else if (Array.isArray(obj)) {
              for (var i = 0; i < obj.length; i++) {
                  if (func(obj[i], i)) {
                      return true;
                  }
              }
              return false;
          } else {
              return func(obj, 0);
          }
      }
      function wildcardMatches(text, pattern) {
          if (pattern.indexOf("*") === -1) {
              return text.toLowerCase() === pattern.toLowerCase();
          }
          var regex = new RegExp("^" + pattern.toLowerCase().replaceAll("*", ".*") + "$");
          return regex.test(text.toLowerCase());
      }
      function isActionMatches(action, statement) {
          if (statement.Action) {
              let matches = false;
              arrayExec(statement.Action, function (statementAction) {
                  if (wildcardMatches(action, statementAction)) {
                      matches = true;
                      // break;
                      return true;
                  }
              });
              return matches;
          } else if (statement.NotAction) {
              let matches = false;
              arrayExec(statement.NotAction, function (statementAction) {
                  if (wildcardMatches(action, statementAction)) {
                      matches = true;
                      // break;
                      return true;
                  }
              });
              return !matches;
          }
      }
      function allowResources(openedResources, statement, statementIndex) {
          if (statement.Resource) {
              arrayExec(statement.Resource, function (resource) {
                  openedResources.push({
                      allowType: "R",
                      allowResource: resource,
                      allowStatement: statementIndex,
                      accessLevel: statement.AnalyzedResult.accessLevel,
                      accessLevelOrdinal: accessLevelOrdinal(statement.AnalyzedResult.accessLevel)
                  });
              });
          } else if (statement.NotResource) {
              arrayExec(statement.NotResource, function (resource) {
                  openedResources.push({
                      allowType: "NR",
                      allowResource: resource,
                      allowStatement: statementIndex,
                      accessLevel: statement.AnalyzedResult.accessLevel,
                      accessLevelOrdinal: accessLevelOrdinal(statement.AnalyzedResult.accessLevel)
                  });
              });
          }
      }
      function denyResources(openedResources, statement, statementIndex) {
          var denyType, list;
          if (statement.Resource) {
              denyType = "R";
              list = statement.Resource;
          } else if (statement.NotResource) {
              denyType = "NR";
              list = statement.NotResource;
          } else {
              return;
          }
          var closingAccessLevelOrdinal = accessLevelOrdinal(statement.AnalyzedResult.accessLevel);
          arrayExec(list, function (resource) {
              for (var i = 0; i < openedResources.length; i++) {
                  var openedResource = openedResources[i];
                  if (openedResource.accessLevelOrdinal <= closingAccessLevelOrdinal) {
                      // there is no sense processing deny if it is more widely open than the original allow
                      continue;
                  }
                  if (openedResource.allowType === denyType) {
                      if (wildcardMatches(openedResource.allowResource, resource)) {
                          //
                          openedResource.denyStatement = statementIndex;
                          openedResource.denyType = denyType;
                          openedResource.denyResource = resource;
                          openedResource.accessLevel = statement.AnalyzedResult.accessLevel;
                          openedResource.accessLevelOrdinal = closingAccessLevelOrdinal;
                      }
                  } else {
                      if (!wildcardMatches(openedResource.allowResource, resource)) {
                          //
                          openedResource.denyStatement = statementIndex;
                          openedResource.denyType = denyType;
                          openedResource.denyResource = resource;
                          openedResource.accessLevel = statement.AnalyzedResult.accessLevel;
                          openedResource.accessLevelOrdinal = closingAccessLevelOrdinal;
                      }
                  }
              }
          });
      }
      function calculateSingleAccess(policyExt, action) {
          var openedResources = [];
          var result;
          arrayExec(policyExt.Statement, function (statement, statementIndex) {
              if (statement.Effect !== 'Allow') {
                  // we're accumulating only what's allowed
                  return false; // continue;
              }
              if (statement.AnalyzedResult == null) {
                  // we can't analyze the policy without pre-analysis done on the CMDB side
                  result = {
                      accessLevelOrdinal: accessLevelOrdinal("ANONYMOUS_PRINCIPAL"),
                      accessLevel: "ANONYMOUS_PRINCIPAL",
                      reason: 'There is no analyzed result for a statement #' + (statementIndex + 1)
                  };
                  return true; // break;
              }
              if (isActionMatches(action, statement)) {
                  allowResources(openedResources, statement, statementIndex);
              }
          });
          if (result) {
              return [result];
          }
          if (openedResources.length == 0) {
              return [{
                  accessLevelOrdinal: accessLevelOrdinal("NOBODY"),
                  accessLevel: "NOBODY",
                  reason: "Action " + action + " is implicitly denied. None of the statements are matching this action."
              }];
          }
          arrayExec(policyExt.Statement, function (statement, statementIndex) {
              if (statement.Effect !== 'Deny') {
                  // we're accumulating only what's denied
                  return false; // continue;
              }
              if (statement.AnalyzedResult == null) {
                  // we can't analyze the policy without pre-analysis done on the CMDB side
                  result = {
                      accessLevelOrdinal: accessLevelOrdinal("ANONYMOUS_PRINCIPAL"),
                      accessLevel: "ANONYMOUS_PRINCIPAL",
                      reason: 'There is no analyzed result for a statement #' + (statementIndex + 1)
                  };
                  return true; // break;
              }
              if (isActionMatches(action, statement)) {
                  denyResources(openedResources, statement, statementIndex);
              }
          });
          if (result) {
              return [result];
          }
          /**
           * чтобы "закрыть" Allow тебе нужно
           * 1) иметь accessLevel уже чем у Allow
           * 2) закрыть все Resource у Allow своими, которые в Deny
           */
          return openedResources;
      }
      function resourceAccessibleBy(openedResources, widestAcceptableAccessLevel) {
          var ordinal = accessLevelOrdinal(widestAcceptableAccessLevel);
          return openedResources.filter(openedResource => openedResource.accessLevelOrdinal > ordinal);
      }
      this.calculateAccess = function(policyExt, actions, widestAcceptableAccessLevel) {
          var openedResources = [];
          arrayExec(actions, function (action) {
              var actionResult = calculateSingleAccess(policyExt, action);
              if (Array.isArray(actionResult)) {
                  var filtered = resourceAccessibleBy(actionResult, widestAcceptableAccessLevel);
                  if (filtered.length > 0) {
                      var lowestLevel = null;
                      arrayExec(filtered, function (resource) {
                          if (lowestLevel == null) {
                              lowestLevel = resource.accessLevel;
                          } else {
                              var resourceAccessLevelOrdinal = accessLevelOrdinal(resource.accessLevel);
                              var lowestLevelOrdinal = accessLevelOrdinal(lowestLevel);
                              if (resourceAccessLevelOrdinal > lowestLevelOrdinal) {
                                  lowestLevel = resource.accessLevel;
                              }
                          }
                      });
                      openedResources.push({
                          action: action,
                          accessLevel: lowestLevel,
                          accessLevelOrdinal: accessLevelOrdinal(lowestLevel),
                          reason: 'Policy allows action ' + action + ' with access level up to ' + lowestLevel,
                          openedResources: filtered
                      });
                  }
              } else {
                  actionResult.action = action;
                  openedResources.push(actionResult);
              }
          });
          return openedResources;
      }
  }();
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From 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__policyIsPublic__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__policyIsPublic__c.delegatedTo(CA10__policyIsPublic__c).isEmpty()", currentStateMessage: "Unable to determine the bucket policy status. Possible permission issue with s3:GetBucketPolicyStatus", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__policyIsPublic__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Policy Is Public [obj.CA10__policyIsPublic__c]: ' + obj.CA10__policyIsPublic__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'Yes')) {
              return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__policyIsPublic__c') != 'Yes'", currentStateMessage: "The bucket policy is not public.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function fieldChecked7() {
          if (TextLib.isEmpty(obj.CA10__blockPublicPolicy__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__blockPublicPolicy__c.delegatedTo(CA10__blockPublicPolicy__c).isEmpty()", currentStateMessage: "Unable to determine the bucket policy. Possible permission issue with s3:GetBucketPublicAccessBlock", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__blockPublicPolicy__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      references1.push('Block Public Policy [obj.CA10__blockPublicPolicy__c]: ' + obj.CA10__blockPublicPolicy__c);
      try {
          if (TextLib.equal(extract6.call(extract6), 'Yes')) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__blockPublicPolicy__c') == 'Yes'", currentStateMessage: "The Bucket policy is public but the block public policy configuration 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[3], conditionIndex:[300..399]
      function awsPolicyAllows10() {
          var policyExt9 = obj.CA10__policyDocumentExt__c;
          if (policyExt9 === '') {
              policyExt9 = '{}';
          }
          var calculated8 = AwsPolicyAllows.calculateAccess(JSON.parse(policyExt9), ['s3:PutObject', 's3:DeleteObject', 's3:DeleteObjectVersion', 's3:PutObjectAcl', 's3:PutBucketAcl', 's3:PutBucketPolicy'], 'EXTERNAL_PRINCIPAL');
          return calculated8.length > 0;
      }
      try {
          if (awsPolicyAllows10()) {
              return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:PutObject, s3:DeleteObject, s3:DeleteObjectVersion, ... 3 elements])", currentStateMessage: "The bucket policy grants public write access to the bucket data.", currentStateReferences: references1.join('\n'), remediation: "Consider removing the public write access from the bucket.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[4], conditionIndex:[400..499]
      function awsPolicyAllows13() {
          var policyExt12 = obj.CA10__policyDocumentExt__c;
          if (policyExt12 === '') {
              policyExt12 = '{}';
          }
          var calculated11 = AwsPolicyAllows.calculateAccess(JSON.parse(policyExt12), ['s3:ListBucket', 's3:GetObject', 's3:GetObjectVersion'], 'EXTERNAL_PRINCIPAL');
          return calculated11.length > 0;
      }
      try {
          if (awsPolicyAllows13()) {
              return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "CA10__policyDocumentExt__c .allows(EXTERNAL_PRINCIPAL, [s3:ListBucket, s3:GetObject, s3:GetObjectVersion])", currentStateMessage: "The bucket policy grants public read access to the bucket data.", currentStateReferences: references1.join('\n'), remediation: "Consider removing the public read access from the bucket.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "The Bucket policy does not grant public read or write access to the bucket data.", 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__policyIsPublic__c AS CA10__policyIsPublic__c,
          sObject.CA10__blockPublicPolicy__c AS CA10__blockPublicPolicy__c,
          sObject.CA10__policyDocumentExt__c AS CA10__policyDocumentExt__c,
          sObject.Id AS Id,
          process_CA10__CaAwsBucket__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__policyIsPublic__c AS CA10__policyIsPublic__c,
                  sObject.CA10__blockPublicPolicy__c AS CA10__blockPublicPolicy__c,
                  sObject.CA10__policyDocumentExt__c AS CA10__policyDocumentExt__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsBucket__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
