---
policy: /ce/ca/aws/rds/instance-master-username
logic: /ce/ca/aws/rds/instance-master-username/prod.logic.yaml
executionTime: 2026-01-31T12:02:14.192502905Z
generationMs: 72
executionMs: 927
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: extract('CA10__status__c') != 'available'
      actual: extract('CA10__status__c') != 'available'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__clusterArn__c').isNotEmpty()
      actual: extract('CA10__clusterArn__c').isNotEmpty()
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 599
      actual: 599
    conditionText:
      expected: "setOfText(['root', 'admin', 'administrator', 'adminuser', 'superuser',\
        \ 'sa', 'sysadmin', 'dbadmin', 'user', 'dbuser', 'sys', 'system', 'awsuser',\
        \ 'mysql', 'oracle', 'postgres']).contains(extract('CA10__masterUsername__c'))"
      actual: "setOfText(['root', 'admin', 'administrator', 'adminuser', 'superuser',\
        \ 'sa', 'sysadmin', 'dbadmin', 'user', 'dbuser', 'sys', 'system', 'awsuser',\
        \ 'mysql', 'oracle', 'postgres']).contains(extract('CA10__masterUsername__c'))"
    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: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__engine__c') == 'neptune'
      actual: extract('CA10__engine__c') == 'neptune'
    runtimeError: {}
  - id: test7
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: extract('CA10__engine__c') == 'docdb'
      actual: extract('CA10__engine__c') == 'docdb'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/rds/instance-master-username/policy.yaml
    md5Hash: 80700121792B1CECE3AC46FC4F1CF6CD
    content: "---\nnames:\n  full: \"AWS RDS Instance has a common master username\"\
      \n  contextual: \"Instance has a common master username\"\ndescription: >\n\
      \  Ensure that Amazon RDS database instances do not use common default administrative\
      \ \n  usernames such as 'admin', 'root', 'postgres', etc. Using non-default\
      \ usernames \n  adds a layer of security by making it harder for attackers to\
      \ guess administrative \n  credentials during brute-force attacks.\ntype: \"\
      COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n  -\
      \ \"/frameworks/cloudaware/resource-security/secure-access\"\n  - \"/frameworks/aws-fsbp-v1.0.0/rds/25\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[RDS.25] RDS database instances\
      \ should use a custom administrator username\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/rds-controls.html#rds-25\"\
      \n"
  - path: /ce/ca/aws/rds/instance-master-username/prod.logic.yaml
    md5Hash: F90953BC2911218964FBB857E9374A72
    content: "---\ninputType: \"CA10__CaAwsDbInstance__c\"\ntestData:\n  - file: test-data.json\n\
      importExtracts:\n  - file: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml\n\
      conditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"The Instance\
      \ is not available.\"\n    check:\n      NOT_EQUAL:\n        left:\n       \
      \   EXTRACT: \"CA10__status__c\"\n        right:\n          TEXT: \"available\"\
      \n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"This policy doesn't\
      \ apply to Cluster Instances.\"\n    check:\n      NOT_EMPTY:\n        arg:\n\
      \          EXTRACT: \"CA10__clusterArn__c\"\n  - status: \"INAPPLICABLE\"\n\
      \    currentStateMessage: \"This policy doesn't apply to Neptune.\"\n    check:\n\
      \      IS_EQUAL:\n        left:\n          EXTRACT: \"CA10__engine__c\"\n  \
      \      right:\n          TEXT: \"neptune\"\n  - status: \"INAPPLICABLE\"\n \
      \   currentStateMessage: \"This policy doesn't apply to DocumentDB.\"\n    check:\n\
      \      IS_EQUAL:\n        left:\n          EXTRACT: \"CA10__engine__c\"\n  \
      \      right:\n          TEXT: \"docdb\"          \n  - status: \"INCOMPLIANT\"\
      \n    currentStateMessage: \"The RDS Instance has default or insecure admin\
      \ username.\"\n    remediationMessage: \"Change the instance admin username.\"\
      \n    check:\n      CONTAINS:\n        arg:\n          SET:\n            itemType:\
      \ \"TEXT\"\n            items:\n              - \"root\"\n              - \"\
      admin\"\n              - \"administrator\"\n              - \"adminuser\"\n\
      \              - \"superuser\"\n              - \"sa\"\n              - \"sysadmin\"\
      \n              - \"dbadmin\"\n              - \"user\"\n              - \"\
      dbuser\"\n              - \"sys\"\n              - \"system\"\n            \
      \  - \"awsuser\"\n              - \"mysql\"\n              - \"oracle\"\n  \
      \            - \"postgres\"\n        search:\n          EXTRACT: \"CA10__masterUsername__c\"\
      \notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage: \"The RDS Instance\
      \ has a custom admin username.\"\n"
  - path: /ce/ca/aws/rds/instance-master-username/test-data.json
    md5Hash: F1234693ED9A5FB318189E06022D7A97
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-20T07:40:03Z"
              },
              "CA10__disappearanceTime__c": "2026-01-12T22:26:05Z",
              "CA10__status__c": "deleting",
              "CA10__clusterArn__c": "clusterArn",
              "CA10__engine__c": "aurora-postgresql",
              "CA10__masterUsername__c": "root",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__status__c') != 'available'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-20T07:40:03Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "stopped",
              "CA10__clusterArn__c": "clusterArn",
              "CA10__engine__c": "aurora-postgresql",
              "CA10__masterUsername__c": "admin",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__clusterArn__c').isNotEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-20T07:40:03Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__clusterArn__c": "clusterArn",
              "CA10__engine__c": "aurora-mysql",
              "CA10__masterUsername__c": "mysql",
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "599",
                  "conditionText": "setOfText(['root', 'admin', 'administrator', 'adminuser', 'superuser', 'sa', 'sysadmin', 'dbadmin', 'user', 'dbuser', 'sys', 'system', 'awsuser', 'mysql', 'oracle', 'postgres']).contains(extract('CA10__masterUsername__c'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-20T07:40:03Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__clusterArn__c": "",
              "CA10__engine__c": "mariadb",
              "CA10__masterUsername__c": "user",
              "Id": "test4"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "600",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-20T07:40:03Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__clusterArn__c": "",
              "CA10__engine__c": "mysql",
              "CA10__masterUsername__c": "qa_automation",
              "Id": "test5"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10__engine__c') == 'neptune'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-20T07:40:03Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__clusterArn__c": "",
              "CA10__engine__c": "neptune",
              "CA10__masterUsername__c": "admin",
              "Id": "test6"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "499",
                  "conditionText": "extract('CA10__engine__c') == 'docdb'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-20T07:40:03Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__clusterArn__c": "",
              "CA10__engine__c": "docdb",
              "CA10__masterUsername__c": "admin",
              "Id": "test7"
          }
      ]
  - path: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml
    md5Hash: E3FA5A211AA9AD2418645BB09047D3D3
    content: "---\nextracts:\n# Not Nullable. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__engine__c\n    value:\n      FIELD:\n\
      \        path: CA10__engine__c\n        undeterminedIf:\n          isEmpty:\
      \ \"Corrupted data. DB Instance Engine cannot be empty.\"\n# Not Nullable. Can't\
      \ have no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__endpointPort__c\n\
      \    value:\n      FIELD:\n        path: CA10__endpointPort__c\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. DB Endpoint Port cannot be empty.\"\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__publiclyAccessible__c\n    value:\n      FIELD:\n        path:\
      \ CA10__publiclyAccessible__c\n# Checkbox. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__storageEncrypted__c\n    value: \n\
      \      FIELD:\n        path: CA10__storageEncrypted__c\n# Checkbox. Can't have\
      \ no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__autoMinorVersionUpgrade__c\n\
      \    value: \n      FIELD:\n        path: CA10__autoMinorVersionUpgrade__c\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__multiAz__c\n    value: \n      FIELD:\n        path: CA10__multiAz__c\n\
      # Nullable. Values: available, backing-up, creating ...\n  - name: \"CA10__status__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__status__c\"\n# Nullable.\n\
      \  - name: \"CA10__createTime__c\"\n    value:\n      FIELD:\n        path:\
      \ \"CA10__createTime__c\"\n# Nullable.\n  - name: \"CA10__averageCpuOneMonth__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__averageCpuOneMonth__c\"\n\
      # Nullable.\n  - name: \"CA10__regionName__c\"\n    value:\n      FIELD:\n \
      \       path: \"CA10__regionName__c\"\n# Nullable.\n  - name: \"CA10__diskReadIopsAvg30d__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__diskReadIopsAvg30d__c\"\n\
      # Nullable.\n  - name: \"CA10__diskWriteIopsAvg30d__c\"\n    value:\n      FIELD:\n\
      \        path: \"CA10__diskWriteIopsAvg30d__c\"\n# Nullable.\n  - name: \"CA10__databaseConnectionsAvg30d__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__databaseConnectionsAvg30d__c\"\
      \n# Not nullable. Can't have no access, retrieved via rds:DescribeDBInstances\n\
      \  - name: \"CA10__backupRetentionPeriod__c\"\n    value:\n      FIELD:\n  \
      \      path: \"CA10__backupRetentionPeriod__c\"\n# Text.\n  - name: CA10__masterUsername__c\n\
      \    value:\n      FIELD:\n        path: CA10__masterUsername__c\n# Checkbox.\n\
      \  - name: CA10__iamDatabaseAuthenticationEnabled__c\n    value:\n      FIELD:\n\
      \        path: CA10__iamDatabaseAuthenticationEnabled__c\n# Text.\n  - name:\
      \ CA10__enabledCloudWatchLogsExports__c\n    value:\n      FIELD:\n        path:\
      \ CA10__enabledCloudWatchLogsExports__c\n# Checkbox.\n  - name: CA10__deletionProtection__c\n\
      \    value:\n      FIELD:\n        path: CA10__deletionProtection__c\n# Nullable.\
      \ Can't have no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__clusterArn__c\n\
      \    value:\n      FIELD:\n        path: CA10__clusterArn__c\n# Not nullable.\
      \ Can't have no access, retrieved via rds:DescribeDBInstances\n  - name: \"\
      CA10__monitoringInterval__c\"\n    value:\n      FIELD:\n        path: \"CA10__monitoringInterval__c\"\
      \n# Checkbox.\n  - name: CA10__copyTagsToSnapshot__c\n    value:\n      FIELD:\n\
      \        path: CA10__copyTagsToSnapshot__c\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" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__status__c') != 'available'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__clusterArn__c').isNotEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "599",
      "conditionText" : "setOfText(['root', 'admin', 'administrator', 'adminuser', 'superuser', 'sa', 'sysadmin', 'dbadmin', 'user', 'dbuser', 'sys', 'system', 'awsuser', 'mysql', 'oracle', 'postgres']).contains(extract('CA10__masterUsername__c'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "600",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__engine__c') == 'neptune'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test7",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "499",
      "conditionText" : "extract('CA10__engine__c') == 'docdb'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbInstance__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__clusterArn__c STRING,
      CA10__engine__c STRING,
      CA10__masterUsername__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-20T07:40:03Z")
    },
    "CA10__disappearanceTime__c" : new Date("2026-01-12T22:26:05Z"),
    "CA10__status__c" : "deleting",
    "CA10__clusterArn__c" : "clusterArn",
    "CA10__engine__c" : "aurora-postgresql",
    "CA10__masterUsername__c" : "root",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-20T07:40:03Z")
    },
    "CA10__status__c" : "stopped",
    "CA10__clusterArn__c" : "clusterArn",
    "CA10__engine__c" : "aurora-postgresql",
    "CA10__masterUsername__c" : "admin",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-20T07:40:03Z")
    },
    "CA10__status__c" : "available",
    "CA10__clusterArn__c" : "clusterArn",
    "CA10__engine__c" : "aurora-mysql",
    "CA10__masterUsername__c" : "mysql",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-20T07:40:03Z")
    },
    "CA10__status__c" : "available",
    "CA10__clusterArn__c" : "",
    "CA10__engine__c" : "mariadb",
    "CA10__masterUsername__c" : "user",
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-20T07:40:03Z")
    },
    "CA10__status__c" : "available",
    "CA10__clusterArn__c" : "",
    "CA10__engine__c" : "mysql",
    "CA10__masterUsername__c" : "qa_automation",
    "Id" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-20T07:40:03Z")
    },
    "CA10__status__c" : "available",
    "CA10__clusterArn__c" : "",
    "CA10__engine__c" : "neptune",
    "CA10__masterUsername__c" : "admin",
    "Id" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-20T07:40:03Z")
    },
    "CA10__status__c" : "available",
    "CA10__clusterArn__c" : "",
    "CA10__engine__c" : "docdb",
    "CA10__masterUsername__c" : "admin",
    "Id" : "test7"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDbInstance__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__clusterArn__c STRING,
          CA10__engine__c STRING,
          CA10__masterUsername__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 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 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 CollectionLib = new function () {
      this.parse = function(arg, separator, skipEmpty, skipDuplicates, sort, normalize) {
          if (arg == null) return [];
          let parts = arg.split(separator);
          return this.fromArray(parts, skipEmpty, skipDuplicates, sort, normalize);
      };
      this.fromArray = function(arr, skipEmpty, skipDuplicates, sort, normalize) {
          if (arr == null) return [];
          let result = [];
          let seen = new Set();
          arr.forEach(el => {
              let normalized = normalize ? TextLib.normalize(el) : BytesLib.normalize(el);
              if (!skipEmpty || (normalize ? TextLib.isNotEmpty(el) : BytesLib.isNotEmpty(el))) {
                  if (!skipDuplicates || !seen.has(normalized)) {
                      if (skipDuplicates) seen.add(normalized);
                      result.push(normalized);
                  }
              }
          });
          if (sort) result.sort();
          return result;
      };
      this.equal = function(left, right) {
          left = left == null ? [] : left;
          right = right == null ? [] : right;
          if (left.length !== right.length) return false;
          for (let i = 0; i < left.length; i++) {
              if (left[i] !== right[i]) return false;
          }
          return true;
      };
      this.notEqual = function(left, right) {
          return !this.equal(left, right);
      };
      this.size = function(collection) {
          return collection == null ? 0 : collection.length;
      };
      this.startsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[0] === normalizedSearch;
      };
      this.endsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[collection.length - 1] === normalizedSearch;
      };
      this.contains = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          return collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search));
      };
      this.containsAll = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.every(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
      this.containsAny = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.some(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function extract3() { if (!this.out) { this.out = obj.CA10__status__c; } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      if (TextLib.notEqual(extract3.call(extract3), 'available')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'available'", currentStateMessage: "The Instance is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__clusterArn__c; } return this.out; };
      references1.push('Cluster ARN [obj.CA10__clusterArn__c]: ' + obj.CA10__clusterArn__c);
      if (TextLib.isNotEmpty(extract6.call(extract6))) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__clusterArn__c').isNotEmpty()", currentStateMessage: "This policy doesn't apply to Cluster Instances.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function fieldChecked10() {
          if (TextLib.isEmpty(obj.CA10__engine__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10__engine__c.isEmpty()", currentStateMessage: "Corrupted data. DB Instance Engine cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__engine__c;
      }
      function extract9() { if (!this.out) { this.out = fieldChecked10(); } return this.out; };
      references1.push('Engine [obj.CA10__engine__c]: ' + obj.CA10__engine__c);
      try {
          if (TextLib.equal(extract9.call(extract9), 'neptune')) {
              return {status: 'INAPPLICABLE', conditionIndex: 399, conditionText: "extract('CA10__engine__c') == 'neptune'", currentStateMessage: "This policy doesn't apply to Neptune.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[4], conditionIndex:[400..499]
      function fieldChecked13() {
          if (TextLib.isEmpty(obj.CA10__engine__c)) {
              throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "CA10__engine__c.isEmpty()", currentStateMessage: "Corrupted data. DB Instance Engine cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__engine__c;
      }
      function extract12() { if (!this.out) { this.out = fieldChecked13(); } return this.out; };
      try {
          if (TextLib.equal(extract12.call(extract12), 'docdb')) {
              return {status: 'INAPPLICABLE', conditionIndex: 499, conditionText: "extract('CA10__engine__c') == 'docdb'", currentStateMessage: "This policy doesn't apply to DocumentDB.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[5], conditionIndex:[500..599]
      function extract15() { if (!this.out) { this.out = obj.CA10__masterUsername__c; } return this.out; };
      references1.push('Master Username [obj.CA10__masterUsername__c]: ' + obj.CA10__masterUsername__c);
      if (CollectionLib.contains(CollectionLib.fromArray(['root', 'admin', 'administrator', 'adminuser', 'superuser', 'sa', 'sysadmin', 'dbadmin', 'user', 'dbuser', 'sys', 'system', 'awsuser', 'mysql', 'oracle', 'postgres'], true, true, true, true), extract15.call(extract15), true)) {
          return {status: 'INCOMPLIANT', conditionIndex: 599, conditionText: "setOfText(['root', 'admin', 'administrator', 'adminuser', 'superuser', 'sa', 'sysadmin', 'dbadmin', 'user', 'dbuser', 'sys', 'system', 'awsuser', 'mysql', 'oracle', 'postgres']).contains(extract('CA10__masterUsername__c'))", currentStateMessage: "The RDS Instance has default or insecure admin username.", currentStateReferences: references1.join('\n'), remediation: "Change the instance admin username.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 600, conditionText: "otherwise", currentStateMessage: "The RDS Instance has a custom admin username.", 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__status__c AS CA10__status__c,
          sObject.CA10__clusterArn__c AS CA10__clusterArn__c,
          sObject.CA10__engine__c AS CA10__engine__c,
          sObject.CA10__masterUsername__c AS CA10__masterUsername__c,
          sObject.Id AS Id,
          process_CA10__CaAwsDbInstance__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__clusterArn__c AS CA10__clusterArn__c,
                  sObject.CA10__engine__c AS CA10__engine__c,
                  sObject.CA10__masterUsername__c AS CA10__masterUsername__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDbInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
