summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-02-06 19:35:55 +0100
committerFlorian Dold <florian@dold.me>2024-02-06 19:35:55 +0100
commit6c496c070d47e26034a3e2dd6d14a1a9ea42b729 (patch)
tree7d9da9321c4d6875ef068cd56b810f58a5f03914
parent963aef5366097bfd35647efc4d8b2ce04aa565dc (diff)
downloadwallet-core-6c496c070d47e26034a3e2dd6d14a1a9ea42b729.tar.gz
wallet-core-6c496c070d47e26034a3e2dd6d14a1a9ea42b729.tar.bz2
wallet-core-6c496c070d47e26034a3e2dd6d14a1a9ea42b729.zip
harness: do not follow redirects in certain tests
m---------build-system/taler-build-scripts0
-rw-r--r--packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts11
-rw-r--r--packages/taler-util/src/http-common.ts8
-rw-r--r--packages/taler-util/src/http-impl.node.ts5
4 files changed, 17 insertions, 7 deletions
diff --git a/build-system/taler-build-scripts b/build-system/taler-build-scripts
-Subproject 001f5dd081fc8729ff8def90c4a1c3f93eb8689
+Subproject 23538677f6c6be2a62f38dc6137ecdd1c76b7b1
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts
index 21e2b4a4e..8e664dfa9 100644
--- a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts
+++ b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts
@@ -297,8 +297,11 @@ async function testWithClaimToken(
url.searchParams.set("session_id", sessionId);
const httpResp = await httpLib.fetch(url.href, {
headers: { Accept: "text/html" },
+ redirect: "manual",
});
- console.log(`requesting GET ${url.href}, expected 302 got ${httpResp.status}`);
+ console.log(
+ `requesting GET ${url.href}, expected 302 got ${httpResp.status}`,
+ );
t.assertDeepEqual(httpResp.status, 302);
const location = httpResp.headers.get("Location");
console.log("location header:", location);
@@ -554,6 +557,7 @@ async function testWithoutClaimToken(
url.searchParams.set("session_id", sessionId);
const httpResp = await httpLib.fetch(url.href, {
headers: { Accept: "text/html" },
+ redirect: "manual",
});
t.assertDeepEqual(httpResp.status, 302);
const location = httpResp.headers.get("Location");
@@ -569,9 +573,8 @@ async function testWithoutClaimToken(
* specification of the endpoint.
*/
export async function runMerchantSpecPublicOrdersTest(t: GlobalTestState) {
- const { bank, exchange, merchant } = await createSimpleTestkudosEnvironmentV2(
- t,
- );
+ const { bank, exchange, merchant } =
+ await createSimpleTestkudosEnvironmentV2(t);
// Base URL for the default instance.
const merchantBaseUrl = merchant.makeInstanceBaseUrl();
diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts
index 705881801..3973e66fb 100644
--- a/packages/taler-util/src/http-common.ts
+++ b/packages/taler-util/src/http-common.ts
@@ -27,7 +27,7 @@ import {
} from "./index.js";
import { Logger } from "./logging.js";
import { TalerErrorCode } from "./taler-error-codes.js";
-import { Duration, AbsoluteTime } from "./time.js";
+import { AbsoluteTime, Duration } from "./time.js";
import { TalerErrorDetail } from "./wallet-types.js";
const textEncoder = new TextEncoder();
@@ -65,6 +65,12 @@ export interface HttpRequestOptions {
cancellationToken?: CancellationToken;
body?: string | ArrayBuffer | object;
+
+ /**
+ * How to handle redirects.
+ * Same semantics as WHATWG fetch.
+ */
+ redirect?: "follow" | "error" | "manual";
}
/**
diff --git a/packages/taler-util/src/http-impl.node.ts b/packages/taler-util/src/http-impl.node.ts
index b9c007b35..8ca2deecd 100644
--- a/packages/taler-util/src/http-impl.node.ts
+++ b/packages/taler-util/src/http-impl.node.ts
@@ -21,7 +21,7 @@
*/
import * as net from "node:net";
import type { ClientRequest, IncomingMessage } from "node:http";
-import { RedirectableRequest, http, https } from "follow-redirects";
+import { FollowOptions, RedirectableRequest, http, https } from "follow-redirects";
import { RequestOptions } from "node:http";
import { TalerError } from "./errors.js";
import { encodeBody, getDefaultHeaders, HttpLibArgs } from "./http-common.js";
@@ -141,7 +141,7 @@ export class HttpLibImpl implements HttpRequestLibrary {
throw Error(`unsupported protocol (${parsedUrl.protocol})`);
}
- const options: RequestOptions = {
+ const options: RequestOptions & FollowOptions<RequestOptions> = {
protocol,
port: parsedUrl.port,
host: parsedUrl.hostname,
@@ -149,6 +149,7 @@ export class HttpLibImpl implements HttpRequestLibrary {
path,
headers: requestHeadersMap,
timeout: timeoutMs,
+ followRedirects: opt?.redirect !== "manual",
};
const chunks: Uint8Array[] = [];