Skip to content

Commit

Permalink
test(aws-middleware-test): add mock creds for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Oct 28, 2024
1 parent fed1215 commit 6b988d4
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { test as it, describe, expect } from "vitest";

import { S3Control } from "@aws-sdk/client-s3-control";
import { describe, expect, test as it } from "vitest";

import { requireRequestsFrom } from "../../aws-util-test/src";

describe("middleware-apply-body-checksum", () => {
describe(S3Control.name, () => {
it("should add body-checksum", async () => {
const client = new S3Control({ region: "us-west-2" });
const client = new S3Control({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
headers: {
"content-md5": /^.{22}(==)?$/i,
Expand Down
43 changes: 36 additions & 7 deletions private/aws-middleware-test/src/middleware-content-length.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { test as it, describe, expect } from "vitest";

import { AccessAnalyzer } from "@aws-sdk/client-accessanalyzer";
import { S3 } from "@aws-sdk/client-s3";
import { XRay } from "@aws-sdk/client-xray";
import { describe, expect, test as it } from "vitest";

import { requireRequestsFrom } from "../../../private/aws-util-test/src";

describe("middleware-content-length", () => {
describe(AccessAnalyzer.name, () => {
it("should not add content-length if no body", async () => {
const client = new AccessAnalyzer({ region: "us-west-2" });
const client = new AccessAnalyzer({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
headers: {
"content-length": /undefined/,
Expand All @@ -24,7 +29,13 @@ describe("middleware-content-length", () => {
});

it("should add content-length if body present", async () => {
const client = new AccessAnalyzer({ region: "us-west-2" });
const client = new AccessAnalyzer({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
headers: {
"content-length": /106/,
Expand All @@ -42,7 +53,13 @@ describe("middleware-content-length", () => {

describe(S3.name, () => {
it("should not add content-length if no body", async () => {
const client = new S3({ region: "us-west-2" });
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
headers: {
"content-length": /undefined/,
Expand All @@ -58,7 +75,13 @@ describe("middleware-content-length", () => {
});

it("should add content-length if body present", async () => {
const client = new S3({ region: "us-west-2" });
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
headers: {
"content-length": /4/,
Expand All @@ -77,7 +100,13 @@ describe("middleware-content-length", () => {

describe(XRay.name, () => {
it("should add content-length if body present", async () => {
const client = new XRay({ region: "us-west-2" });
const client = new XRay({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
headers: {
"content-length": /24/,
Expand Down
11 changes: 9 additions & 2 deletions private/aws-middleware-test/src/middleware-endpoint.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test as it, describe, expect } from "vitest";

import { S3 } from "@aws-sdk/client-s3";
import { S3Control } from "@aws-sdk/client-s3-control";
import { describe, expect, test as it } from "vitest";

import { requireRequestsFrom } from "../../aws-util-test/src";

Expand All @@ -13,6 +12,10 @@ describe("middleware-endpoint", () => {
it("should resolve endpoints", async () => {
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
useFipsEndpoint: true,
useDualstackEndpoint: true,
useArnRegion: true,
Expand All @@ -33,6 +36,10 @@ describe("middleware-endpoint", () => {
it("should resolve endpoints", async () => {
const client = new S3Control({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
useFipsEndpoint: true,
useDualstackEndpoint: true,
useArnRegion: true,
Expand Down
7 changes: 5 additions & 2 deletions private/aws-middleware-test/src/middleware-retry.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test as it, describe, expect } from "vitest";

import { Lambda } from "@aws-sdk/client-lambda";
import { describe, expect, test as it } from "vitest";

import { requireRequestsFrom } from "../../aws-util-test/src";

Expand All @@ -9,6 +8,10 @@ describe("middleware-retry", () => {
it("should set retry headers", async () => {
const client = new Lambda({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});

requireRequestsFrom(client).toMatch({
Expand Down
35 changes: 29 additions & 6 deletions private/aws-middleware-test/src/middleware-serde.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { test as it, describe } from "vitest";

import { EC2 } from "@aws-sdk/client-ec2";
import { S3 } from "@aws-sdk/client-s3";
import { SageMaker } from "@aws-sdk/client-sagemaker";
import { SageMakerRuntime } from "@aws-sdk/client-sagemaker-runtime";
import { describe, test as it } from "vitest";

import { requireRequestsFrom } from "../../aws-util-test/src";

describe("middleware-serde", () => {
describe(S3.name, () => {
it("should serialize xml", async () => {
const client = new S3({ region: "us-west-2" });
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
method: "PUT",
hostname: "s3.us-west-2.amazonaws.com",
Expand Down Expand Up @@ -55,7 +60,13 @@ describe("middleware-serde", () => {

describe(EC2.name, () => {
it("should serialize query", async () => {
const client = new EC2({ region: "us-west-2" });
const client = new EC2({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
method: "POST",
hostname: "ec2.us-west-2.amazonaws.com",
Expand All @@ -79,7 +90,13 @@ describe("middleware-serde", () => {

describe(SageMaker.name, () => {
it("should serialize json", async () => {
const client = new SageMaker({ region: "us-west-2" });
const client = new SageMaker({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
method: "POST",
hostname: "api.sagemaker.us-west-2.amazonaws.com",
Expand All @@ -102,7 +119,13 @@ describe("middleware-serde", () => {

describe(SageMakerRuntime.name, () => {
it("should serialize json", async () => {
const client = new SageMakerRuntime({ region: "us-west-2" });
const client = new SageMakerRuntime({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
method: "POST",
hostname: "runtime.sagemaker.us-west-2.amazonaws.com",
Expand Down
15 changes: 12 additions & 3 deletions private/aws-middleware-test/src/util-stream.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { test as it, describe, expect } from "vitest";

import { Lambda } from "@aws-sdk/client-lambda";
import { HttpHandler, HttpResponse } from "@smithy/protocol-http";
import { HttpRequest as IHttpRequest } from "@smithy/types";
import { Uint8ArrayBlobAdapter } from "@smithy/util-stream";
import { fromUtf8 } from "@smithy/util-utf8";
import { Readable } from "stream";
import { describe, expect, test as it } from "vitest";

import { requireRequestsFrom } from "../../aws-util-test/src";

describe("util-stream", () => {
describe(Lambda.name, () => {
it("should be uniform between string and Uint8Array payloads", async () => {
const client = new Lambda({ region: "us-west-2" });
const client = new Lambda({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});
requireRequestsFrom(client).toMatch({
method: "POST",
hostname: "lambda.us-west-2.amazonaws.com",
Expand Down Expand Up @@ -54,6 +59,10 @@ describe("util-stream", () => {

const lambda = new Lambda({
region: "us-west-2",
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
});

requireRequestsFrom(lambda).toMatch({
Expand Down

0 comments on commit 6b988d4

Please sign in to comment.