---
policy: /ce/ca/aws/account/security-hub
logic: /ce/ca/aws/account/security-hub/prod.logic.yaml
executionTime: 2025-04-24T23:44:14.012051842Z
rows:
  - id: test1
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10A1__AWS_Security_Hubs__r.has(COMPLIANT)
      actual: CA10A1__AWS_Security_Hubs__r.has(COMPLIANT)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/account/security-hub/policy.yaml
    md5Hash: A5489B2CA5FFEEA6F7078609BE07AFD9
    content: |
      ---
      names:
        full: AWS Account Security Hub is not enabled
        contextual: Security Hub is not enabled
      description: "Security Hub collects security data from across AWS accounts, services,\
        \ and supported third-party partner products and helps you analyze your security\
        \ trends   and identify the highest priority security issues. When you enable Security\
        \ Hub, it begins to consume, aggregate, organize, and prioritize findings from AWS\
        \ services that you have enabled, such as Amazon GuardDuty, Amazon Inspector, and\
        \ Amazon Macie."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-aws-v5.0.0/04/16"
        - "/frameworks/cloudaware/resource-security/threat-protection"
      similarPolicies:
        internal:
          - "dec-z-bc139af8"
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/SecurityHub/security-hub-enabled.html
            name: Security Hub Enabled
  - path: /ce/ca/aws/account/security-hub/prod.logic.yaml
    md5Hash: E9072C659E30F85B4B0E176D6ACFECFD
    content: |-
      ---
      inputType: "CA10__CaAwsAccount__c"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "COMPLIANT"
          currentStateMessage: "Security Hub is enabled."
          check:
            RELATED_LIST_HAS:
              status: "COMPLIANT"
              relationshipName: "CA10A1__AWS_Security_Hubs__r"
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "Security Hub is disabled."
        remediationMessage: "Consider enabling Security Hub in all regions."
      relatedLists:
        - relationshipName: "CA10A1__AWS_Security_Hubs__r"
          conditions: []
          otherwise:
            status: "COMPLIANT"
            currentStateMessage: "Security Hub is enabled."
  - path: /ce/ca/aws/account/security-hub/test-data.json
    md5Hash: 6547719279B6088D0E135CCC1DC2A1DB
    content: "[\n    {\n        \"expectedResult\": {\n            \"status\": \"\
      COMPLIANT\",\n            \"conditionIndex\": \"199\",\n            \"conditionText\"\
      : \"CA10A1__AWS_Security_Hubs__r.has(COMPLIANT)\",\n            \"runtimeError\"\
      : null\n        },\n        \"context\": {\n            \"snapshotTime\": \"\
      2024-06-16T19:32:23Z\"\n        },\n        \"Id\": \"test1\",\n        \"CA10A1__AWS_Security_Hubs__r\"\
      : [\n            {\n                \"Id\": \"test1_1\",\n                \"\
      CA10A1__disappearanceTime__c\": null,\n                \"CA10A1__account__c\"\
      : \"test1\"   \n            }\n        ]\n    },\n    {\n        \"expectedResult\"\
      : {\n            \"status\": \"INCOMPLIANT\",\n            \"conditionIndex\"\
      : \"200\",\n            \"conditionText\": \"otherwise\",\n            \"runtimeError\"\
      : null\n        },\n        \"context\": {\n            \"snapshotTime\": \"\
      2024-06-16T19:32:23Z\"\n        },\n        \"Id\": \"test2\",\n        \"CA10A1__AWS_Security_Hubs__r\"\
      : []\n    },\n    {\n        \"expectedResult\": {\n            \"status\":\
      \ \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\",\n            \"\
      conditionText\": \"otherwise\",\n            \"runtimeError\": null\n      \
      \  },\n        \"context\": {\n            \"snapshotTime\": \"2024-06-16T19:32:23Z\"\
      \n        },\n        \"Id\": \"test3\",\n        \"CA10A1__AWS_Security_Hubs__r\"\
      : [\n            {\n                \"Id\": \"test3_1\",\n                \"\
      CA10A1__disappearanceTime__c\": \"2024-06-16T19:32:23Z\",\n                \"\
      CA10A1__account__c\": \"test3\"   \n            }\n        ]\n    }\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" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10A1__AWS_Security_Hubs__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAccount__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-16T19:32:23Z")
    },
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-16T19:32:23Z")
    },
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-16T19:32:23Z")
    },
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsSecurityHub__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__account__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-16T19:32:23Z")
    },
    "Id" : "test1_1",
    "CA10A1__account__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-16T19:32:23Z")
    },
    "Id" : "test3_1",
    "CA10A1__disappearanceTime__c" : new Date("2024-06-16T19:32:23Z"),
    "CA10A1__account__c" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsAccount__c(
      obj STRUCT<
          Id STRING,
          CA10A1__AWS_Security_Hubs__r ARRAY<STRUCT<
              Id STRING,
              CA10A1__disappearanceTime__c TIMESTAMP,
              CA10A1__account__c STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError 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 references1 = [];
      // condition[0], conditionIndex:[0..99]
      if (false) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10A1__AWS_Security_Hubs__r_COMPLIANT2 = 0;
      if (obj.CA10A1__AWS_Security_Hubs__r != null) {
          for (var i3 = 0; i3 < obj.CA10A1__AWS_Security_Hubs__r.length; i3++) {
              if (obj.CA10A1__AWS_Security_Hubs__r[i3].result.status == 'COMPLIANT') {
                  count_CA10A1__AWS_Security_Hubs__r_COMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10A1__AWS_Security_Hubs__r] ' + (count_CA10A1__AWS_Security_Hubs__r_COMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status');
      if (count_CA10A1__AWS_Security_Hubs__r_COMPLIANT2 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "CA10A1__AWS_Security_Hubs__r.has(COMPLIANT)", currentStateMessage: "Security Hub is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Security Hub is disabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling Security Hub in all regions.", runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10A1__AWS_Security_Hubs__r(
      obj STRUCT<
          Id STRING,
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__account__c 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 references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10A1__disappearanceTime__c]: ' + obj.CA10A1__disappearanceTime__c);
      if (obj.CA10A1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10A1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "Security Hub is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.Id AS Id,
          `CA10A1__AWS_Security_Hubs__r`.arr AS CA10A1__AWS_Security_Hubs__r,
          process_CA10__CaAwsAccount__c(
              STRUCT(
                  sObject.Id AS Id,
                  `CA10A1__AWS_Security_Hubs__r`.arr AS CA10A1__AWS_Security_Hubs__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsAccount__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10A1__account__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                      sObject.CA10A1__account__c AS CA10A1__account__c,
                      process_CA10A1__AWS_Security_Hubs__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                              sObject.CA10A1__account__c AS CA10A1__account__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10A1__CaAwsSecurityHub__c()) AS sObject
          GROUP BY sObject.CA10A1__account__c
      ) AS `CA10A1__AWS_Security_Hubs__r`
          ON sObject.Id = `CA10A1__AWS_Security_Hubs__r`.CA10A1__account__c
  ) sObject ON sObject.Id = expectedResult.Id;
