--- policy: /ce/ca/aws/cloudfront/distribution-unencrypted-cache-behaviors logic: /ce/ca/aws/cloudfront/distribution-unencrypted-cache-behaviors/prod.logic.yaml executionTime: 2026-02-10T22:32:36.018935688Z generationMs: 139 executionMs: 1444 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: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 199 actual: 199 conditionText: expected: "not(setOfText(['caWebDistribution']).contains(RecordType.DeveloperName))" actual: "not(setOfText(['caWebDistribution']).contains(RecordType.DeveloperName))" runtimeError: {} - id: test3 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 499 actual: 499 conditionText: expected: extract('CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c') == 'allow-all' actual: extract('CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c') == 'allow-all' runtimeError: {} - id: test4 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 599 actual: 599 conditionText: expected: CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT) actual: CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT) runtimeError: {} - id: test5 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 600 actual: 600 conditionText: expected: otherwise actual: otherwise runtimeError: {} - id: test6 match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 399 actual: 399 conditionText: expected: isEmptyLookup('CA10__defaultCacheBehavior__r') actual: isEmptyLookup('CA10__defaultCacheBehavior__r') runtimeError: {} - id: test7 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 299 actual: 299 conditionText: expected: isEmptyLookup('CA10__defaultCacheBehavior__r') && CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT) actual: isEmptyLookup('CA10__defaultCacheBehavior__r') && CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT) runtimeError: {} usedFiles: - path: /ce/ca/aws/cloudfront/distribution-unencrypted-cache-behaviors/policy.yaml md5Hash: 816E8C64A79382910AD17055ED1280E5 content: "---\nnames:\n full: AWS CloudFront Web Distribution Cache Behaviors\ \ allow unencrypted traffic\n contextual: Web Distribution Cache Behaviors\ \ allow unencrypted traffic\ndescription: >\n Ensures that CloudFront distribution\ \ cache behaviors are configured to enforce \n encrypted connections (HTTPS)\ \ by redirecting or allowing only HTTPS traffic. \n This prevents unencrypted\ \ HTTP communication between viewers and CloudFront.\ncategories:\n - \"SECURITY\"\ \ntype: \"COMPLIANCE_POLICY\"\nframeworkMappings:\n - \"/frameworks/cloudaware/resource-security/data-encryption\"\ \n - \"/frameworks/aws-fsbp-v1.0.0/cloudfront/03\"\nsimilarPolicies:\n awsSecurityHub:\n\ \ - name: \"[CloudFront.3] CloudFront distributions should require encryption\ \ in transit\"\n url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/cloudfront-controls.html#cloudfront-3\"\ \n internal:\n - \"dec-x-791dab13\"" - path: /ce/ca/aws/cloudfront/distribution-unencrypted-cache-behaviors/prod.logic.yaml md5Hash: BDCFB4A4F1CDA3202BA5FBDCCDCEC5E6 content: "---\ninputType: \"CA10__CaAwsDistribution__c\"\nimportExtracts:\n -\ \ file: \"/types/CA10__CaAwsCacheBehavior2__c/object.extracts.yaml\"\ntestData:\n\ \ - file: \"test-data.json\" \nrecordTypes:\n - \"caWebDistribution\"\nconditions:\n\ \ - status: \"INCOMPLIANT\"\n currentStateMessage: \"At least one CloudFront\ \ distribution cache behavior allows unencrypted HTTP traffic.\"\n remediationMessage:\ \ \"Set the viewer protocol policy to Redirect HTTP to HTTPS or HTTPS Only for\ \ all cache behaviors.\"\n check:\n AND:\n args:\n -\ \ IS_EMPTY_LOOKUP: \"CA10__defaultCacheBehavior__r\"\n - RELATED_LIST_HAS:\n\ \ status: \"INCOMPLIANT\"\n relationshipName: \"CA10__AWS_CloudFront_Cache_Behaviors__r\"\ \n - status: \"UNDETERMINED\"\n currentStateMessage: \"The default CloudFront\ \ distribution cache behavior is not present in the CMDB.\"\n check:\n \ \ IS_EMPTY_LOOKUP: \"CA10__defaultCacheBehavior__r\"\n - status: \"INCOMPLIANT\"\ \n currentStateMessage: \"The default CloudFront distribution cache behavior\ \ allows unencrypted HTTP traffic.\"\n remediationMessage: \"Set the viewer\ \ protocol policy to Redirect HTTP to HTTPS or HTTPS Only for the default cache\ \ behavior.\"\n check:\n IS_EQUAL:\n left:\n EXTRACT:\ \ \"CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c\"\n right:\n\ \ TEXT: \"allow-all\"\n - status: \"INCOMPLIANT\"\n currentStateMessage:\ \ \"At least one CloudFront distribution cache behavior allows unencrypted HTTP\ \ traffic.\"\n remediationMessage: \"Set the viewer protocol policy to Redirect\ \ HTTP to HTTPS or HTTPS Only for all cache behaviors.\"\n check:\n \ \ RELATED_LIST_HAS:\n status: \"INCOMPLIANT\"\n relationshipName:\ \ \"CA10__AWS_CloudFront_Cache_Behaviors__r\"\notherwise:\n status: \"COMPLIANT\"\ \n currentStateMessage: \"All CloudFront distribution cache behaviors enforce\ \ encrypted communications.\"\nrelatedLists:\n - relationshipName: \"CA10__AWS_CloudFront_Cache_Behaviors__r\"\ \n conditions:\n - status: \"INCOMPLIANT\"\n currentStateMessage:\ \ \"The viewer protocol policy for this cache behavior is set to allow-all.\"\ \n check:\n IS_EQUAL:\n left:\n EXTRACT:\ \ \"CA10__viewerProtocolPolicy__c\"\n right:\n TEXT:\ \ \"allow-all\"\n otherwise:\n status: \"COMPLIANT\"\n currentStateMessage:\ \ \"The viewer protocol policy for this cache behavior encrypts communications.\"\ \n" - path: /ce/ca/aws/cloudfront/distribution-unencrypted-cache-behaviors/test-data.json md5Hash: E08B0BBD7FB6004988EB6E8321E6CF4A content: |- [ { "expectedResult": { "status": "DISAPPEARED", "conditionIndex": "99", "conditionText": "isDisappeared(CA10__disappearanceTime__c)", "runtimeError": null }, "context": { "snapshotTime": "2025-05-10T18:55:17Z" }, "Id": "test1", "RecordTypeId": "RecordTypeId2", "CA10__disappearanceTime__c": "2025-05-10T18:55:17Z", "CA10__defaultCacheBehavior__c": "defaultCacheBehavior1", "CA10__defaultCacheBehaviorUniqueId__c": "defaultCacheBehaviorUniqueId1", "RecordType": { "DeveloperName": "caWebDistribution", "Id": "RecordTypeId2" }, "CA10__defaultCacheBehavior__r": { "Id": "defaultCacheBehavior1", "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": "allow-all" }, "CA10__AWS_CloudFront_Cache_Behaviors__r": [ { "Id": "defaultCacheBehavior1", "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": "allow-all", "CA10__distribution__c": "test1" } ] }, { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "199", "conditionText": "not(setOfText(['caWebDistribution']).contains(RecordType.DeveloperName))", "runtimeError": null }, "context": { "snapshotTime": "2025-05-10T18:55:17Z" }, "Id": "test2", "RecordTypeId": "RecordTypeId1", "CA10__disappearanceTime__c": null, "CA10__defaultCacheBehavior__c": "", "CA10__defaultCacheBehaviorUniqueId__c": "", "RecordType": { "DeveloperName": "caRtmpDistribution", "Id": "RecordTypeId1" }, "CA10__defaultCacheBehavior__r": { "Id": null, "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": null }, "CA10__AWS_CloudFront_Cache_Behaviors__r": [] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "499", "conditionText": "extract('CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c') == 'allow-all'", "runtimeError": null }, "context": { "snapshotTime": "2025-05-10T18:55:17Z" }, "Id": "test3", "RecordTypeId": "RecordTypeId2", "CA10__disappearanceTime__c": null, "CA10__defaultCacheBehavior__c": "defaultCacheBehavior3_1", "CA10__defaultCacheBehaviorUniqueId__c": "defaultCacheBehaviorUniqueId3", "RecordType": { "DeveloperName": "caWebDistribution", "Id": "RecordTypeId2" }, "CA10__defaultCacheBehavior__r": { "Id": "defaultCacheBehavior3_1", "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": "allow-all" }, "CA10__AWS_CloudFront_Cache_Behaviors__r": [ { "Id": "defaultCacheBehavior3_2", "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": "allow-all", "CA10__distribution__c": "test3" } ] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "599", "conditionText": "CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2025-05-10T18:55:17Z" }, "Id": "test4", "RecordTypeId": "RecordTypeId2", "CA10__disappearanceTime__c": null, "CA10__defaultCacheBehavior__c": "defaultCacheBehavior4_1", "CA10__defaultCacheBehaviorUniqueId__c": "defaultCacheBehaviorUniqueId4", "RecordType": { "DeveloperName": "caWebDistribution", "Id": "RecordTypeId2" }, "CA10__defaultCacheBehavior__r": { "Id": "defaultCacheBehavior4_1", "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": "redirect-to-https" }, "CA10__AWS_CloudFront_Cache_Behaviors__r": [ { "Id": "defaultCacheBehavior4_2", "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": "allow-all", "CA10__distribution__c": "test4" } ] }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "600", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2025-05-10T18:55:17Z" }, "Id": "test5", "RecordTypeId": "RecordTypeId2", "CA10__disappearanceTime__c": null, "CA10__defaultCacheBehavior__c": "defaultCacheBehavior5_1", "CA10__defaultCacheBehaviorUniqueId__c": "defaultCacheBehaviorUniqueId5", "RecordType": { "DeveloperName": "caWebDistribution", "Id": "RecordTypeId2" }, "CA10__defaultCacheBehavior__r": { "Id": "defaultCacheBehavior5_1", "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": "redirect-to-https" }, "CA10__AWS_CloudFront_Cache_Behaviors__r": [ { "Id": "defaultCacheBehavior5_2", "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": "redirect-to-https", "CA10__distribution__c": "test5" } ] }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "399", "conditionText": "isEmptyLookup('CA10__defaultCacheBehavior__r')", "runtimeError": null }, "context": { "snapshotTime": "2025-05-10T18:55:17Z" }, "Id": "test6", "RecordTypeId": "RecordTypeId2", "CA10__disappearanceTime__c": null, "CA10__defaultCacheBehavior__c": "defaultCacheBehavior6_1", "CA10__defaultCacheBehaviorUniqueId__c": "defaultCacheBehaviorUniqueId6", "RecordType": { "DeveloperName": "caWebDistribution", "Id": "RecordTypeId2" }, "CA10__defaultCacheBehavior__r": { "Id": "defaultCacheBehavior6_1", "CA10__disappearanceTime__c": "2025-05-10T18:55:17Z", "CA10__viewerProtocolPolicy__c": "allow-all" }, "CA10__AWS_CloudFront_Cache_Behaviors__r": [ { "Id": "defaultCacheBehavior6_2", "CA10__disappearanceTime__c": "2025-05-10T18:55:17Z", "CA10__viewerProtocolPolicy__c": "allow-all", "CA10__distribution__c": "test6" } ] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "299", "conditionText": "isEmptyLookup('CA10__defaultCacheBehavior__r') && CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2025-05-10T18:55:17Z" }, "Id": "test7", "RecordTypeId": "RecordTypeId2", "CA10__disappearanceTime__c": null, "CA10__defaultCacheBehavior__c": "defaultCacheBehavior7_1", "CA10__defaultCacheBehaviorUniqueId__c": "defaultCacheBehaviorUniqueId7", "RecordType": { "DeveloperName": "caWebDistribution", "Id": "RecordTypeId2" }, "CA10__defaultCacheBehavior__r": { "Id": "defaultCacheBehavior7_1", "CA10__disappearanceTime__c": "2025-05-10T18:55:17Z", "CA10__viewerProtocolPolicy__c": "allow-all" }, "CA10__AWS_CloudFront_Cache_Behaviors__r": [ { "Id": "defaultCacheBehavior7_2", "CA10__disappearanceTime__c": null, "CA10__viewerProtocolPolicy__c": "allow-all", "CA10__distribution__c": "test7" } ] } ] - path: /types/CA10__CaAwsCacheBehavior2__c/object.extracts.yaml md5Hash: 9FCFD18140FB8C38265EB37003668054 content: |- --- extracts: # Values: allow-all | https-only | redirect-to-https. Not Nullable. Can't have no access, retrieved via cloudfront:GetDistribution - name: "CA10__viewerProtocolPolicy__c" value: FIELD: path: CA10__viewerProtocolPolicy__c undeterminedIf: isEmpty: "Corrupted data. Viewer Protocol Policy cannot be empty." script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "test1", "expectedResult" : { "status" : "DISAPPEARED", "conditionIndex" : "99", "conditionText" : "isDisappeared(CA10__disappearanceTime__c)", "runtimeError" : null } }, { "Id" : "test2", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "199", "conditionText" : "not(setOfText(['caWebDistribution']).contains(RecordType.DeveloperName))", "runtimeError" : null } }, { "Id" : "test3", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "499", "conditionText" : "extract('CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c') == 'allow-all'", "runtimeError" : null } }, { "Id" : "test4", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "599", "conditionText" : "CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT)", "runtimeError" : null } }, { "Id" : "test5", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "600", "conditionText" : "otherwise", "runtimeError" : null } }, { "Id" : "test6", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "399", "conditionText" : "isEmptyLookup('CA10__defaultCacheBehavior__r')", "runtimeError" : null } }, { "Id" : "test7", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "299", "conditionText" : "isEmptyLookup('CA10__defaultCacheBehavior__r') && CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT)", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsDistribution__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__disappearanceTime__c" : new Date("2025-05-10T18:55:17Z"), "CA10__defaultCacheBehavior__c" : "defaultCacheBehavior1", "CA10__defaultCacheBehaviorUniqueId__c" : "defaultCacheBehaviorUniqueId1", "Id" : "test1", "RecordTypeId" : "RecordTypeId2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__defaultCacheBehavior__c" : "", "CA10__defaultCacheBehaviorUniqueId__c" : "", "Id" : "test2", "RecordTypeId" : "RecordTypeId1" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__defaultCacheBehavior__c" : "defaultCacheBehavior3_1", "CA10__defaultCacheBehaviorUniqueId__c" : "defaultCacheBehaviorUniqueId3", "Id" : "test3", "RecordTypeId" : "RecordTypeId2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__defaultCacheBehavior__c" : "defaultCacheBehavior4_1", "CA10__defaultCacheBehaviorUniqueId__c" : "defaultCacheBehaviorUniqueId4", "Id" : "test4", "RecordTypeId" : "RecordTypeId2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__defaultCacheBehavior__c" : "defaultCacheBehavior5_1", "CA10__defaultCacheBehaviorUniqueId__c" : "defaultCacheBehaviorUniqueId5", "Id" : "test5", "RecordTypeId" : "RecordTypeId2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__defaultCacheBehavior__c" : "defaultCacheBehavior6_1", "CA10__defaultCacheBehaviorUniqueId__c" : "defaultCacheBehaviorUniqueId6", "Id" : "test6", "RecordTypeId" : "RecordTypeId2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__defaultCacheBehavior__c" : "defaultCacheBehavior7_1", "CA10__defaultCacheBehaviorUniqueId__c" : "defaultCacheBehaviorUniqueId7", "Id" : "test7", "RecordTypeId" : "RecordTypeId2" } ]; """; CREATE TEMP FUNCTION mock_RecordType() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "DeveloperName" : "caWebDistribution", "Id" : "RecordTypeId2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "DeveloperName" : "caRtmpDistribution", "Id" : "RecordTypeId1" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsCacheBehavior2__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "Id" : "defaultCacheBehavior1", "CA10__viewerProtocolPolicy__c" : "allow-all", "CA10__distribution__c" : "test1" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "Id" : null, "CA10__viewerProtocolPolicy__c" : null }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "Id" : "defaultCacheBehavior3_1", "CA10__viewerProtocolPolicy__c" : "allow-all" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__viewerProtocolPolicy__c" : "allow-all", "CA10__distribution__c" : "test3", "Id" : "defaultCacheBehavior3_2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "Id" : "defaultCacheBehavior4_1", "CA10__viewerProtocolPolicy__c" : "redirect-to-https" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__viewerProtocolPolicy__c" : "allow-all", "CA10__distribution__c" : "test4", "Id" : "defaultCacheBehavior4_2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "Id" : "defaultCacheBehavior5_1", "CA10__viewerProtocolPolicy__c" : "redirect-to-https" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__viewerProtocolPolicy__c" : "redirect-to-https", "CA10__distribution__c" : "test5", "Id" : "defaultCacheBehavior5_2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "Id" : "defaultCacheBehavior6_1", "CA10__disappearanceTime__c" : new Date("2025-05-10T18:55:17Z"), "CA10__viewerProtocolPolicy__c" : "allow-all" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__disappearanceTime__c" : new Date("2025-05-10T18:55:17Z"), "CA10__viewerProtocolPolicy__c" : "allow-all", "CA10__distribution__c" : "test6", "Id" : "defaultCacheBehavior6_2" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "Id" : "defaultCacheBehavior7_1", "CA10__disappearanceTime__c" : new Date("2025-05-10T18:55:17Z"), "CA10__viewerProtocolPolicy__c" : "allow-all" }, { "context" : { "snapshotTime" : new Date("2025-05-10T18:55:17Z") }, "CA10__viewerProtocolPolicy__c" : "allow-all", "CA10__distribution__c" : "test7", "Id" : "defaultCacheBehavior7_2" } ]; """; CREATE TEMP FUNCTION process_CA10__CaAwsDistribution__c( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__defaultCacheBehavior__c STRING, CA10__defaultCacheBehaviorUniqueId__c STRING, Id STRING, RecordTypeId STRING, RecordType STRUCT< DeveloperName STRING, Id STRING >, CA10__defaultCacheBehavior__r STRUCT< Id STRING, CA10__disappearanceTime__c TIMESTAMP, CA10__viewerProtocolPolicy__c STRING >, CA10__AWS_CloudFront_Cache_Behaviors__r ARRAY >> >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" 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 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] references1.push('Record Type Name [obj.RecordType.DeveloperName]: ' + obj.RecordType.DeveloperName); if (!CollectionLib.contains(CollectionLib.fromArray(['caWebDistribution'], true, true, true, true), obj.RecordType.DeveloperName, true)) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(setOfText(['caWebDistribution']).contains(RecordType.DeveloperName))", currentStateMessage: "Object record type is not applicable", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } var count_CA10__AWS_CloudFront_Cache_Behaviors__r_INCOMPLIANT3 = 0; if (obj.CA10__AWS_CloudFront_Cache_Behaviors__r != null) { for (var i4 = 0; i4 < obj.CA10__AWS_CloudFront_Cache_Behaviors__r.length; i4++) { if (typeof(obj.CA10__AWS_CloudFront_Cache_Behaviors__r[i4].status) !== 'undefined') { if (obj.CA10__AWS_CloudFront_Cache_Behaviors__r[i4].status == 'INCOMPLIANT') { count_CA10__AWS_CloudFront_Cache_Behaviors__r_INCOMPLIANT3 += obj.CA10__AWS_CloudFront_Cache_Behaviors__r[i4].count; } } else { if (obj.CA10__AWS_CloudFront_Cache_Behaviors__r[i4].result.status == 'INCOMPLIANT') { count_CA10__AWS_CloudFront_Cache_Behaviors__r_INCOMPLIANT3 += 1; } } } } // condition[2], conditionIndex:[200..299] references1.push('Related list [CA10__AWS_CloudFront_Cache_Behaviors__r] ' + (count_CA10__AWS_CloudFront_Cache_Behaviors__r_INCOMPLIANT3 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status'); if ((TextLib.isEmpty(obj.CA10__defaultCacheBehaviorUniqueId__c) || TextLib.isEmpty(obj.CA10__defaultCacheBehavior__c) || obj.CA10__defaultCacheBehavior__r.CA10__disappearanceTime__c != null) && count_CA10__AWS_CloudFront_Cache_Behaviors__r_INCOMPLIANT3 > 0) { return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "isEmptyLookup('CA10__defaultCacheBehavior__r') && CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT)", currentStateMessage: "At least one CloudFront distribution cache behavior allows unencrypted HTTP traffic.", currentStateReferences: references1.join('\n'), remediation: "Set the viewer protocol policy to Redirect HTTP to HTTPS or HTTPS Only for all cache behaviors.", runtimeError: null}; } // condition[3], conditionIndex:[300..399] if (TextLib.isEmpty(obj.CA10__defaultCacheBehaviorUniqueId__c) || TextLib.isEmpty(obj.CA10__defaultCacheBehavior__c) || obj.CA10__defaultCacheBehavior__r.CA10__disappearanceTime__c != null) { return {status: 'UNDETERMINED', conditionIndex: 399, conditionText: "isEmptyLookup('CA10__defaultCacheBehavior__r')", currentStateMessage: "The default CloudFront distribution cache behavior is not present in the CMDB.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[4], conditionIndex:[400..499] function extractChecked5() { if (TextLib.isEmpty(obj.CA10__defaultCacheBehaviorUniqueId__c)) { throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "extractCheck(obj.CA10__defaultCacheBehaviorUniqueId__c)", currentStateMessage: "Related object via CA10__defaultCacheBehaviorUniqueId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } if (TextLib.isEmpty(obj.CA10__defaultCacheBehavior__c)) { throw new Error("UNDETERMINED condition:402", {cause: {status: 'UNDETERMINED', conditionIndex: 402, conditionText: "extractCheck(obj.CA10__defaultCacheBehavior__c)", currentStateMessage: "Related object via CA10__defaultCacheBehavior__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } if (obj.CA10__defaultCacheBehavior__r.CA10__disappearanceTime__c != null) { throw new Error("UNDETERMINED condition:403", {cause: {status: 'UNDETERMINED', conditionIndex: 403, conditionText: "extractCheck(obj.CA10__defaultCacheBehavior__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__defaultCacheBehavior__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return extract6.call(extract6); } function fieldChecked7() { if (TextLib.isEmpty(obj.CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c)) { throw new Error("UNDETERMINED condition:404", {cause: {status: 'UNDETERMINED', conditionIndex: 404, conditionText: "CA10__viewerProtocolPolicy__c.isEmpty()", currentStateMessage: "Corrupted data. Viewer Protocol Policy cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c; } function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; }; references1.push('Viewer Protocol Policy [obj.CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c]: ' + obj.CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c); try { if (TextLib.equal(extractChecked5(), 'allow-all')) { return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10__defaultCacheBehavior__r.CA10__viewerProtocolPolicy__c') == 'allow-all'", currentStateMessage: "The default CloudFront distribution cache behavior allows unencrypted HTTP traffic.", currentStateReferences: references1.join('\n'), remediation: "Set the viewer protocol policy to Redirect HTTP to HTTPS or HTTPS Only for the default cache behavior.", runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } var count_CA10__AWS_CloudFront_Cache_Behaviors__r_INCOMPLIANT3 = 0; if (obj.CA10__AWS_CloudFront_Cache_Behaviors__r != null) { for (var i8 = 0; i8 < obj.CA10__AWS_CloudFront_Cache_Behaviors__r.length; i8++) { if (typeof(obj.CA10__AWS_CloudFront_Cache_Behaviors__r[i8].status) !== 'undefined') { if (obj.CA10__AWS_CloudFront_Cache_Behaviors__r[i8].status == 'INCOMPLIANT') { count_CA10__AWS_CloudFront_Cache_Behaviors__r_INCOMPLIANT3 += obj.CA10__AWS_CloudFront_Cache_Behaviors__r[i8].count; } } else { if (obj.CA10__AWS_CloudFront_Cache_Behaviors__r[i8].result.status == 'INCOMPLIANT') { count_CA10__AWS_CloudFront_Cache_Behaviors__r_INCOMPLIANT3 += 1; } } } } // condition[5], conditionIndex:[500..599] if (count_CA10__AWS_CloudFront_Cache_Behaviors__r_INCOMPLIANT3 > 0) { return {status: 'INCOMPLIANT', conditionIndex: 599, conditionText: "CA10__AWS_CloudFront_Cache_Behaviors__r.has(INCOMPLIANT)", currentStateMessage: "At least one CloudFront distribution cache behavior allows unencrypted HTTP traffic.", currentStateReferences: references1.join('\n'), remediation: "Set the viewer protocol policy to Redirect HTTP to HTTPS or HTTPS Only for all cache behaviors.", runtimeError: null}; } return {status: 'COMPLIANT', conditionIndex: 600, conditionText: "otherwise", currentStateMessage: "All CloudFront distribution cache behaviors enforce encrypted communications.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; CREATE TEMP FUNCTION process_CA10__AWS_CloudFront_Cache_Behaviors__r( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__viewerProtocolPolicy__c STRING, CA10__distribution__c STRING, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT 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 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__viewerProtocolPolicy__c)) { throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__viewerProtocolPolicy__c.isEmpty()", currentStateMessage: "Corrupted data. Viewer Protocol Policy cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__viewerProtocolPolicy__c; } function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; }; references1.push('Viewer Protocol Policy [obj.CA10__viewerProtocolPolicy__c]: ' + obj.CA10__viewerProtocolPolicy__c); try { if (TextLib.equal(extract3.call(extract3), 'allow-all')) { return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__viewerProtocolPolicy__c') == 'allow-all'", currentStateMessage: "The viewer protocol policy for this cache behavior is set to allow-all.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The viewer protocol policy for this cache behavior encrypts communications.", 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__defaultCacheBehavior__c AS CA10__defaultCacheBehavior__c, sObject.CA10__defaultCacheBehaviorUniqueId__c AS CA10__defaultCacheBehaviorUniqueId__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.DeveloperName AS DeveloperName, `RecordType`.Id AS Id ) AS RecordType, STRUCT ( `CA10__defaultCacheBehavior__r`.Id AS Id, `CA10__defaultCacheBehavior__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, `CA10__defaultCacheBehavior__r`.CA10__viewerProtocolPolicy__c AS CA10__viewerProtocolPolicy__c ) AS CA10__defaultCacheBehavior__r, `CA10__AWS_CloudFront_Cache_Behaviors__r`.arr AS CA10__AWS_CloudFront_Cache_Behaviors__r, process_CA10__CaAwsDistribution__c( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__defaultCacheBehavior__c AS CA10__defaultCacheBehavior__c, sObject.CA10__defaultCacheBehaviorUniqueId__c AS CA10__defaultCacheBehaviorUniqueId__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.DeveloperName AS DeveloperName, `RecordType`.Id AS Id ) AS RecordType, STRUCT ( `CA10__defaultCacheBehavior__r`.Id AS Id, `CA10__defaultCacheBehavior__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, `CA10__defaultCacheBehavior__r`.CA10__viewerProtocolPolicy__c AS CA10__viewerProtocolPolicy__c ) AS CA10__defaultCacheBehavior__r, `CA10__AWS_CloudFront_Cache_Behaviors__r`.arr AS CA10__AWS_CloudFront_Cache_Behaviors__r ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10__CaAwsDistribution__c()) AS sObject LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType` ON sObject.RecordTypeId = `RecordType`.Id LEFT JOIN UNNEST(mock_CA10__CaAwsCacheBehavior2__c()) AS `CA10__defaultCacheBehavior__r` ON sObject.CA10__defaultCacheBehavior__c = `CA10__defaultCacheBehavior__r`.Id LEFT JOIN ( SELECT sObject.CA10__distribution__c, ARRAY_AGG( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__viewerProtocolPolicy__c AS CA10__viewerProtocolPolicy__c, sObject.CA10__distribution__c AS CA10__distribution__c, sObject.Id AS Id, process_CA10__AWS_CloudFront_Cache_Behaviors__r( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__viewerProtocolPolicy__c AS CA10__viewerProtocolPolicy__c, sObject.CA10__distribution__c AS CA10__distribution__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result ) ) AS arr FROM UNNEST(mock_CA10__CaAwsCacheBehavior2__c()) AS sObject GROUP BY sObject.CA10__distribution__c ) AS `CA10__AWS_CloudFront_Cache_Behaviors__r` ON sObject.Id = `CA10__AWS_CloudFront_Cache_Behaviors__r`.CA10__distribution__c ) sObject ON sObject.Id = expectedResult.Id;