2019-08-27 02:49:38 +02:00
|
|
|
/*
|
2019-12-02 00:42:40 +01:00
|
|
|
This file is part of GNU Taler
|
2019-08-27 02:49:38 +02:00
|
|
|
(C) 2019 GNUnet e.V.
|
|
|
|
|
|
|
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
import test from "ava";
|
2019-12-02 00:42:40 +01:00
|
|
|
import {
|
2023-04-04 20:11:08 +02:00
|
|
|
parsePayPushUri,
|
|
|
|
parsePayTemplateUri,
|
2019-12-02 00:42:40 +01:00
|
|
|
parsePayUri,
|
|
|
|
parseRefundUri,
|
2023-04-04 20:11:08 +02:00
|
|
|
parseRestoreUri,
|
2019-12-02 00:42:40 +01:00
|
|
|
parseTipUri,
|
2023-04-04 20:11:08 +02:00
|
|
|
parseWithdrawUri,
|
|
|
|
stringifyPayPushUri,
|
|
|
|
stringifyPayUri,
|
|
|
|
stringifyRestoreUri,
|
2021-06-14 16:08:58 +02:00
|
|
|
} from "./taleruri.js";
|
2019-12-02 00:42:40 +01:00
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler pay url parsing: wrong scheme", (t) => {
|
2019-08-27 02:49:38 +02:00
|
|
|
const url1 = "talerfoo://";
|
|
|
|
const r1 = parsePayUri(url1);
|
|
|
|
t.is(r1, undefined);
|
|
|
|
|
|
|
|
const url2 = "taler://refund/a/b/c/d/e/f";
|
2020-04-07 10:07:32 +02:00
|
|
|
const r2 = parsePayUri(url2);
|
2019-08-27 02:49:38 +02:00
|
|
|
t.is(r2, undefined);
|
|
|
|
});
|
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler pay url parsing: defaults", (t) => {
|
2020-07-27 13:39:52 +02:00
|
|
|
const url1 = "taler://pay/example.com/myorder/";
|
2019-08-27 02:49:38 +02:00
|
|
|
const r1 = parsePayUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 13:39:52 +02:00
|
|
|
t.is(r1.merchantBaseUrl, "https://example.com/");
|
|
|
|
t.is(r1.sessionId, "");
|
2019-08-27 02:49:38 +02:00
|
|
|
|
2020-07-27 13:39:52 +02:00
|
|
|
const url2 = "taler://pay/example.com/myorder/mysession";
|
2019-08-27 02:49:38 +02:00
|
|
|
const r2 = parsePayUri(url2);
|
|
|
|
if (!r2) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 13:39:52 +02:00
|
|
|
t.is(r2.merchantBaseUrl, "https://example.com/");
|
2019-08-27 02:49:38 +02:00
|
|
|
t.is(r2.sessionId, "mysession");
|
|
|
|
});
|
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler pay url parsing: instance", (t) => {
|
2020-07-27 13:39:52 +02:00
|
|
|
const url1 = "taler://pay/example.com/instances/myinst/myorder/";
|
2019-10-01 20:45:36 +02:00
|
|
|
const r1 = parsePayUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 13:39:52 +02:00
|
|
|
t.is(r1.merchantBaseUrl, "https://example.com/instances/myinst/");
|
2019-12-06 12:47:28 +01:00
|
|
|
t.is(r1.orderId, "myorder");
|
2019-10-01 20:45:36 +02:00
|
|
|
});
|
|
|
|
|
2020-07-30 13:58:09 +02:00
|
|
|
test("taler pay url parsing (claim token)", (t) => {
|
|
|
|
const url1 = "taler://pay/example.com/instances/myinst/myorder/?c=ASDF";
|
|
|
|
const r1 = parsePayUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t.is(r1.merchantBaseUrl, "https://example.com/instances/myinst/");
|
|
|
|
t.is(r1.orderId, "myorder");
|
|
|
|
t.is(r1.claimToken, "ASDF");
|
|
|
|
});
|
2019-10-02 10:51:31 +02:00
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler refund uri parsing: non-https #1", (t) => {
|
2020-09-06 13:06:50 +02:00
|
|
|
const url1 = "taler+http://refund/example.com/myorder/";
|
2020-01-18 23:32:03 +01:00
|
|
|
const r1 = parseRefundUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
2020-03-30 12:39:32 +02:00
|
|
|
}
|
2020-07-27 13:39:52 +02:00
|
|
|
t.is(r1.merchantBaseUrl, "http://example.com/");
|
2020-03-30 12:39:32 +02:00
|
|
|
t.is(r1.orderId, "myorder");
|
2020-01-18 23:32:03 +01:00
|
|
|
});
|
|
|
|
|
2020-07-27 13:39:52 +02:00
|
|
|
test("taler pay uri parsing: non-https", (t) => {
|
|
|
|
const url1 = "taler+http://pay/example.com/myorder/";
|
2019-10-02 10:51:31 +02:00
|
|
|
const r1 = parsePayUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
2020-03-30 12:39:32 +02:00
|
|
|
}
|
2020-07-27 13:39:52 +02:00
|
|
|
t.is(r1.merchantBaseUrl, "http://example.com/");
|
2020-03-30 12:39:32 +02:00
|
|
|
t.is(r1.orderId, "myorder");
|
2019-10-02 10:51:31 +02:00
|
|
|
});
|
|
|
|
|
2020-07-27 13:39:52 +02:00
|
|
|
test("taler pay uri parsing: missing session component", (t) => {
|
|
|
|
const url1 = "taler+http://pay/example.com/myorder";
|
2019-10-02 10:51:31 +02:00
|
|
|
const r1 = parsePayUri(url1);
|
2020-07-27 13:39:52 +02:00
|
|
|
if (r1) {
|
2019-10-02 10:51:31 +02:00
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 13:39:52 +02:00
|
|
|
t.pass();
|
2019-10-01 20:45:36 +02:00
|
|
|
});
|
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler withdraw uri parsing", (t) => {
|
2020-07-27 13:39:52 +02:00
|
|
|
const url1 = "taler://withdraw/bank.example.com/12345";
|
2019-08-28 02:49:27 +02:00
|
|
|
const r1 = parseWithdrawUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 13:39:52 +02:00
|
|
|
t.is(r1.withdrawalOperationId, "12345");
|
|
|
|
t.is(r1.bankIntegrationApiBaseUrl, "https://bank.example.com/");
|
2019-10-01 20:45:36 +02:00
|
|
|
});
|
2019-11-01 18:39:23 +01:00
|
|
|
|
2020-07-27 19:57:32 +02:00
|
|
|
test("taler withdraw uri parsing (http)", (t) => {
|
|
|
|
const url1 = "taler+http://withdraw/bank.example.com/12345";
|
|
|
|
const r1 = parseWithdrawUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t.is(r1.withdrawalOperationId, "12345");
|
|
|
|
t.is(r1.bankIntegrationApiBaseUrl, "http://bank.example.com/");
|
|
|
|
});
|
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler refund uri parsing", (t) => {
|
2020-09-06 13:06:50 +02:00
|
|
|
const url1 = "taler://refund/merchant.example.com/1234/";
|
2019-11-01 18:39:23 +01:00
|
|
|
const r1 = parseRefundUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 13:39:52 +02:00
|
|
|
t.is(r1.merchantBaseUrl, "https://merchant.example.com/");
|
2019-12-05 19:38:19 +01:00
|
|
|
t.is(r1.orderId, "1234");
|
2019-11-01 18:39:23 +01:00
|
|
|
});
|
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler refund uri parsing with instance", (t) => {
|
2020-09-06 13:06:50 +02:00
|
|
|
const url1 = "taler://refund/merchant.example.com/instances/myinst/1234/";
|
2019-11-01 18:39:23 +01:00
|
|
|
const r1 = parseRefundUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2019-12-05 19:38:19 +01:00
|
|
|
t.is(r1.orderId, "1234");
|
2020-08-03 09:30:48 +02:00
|
|
|
t.is(r1.merchantBaseUrl, "https://merchant.example.com/instances/myinst/");
|
2019-11-01 18:39:23 +01:00
|
|
|
});
|
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler tip pickup uri", (t) => {
|
2020-07-27 13:39:52 +02:00
|
|
|
const url1 = "taler://tip/merchant.example.com/tipid";
|
2019-11-01 18:39:23 +01:00
|
|
|
const r1 = parseTipUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 13:39:52 +02:00
|
|
|
t.is(r1.merchantBaseUrl, "https://merchant.example.com/");
|
2019-11-01 18:39:23 +01:00
|
|
|
});
|
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler tip pickup uri with instance", (t) => {
|
2020-07-27 13:39:52 +02:00
|
|
|
const url1 = "taler://tip/merchant.example.com/instances/tipm/tipid";
|
2019-11-01 18:39:23 +01:00
|
|
|
const r1 = parseTipUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2020-08-03 09:30:48 +02:00
|
|
|
t.is(r1.merchantBaseUrl, "https://merchant.example.com/instances/tipm/");
|
2019-12-02 00:42:40 +01:00
|
|
|
t.is(r1.merchantTipId, "tipid");
|
2019-11-01 18:39:23 +01:00
|
|
|
});
|
|
|
|
|
2020-03-30 12:39:32 +02:00
|
|
|
test("taler tip pickup uri with instance and prefix", (t) => {
|
2020-07-27 13:39:52 +02:00
|
|
|
const url1 = "taler://tip/merchant.example.com/my/pfx/tipm/tipid";
|
2019-11-01 18:39:23 +01:00
|
|
|
const r1 = parseTipUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2020-08-03 09:30:48 +02:00
|
|
|
t.is(r1.merchantBaseUrl, "https://merchant.example.com/my/pfx/tipm/");
|
2019-12-02 00:42:40 +01:00
|
|
|
t.is(r1.merchantTipId, "tipid");
|
2019-11-01 18:39:23 +01:00
|
|
|
});
|
2022-08-09 15:00:45 +02:00
|
|
|
|
|
|
|
test("taler peer to peer push URI", (t) => {
|
|
|
|
const url1 = "taler://pay-push/exch.example.com/foo";
|
|
|
|
const r1 = parsePayPushUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t.is(r1.exchangeBaseUrl, "https://exch.example.com/");
|
|
|
|
t.is(r1.contractPriv, "foo");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("taler peer to peer push URI (path)", (t) => {
|
|
|
|
const url1 = "taler://pay-push/exch.example.com:123/bla/foo";
|
|
|
|
const r1 = parsePayPushUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t.is(r1.exchangeBaseUrl, "https://exch.example.com:123/bla/");
|
|
|
|
t.is(r1.contractPriv, "foo");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("taler peer to peer push URI (http)", (t) => {
|
|
|
|
const url1 = "taler+http://pay-push/exch.example.com:123/bla/foo";
|
|
|
|
const r1 = parsePayPushUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t.is(r1.exchangeBaseUrl, "http://exch.example.com:123/bla/");
|
|
|
|
t.is(r1.contractPriv, "foo");
|
|
|
|
});
|
|
|
|
|
2023-04-04 20:11:08 +02:00
|
|
|
test("taler peer to peer push URI (stringify)", (t) => {
|
|
|
|
const url = stringifyPayPushUri({
|
2022-08-09 15:00:45 +02:00
|
|
|
exchangeBaseUrl: "https://foo.example.com/bla/",
|
|
|
|
contractPriv: "123",
|
|
|
|
});
|
|
|
|
t.deepEqual(url, "taler://pay-push/foo.example.com/bla/123");
|
|
|
|
});
|
2023-04-04 20:11:08 +02:00
|
|
|
test("taler pay URI (stringify)", (t) => {
|
|
|
|
const url1 = stringifyPayUri({
|
|
|
|
merchantBaseUrl: "http://localhost:123/",
|
|
|
|
orderId: "foo",
|
|
|
|
sessionId: "",
|
|
|
|
});
|
2023-02-11 14:24:29 +01:00
|
|
|
t.deepEqual(url1, "taler+http://pay/localhost:123/foo/");
|
|
|
|
|
2023-04-04 20:11:08 +02:00
|
|
|
const url2 = stringifyPayUri({
|
|
|
|
merchantBaseUrl: "http://localhost:123/",
|
|
|
|
orderId: "foo",
|
|
|
|
sessionId: "bla",
|
|
|
|
});
|
2023-02-11 14:24:29 +01:00
|
|
|
t.deepEqual(url2, "taler+http://pay/localhost:123/foo/bla");
|
|
|
|
});
|
|
|
|
|
2023-04-04 20:11:08 +02:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
|
2023-02-11 14:24:29 +01:00
|
|
|
test("taler pay template URI (parsing)", (t) => {
|
|
|
|
const url1 =
|
|
|
|
"taler://pay-template/merchant.example.com/FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY?amount=KUDOS:5";
|
|
|
|
const r1 = parsePayTemplateUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t.deepEqual(r1.merchantBaseUrl, "https://merchant.example.com/");
|
|
|
|
t.deepEqual(r1.templateId, "FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY");
|
|
|
|
t.deepEqual(r1.templateParams.amount, "KUDOS:5");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("taler pay template URI (parsing, http with port)", (t) => {
|
|
|
|
const url1 =
|
|
|
|
"taler+http://pay-template/merchant.example.com:1234/FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY?amount=KUDOS:5";
|
|
|
|
const r1 = parsePayTemplateUri(url1);
|
|
|
|
if (!r1) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t.deepEqual(r1.merchantBaseUrl, "http://merchant.example.com:1234/");
|
|
|
|
t.deepEqual(r1.templateId, "FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY");
|
|
|
|
t.deepEqual(r1.templateParams.amount, "KUDOS:5");
|
|
|
|
});
|
2023-04-04 20:11:08 +02:00
|
|
|
|
|
|
|
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",
|
|
|
|
);
|
|
|
|
});
|