Skip to content

chore(functional): add tests for supported fips endpoints #2931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2021

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Oct 25, 2021

Issue

Internal JS-2904

Description

Adds tests for supported FIPS endpoints

Code used for populating test cases
// The models directory contains smithy models in *.json format
// The endpoints.json contains RIP endpoints

import { readFile, readdir, writeFile } from "fs/promises";

const findVal = (object, key) => {
  let value;
  Object.keys(object).some((k) => {
    if (k === key) {
      value = object[k];
      return true;
    }
    if (object[k] && typeof object[k] === "object") {
      value = findVal(object[k], key);
      return value !== undefined;
    }
  });
  return value;
};

const getServiceInfo = (api) => {
  return findVal(api, "aws.api#service");
};

const endpointPrefixSdkIdHash = {};
const models = await readdir("models");
for (const modelFileName of models) {
  const model = JSON.parse(
    (await readFile(`models/${modelFileName}`)).toString()
  );
  const serviceInfo = getServiceInfo(model);
  endpointPrefixSdkIdHash[
    serviceInfo.endpointPrefix === "api.tunneling.iot"
      ? "iotsecuredtunneling"
      : serviceInfo.endpointPrefix
  ] = serviceInfo.sdkId;
}

const isFipsRegion = (region) =>
  region.startsWith("fips-") || region.endsWith("-fips");

const testCases = [];
const endpoints = JSON.parse((await readFile("endpoints.json")).toString());
for (const partition of endpoints.partitions) {
  for (const [endpointPrefix, serviceConfig] of Object.entries(
    partition.services
  )) {
    for (const [region, regionConfig] of Object.entries(
      serviceConfig.endpoints
    )) {
      if (isFipsRegion(region)) {
        const { hostname } = regionConfig;
        const regionRegex = partition.regionRegex
          .replace("\\\\", "\\")
          .replace(/^\^/g, "")
          .replace(/\$$/g, "");
        const signingRegion =
          regionConfig.credentialScope?.region ||
          hostname.match(regionRegex)[0];
        testCases.push({
          endpointPrefix,
          sdkId: endpointPrefixSdkIdHash[endpointPrefix],
          region,
          signingRegion,
          hostname,
        });
      }
    }
  }
}
await writeFile("testCases.json", JSON.stringify(testCases, null, 2));

Testing

  • CI
  • Verified that yarn test:functional is successful.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr requested a review from AllanZhengYP October 25, 2021 22:47
@codecov-commenter
Copy link

Codecov Report

Merging #2931 (5278fdf) into main (df8ef52) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2931   +/-   ##
=======================================
  Coverage   58.57%   58.57%           
=======================================
  Files         558      558           
  Lines       30249    30249           
  Branches     7443     7443           
=======================================
  Hits        17719    17719           
  Misses      12530    12530           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df8ef52...5278fdf. Read the comment docs.

@trivikr trivikr merged commit 28e1a8d into aws:main Oct 25, 2021
@trivikr trivikr deleted the test-functional-endpoints-fips branch October 25, 2021 23:55
@github-actions
Copy link

github-actions bot commented Nov 9, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants