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 {
|
|
|
|
parsePayUri,
|
|
|
|
parseWithdrawUri,
|
|
|
|
parseRefundUri,
|
|
|
|
parseTipUri,
|
|
|
|
} from "./taleruri";
|
|
|
|
|
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-07-27 13:39:52 +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-07-27 13:39:52 +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-07-27 13:39:52 +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
|
|
|
});
|