diff --git a/package-lock.json b/package-lock.json index a747260..f18f07d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -373,6 +373,7 @@ "integrity": "sha512-HFN59MmQXGHVyYadKLVumYsA9dBFun/ldYxipEjzA4196jpLZd8UjEEBLkbEkvfYreDqJhZxYAWFPtrfhNpj4w==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/template": "^7.27.2", "@babel/types": "^7.28.4" @@ -2024,6 +2025,7 @@ "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" @@ -2703,7 +2705,6 @@ "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.2.tgz", "integrity": "sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA==", "license": "MIT", - "peer": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.4", @@ -2831,7 +2832,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.19", "caniuse-lite": "^1.0.30001751", @@ -3085,7 +3085,8 @@ "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", "dev": true, - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/core-js-compat": { "version": "3.46.0", @@ -3541,6 +3542,7 @@ "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=6.9.0" } @@ -3937,6 +3939,7 @@ "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "json5": "lib/cli.js" }, @@ -4277,7 +4280,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -4481,7 +4483,6 @@ "integrity": "sha512-w8GmOxZfBmKknvdXU1sdM9NHcoQejwF/4mNgj2JuEEdRaHwwF12K7e9eXn1nLZ07ad+du76mkVsyeb2rKGllsA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/estree": "1.0.8" }, @@ -4858,8 +4859,7 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD", - "peer": true + "license": "0BSD" }, "node_modules/tsx": { "version": "4.20.6", @@ -4887,7 +4887,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/src/ClientBuilder.js b/src/ClientBuilder.js index 19a85b5..d4ae9d5 100644 --- a/src/ClientBuilder.js +++ b/src/ClientBuilder.js @@ -4,6 +4,7 @@ const BaseUrlSender = require("./BaseUrlSender"); const AgentSender = require("./AgentSender"); const StaticCredentials = require("./StaticCredentials"); const SharedCredentials = require("./SharedCredentials"); +const BasicAuthCredentials = require("./BasicAuthCredentials"); const CustomHeaderSender = require("./CustomHeaderSender"); const StatusCodeSender = require("./StatusCodeSender"); const LicenseSender = require("./LicenseSender"); @@ -54,7 +55,7 @@ class ClientBuilder { this.customQueries = new Map(); function credentialsProvided() { - return signer instanceof StaticCredentials || signer instanceof SharedCredentials; + return signer instanceof StaticCredentials || signer instanceof SharedCredentials || signer instanceof BasicAuthCredentials; } } diff --git a/src/SigningSender.ts b/src/SigningSender.ts index ddb0701..7b4f936 100644 --- a/src/SigningSender.ts +++ b/src/SigningSender.ts @@ -1,5 +1,6 @@ import { Request, Response, Sender } from "./types.js"; import SharedCredentials from "./SharedCredentials.js"; +import BasicAuthCredentials from "./BasicAuthCredentials.js"; import { UnprocessableEntityError } from "./Errors.js"; interface Signer { diff --git a/tests/test_SigningSender.ts b/tests/test_SigningSender.ts index e594207..f4cef48 100644 --- a/tests/test_SigningSender.ts +++ b/tests/test_SigningSender.ts @@ -4,6 +4,7 @@ import Response from "../src/Response.js"; import SigningSender from "../src/SigningSender.js"; import StaticCredentials from "../src/StaticCredentials.js"; import SharedCredentials from "../src/SharedCredentials.js"; +import BasicAuthCredentials from "../src/BasicAuthCredentials.js"; import { UnprocessableEntityError } from "../src/Errors"; describe("A signing sender", function () { @@ -45,6 +46,16 @@ describe("A signing sender", function () { ); }); + it("signs a request with basic auth credentials.", function () { + const basicAuthCredentials = new BasicAuthCredentials(mockAuthId, mockAuthToken); + const signingSender = new SigningSender(mockSender, basicAuthCredentials); + + signingSender.send(request); + + expect("Authorization" in request.headers).to.equal(true); + expect((request.headers as Record)["Authorization"]).to.include("Basic "); + }); + it("errors if signing a POST request with shared credentials.", function () { const sharedCredentials = new SharedCredentials(mockAuthId, mockHostName); const signingSender = new SigningSender(mockSender, sharedCredentials); @@ -55,4 +66,15 @@ describe("A signing sender", function () { expect(() => signingSender.send(request)).to.throw(UnprocessableEntityError); }); + + it("does not error if signing a POST request with basic auth credentials.", function () { + const basicAuthCredentials = new BasicAuthCredentials(mockAuthId, mockAuthToken); + const signingSender = new SigningSender(mockSender, basicAuthCredentials); + const mockRequestPayload = { + foo: "bar", + }; + request.payload = mockRequestPayload; + + expect(() => signingSender.send(request)).to.not.throw(); + }); });