Require HTTPS-only external pricing-provider URLs and verify the adapter contract with the application suite.
This commit is contained in:
@@ -10,10 +10,21 @@ export function createHttpPricingProvider({
|
|||||||
throw new Error('Pricing provider endpoint is required.');
|
throw new Error('Pricing provider endpoint is required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let parsedUrl;
|
||||||
|
try {
|
||||||
|
parsedUrl = new URL(endpoint);
|
||||||
|
} catch {
|
||||||
|
throw new Error('Pricing provider endpoint must be a valid HTTPS URL.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsedUrl.protocol !== 'https:') {
|
||||||
|
throw new Error('Pricing provider endpoint must use HTTPS.');
|
||||||
|
}
|
||||||
|
|
||||||
return createPricingProvider({
|
return createPricingProvider({
|
||||||
id,
|
id,
|
||||||
async observe(input) {
|
async observe(input) {
|
||||||
const url = new URL(endpoint);
|
const url = new URL(parsedUrl.toString());
|
||||||
for (const [key, value] of Object.entries(input)) {
|
for (const [key, value] of Object.entries(input)) {
|
||||||
if (value) url.searchParams.set(key, value);
|
if (value) url.searchParams.set(key, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,26 @@ test("fixture provider returns deterministic normalized observations", async ()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("http provider rejects insecure or malformed external provider URLs", () => {
|
||||||
|
assert.throws(
|
||||||
|
() =>
|
||||||
|
createHttpPricingProvider({
|
||||||
|
id: "http-provider",
|
||||||
|
endpoint: "http://provider.example/prices",
|
||||||
|
}),
|
||||||
|
/HTTPS/i,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() =>
|
||||||
|
createHttpPricingProvider({
|
||||||
|
id: "http-provider",
|
||||||
|
endpoint: "not-a-url",
|
||||||
|
}),
|
||||||
|
/valid https URL/i,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("http provider sends mapping context and normalizes its response", async () => {
|
test("http provider sends mapping context and normalizes its response", async () => {
|
||||||
let request;
|
let request;
|
||||||
const provider = createHttpPricingProvider({
|
const provider = createHttpPricingProvider({
|
||||||
|
|||||||
Reference in New Issue
Block a user