aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-04-04 15:11:08 -0300
committerSebastian <sebasjm@gmail.com>2023-04-04 15:11:27 -0300
commit7090807fcbb2e7345ad0566c0057540e34bfb9f5 (patch)
tree90dfcee47491c4514134755f52298d2c962ab536 /packages/taler-util
parent68d711b2e7f096369c922a2fa340dd39bf2cb711 (diff)
downloadwallet-core-7090807fcbb2e7345ad0566c0057540e34bfb9f5.tar.xz
fix broken tests
Diffstat (limited to 'packages/taler-util')
-rw-r--r--packages/taler-util/src/taleruri.test.ts90
-rw-r--r--packages/taler-util/src/taleruri.ts52
2 files changed, 94 insertions, 48 deletions
diff --git a/packages/taler-util/src/taleruri.test.ts b/packages/taler-util/src/taleruri.test.ts
index a6c4d89fc..ffc56a723 100644
--- a/packages/taler-util/src/taleruri.test.ts
+++ b/packages/taler-util/src/taleruri.test.ts
@@ -16,14 +16,16 @@
import test from "ava";
import {
+ parsePayPushUri,
+ parsePayTemplateUri,
parsePayUri,
- parseWithdrawUri,
parseRefundUri,
+ parseRestoreUri,
parseTipUri,
- parsePayPushUri,
- constructPayPushUri,
- parsePayTemplateUri,
- constructPayUri,
+ parseWithdrawUri,
+ stringifyPayPushUri,
+ stringifyPayUri,
+ stringifyRestoreUri,
} from "./taleruri.js";
test("taler pay url parsing: wrong scheme", (t) => {
@@ -220,22 +222,46 @@ test("taler peer to peer push URI (http)", (t) => {
t.is(r1.contractPriv, "foo");
});
-test("taler peer to peer push URI (construction)", (t) => {
- const url = constructPayPushUri({
+test("taler peer to peer push URI (stringify)", (t) => {
+ const url = stringifyPayPushUri({
exchangeBaseUrl: "https://foo.example.com/bla/",
contractPriv: "123",
});
t.deepEqual(url, "taler://pay-push/foo.example.com/bla/123");
});
-
-test("taler pay URI (construction)", (t) => {
- const url1 = constructPayUri("http://localhost:123/", "foo", "");
+test("taler pay URI (stringify)", (t) => {
+ const url1 = stringifyPayUri({
+ merchantBaseUrl: "http://localhost:123/",
+ orderId: "foo",
+ sessionId: "",
+ });
t.deepEqual(url1, "taler+http://pay/localhost:123/foo/");
- const url2 = constructPayUri("http://localhost:123/", "foo", "bla");
+ const url2 = stringifyPayUri({
+ merchantBaseUrl: "http://localhost:123/",
+ orderId: "foo",
+ sessionId: "bla",
+ });
t.deepEqual(url2, "taler+http://pay/localhost:123/foo/bla");
});
+test("taler pay URI (stringify with https)", (t) => {
+ const url1 = stringifyPayUri({
+ merchantBaseUrl: "https://localhost:123/",
+ orderId: "foo",
+ sessionId: "",
+ });
+ t.deepEqual(url1, "taler://pay/localhost:123/foo/");
+
+ const url2 = stringifyPayUri({
+ merchantBaseUrl: "https://localhost/",
+ orderId: "foo",
+ sessionId: "bla",
+ noncePriv: "123",
+ });
+ t.deepEqual(url2, "taler://pay/localhost/foo/bla?n=123");
+});
+
test("taler pay template URI (parsing)", (t) => {
const url1 =
"taler://pay-template/merchant.example.com/FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY?amount=KUDOS:5";
@@ -261,3 +287,45 @@ test("taler pay template URI (parsing, http with port)", (t) => {
t.deepEqual(r1.templateId, "FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY");
t.deepEqual(r1.templateParams.amount, "KUDOS:5");
});
+
+test("taler restore URI (parsing, http with port)", (t) => {
+ const r1 = parseRestoreUri(
+ "taler+http://restore/GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0/prov1.example.com,prov2.example.com:123",
+ );
+ if (!r1) {
+ t.fail();
+ return;
+ }
+ t.deepEqual(
+ r1.walletRootPriv,
+ "GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0",
+ );
+ t.deepEqual(r1.providers[0], "http://prov1.example.com/");
+ t.deepEqual(r1.providers[1], "http://prov2.example.com:123/");
+});
+test("taler restore URI (parsing, https with port)", (t) => {
+ const r1 = parseRestoreUri(
+ "taler://restore/GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0/prov1.example.com,prov2.example.com:234,https%3A%2F%2Fprov1.example.com%2F",
+ );
+ if (!r1) {
+ t.fail();
+ return;
+ }
+ t.deepEqual(
+ r1.walletRootPriv,
+ "GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0",
+ );
+ t.deepEqual(r1.providers[0], "https://prov1.example.com/");
+ t.deepEqual(r1.providers[1], "https://prov2.example.com:234/");
+});
+
+test("taler restore URI (stringify)", (t) => {
+ const url = stringifyRestoreUri({
+ walletRootPriv: "GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0",
+ providers: ["http://prov1.example.com", "https://prov2.example.com:234/"],
+ });
+ t.deepEqual(
+ url,
+ "taler://restore/GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0/http%3A%2F%2Fprov1.example.com%2F,https%3A%2F%2Fprov2.example.com%3A234%2F",
+ );
+});
diff --git a/packages/taler-util/src/taleruri.ts b/packages/taler-util/src/taleruri.ts
index e641f1d27..bd63fd103 100644
--- a/packages/taler-util/src/taleruri.ts
+++ b/packages/taler-util/src/taleruri.ts
@@ -35,8 +35,8 @@ export interface PayUriResult {
merchantBaseUrl: string;
orderId: string;
sessionId: string;
- claimToken: string | undefined;
- noncePriv: string | undefined;
+ claimToken?: string;
+ noncePriv?: string;
}
export interface PayTemplateUriResult {
@@ -96,10 +96,7 @@ export interface DevExperimentUri {
export interface BackupRestoreUri {
type: TalerUriAction.Restore;
walletRootPriv: string;
- providers: {
- name: string;
- url: string;
- }[];
+ providers: Array<string>;
}
/**
@@ -535,9 +532,9 @@ export function parseRefundUri(s: string): RefundUriResult | undefined {
return undefined;
}
const host = parts[0].toLowerCase();
- // const sessionId = parts[parts.length - 1];
- const orderId = parts[parts.length - 1];
- const pathSegments = parts.slice(1, parts.length - 1);
+ const sessionId = parts[parts.length - 1];
+ const orderId = parts[parts.length - 2];
+ const pathSegments = parts.slice(1, parts.length - 2);
const hostAndSegments = [host, ...pathSegments].join("/");
const merchantBaseUrl = canonicalizeBaseUrl(
`${pi.innerProto}://${hostAndSegments}/`,
@@ -576,10 +573,12 @@ export function parseRestoreUri(uri: string): BackupRestoreUri | undefined {
const walletRootPriv = parts[0];
if (!walletRootPriv) return undefined;
- const providers = new Array<{ name: string; url: string }>();
+ const providers = new Array<string>();
parts[1].split(",").map((name) => {
- const url = canonicalizeBaseUrl(`${pi.innerProto}://${name}/`);
- providers.push({ name, url });
+ const url = canonicalizeBaseUrl(
+ `${pi.innerProto}://${decodeURIComponent(name)}/`,
+ );
+ providers.push(url);
});
return {
type: TalerUriAction.Restore,
@@ -597,10 +596,7 @@ export function parseRestoreUri(uri: string): BackupRestoreUri | undefined {
*/
export function constructRecoveryUri(args: {
walletRootPriv: string;
- providers: {
- name: string;
- url: string;
- }[];
+ providers: string[];
}): string {
return stringifyRestoreUri(args);
}
@@ -652,26 +648,6 @@ export function stringifyPayUri({
claimToken,
noncePriv,
}: Omit<PayUriResult, "type">): string {
- // const base = canonicalizeBaseUrl(merchantBaseUrl);
- // const url = new URL(base);
- // const isHttp = base.startsWith("http://");
- // let result = isHttp ? `taler+http://pay/` : `taler://pay/`;
- // result += url.hostname;
- // if (url.port != "") {
- // result += `:${url.port}`;
- // }
- // result += `${url.pathname}${orderId}/${sessionId}`;
- // const qp = new URLSearchParams();
- // if (claimToken) {
- // qp.append("c", claimToken);
- // }
- // if (noncePriv) {
- // qp.append("n", noncePriv);
- // }
- // const queryPart = qp.toString();
- // if (queryPart) {
- // result += "?" + queryPart;
- // }
const { proto, path, query } = getUrlInfo(merchantBaseUrl, {
c: claimToken,
n: noncePriv,
@@ -700,7 +676,9 @@ export function stringifyRestoreUri({
providers,
walletRootPriv,
}: Omit<BackupRestoreUri, "type">): string {
- const list = providers.map((p) => `${new URL(p.url).hostname}`).join("m");
+ const list = providers
+ .map((url) => `${encodeURIComponent(new URL(url).href)}`)
+ .join(",");
return `taler://restore/${walletRootPriv}/${list}`;
}