Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2026 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify it under the
6 : terms of the GNU General Public License as published by the Free Software
7 : Foundation; either version 3, or (at your option) any later version.
8 :
9 : TALER is distributed in the hope that it will be useful, but WITHOUT ANY
10 : WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 : A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 :
13 : You should have received a copy of the GNU General Public License along with
14 : TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15 : */
16 : /**
17 : * @file backend/test_merchant_kyc_order.c
18 : * @brief Test deterministic ordering of KYC response data
19 : */
20 : #include "platform.h"
21 : #include <gnunet/gnunet_util_lib.h>
22 : #include <taler/taler_json_lib.h>
23 : #include "taler-merchant-httpd_kyc-order.h"
24 :
25 :
26 : /**
27 : * Check one entry in a sorted KYC response.
28 : *
29 : * @param data KYC response array
30 : * @param index index to check
31 : * @param h_wire expected account hash
32 : * @param exchange_url expected exchange URL
33 : */
34 : static void
35 3 : check_entry (const json_t *data,
36 : size_t index,
37 : const char *h_wire,
38 : const char *exchange_url)
39 : {
40 3 : const json_t *entry = json_array_get (data,
41 : index);
42 :
43 3 : GNUNET_assert (0 ==
44 : strcmp (h_wire,
45 : json_string_value (
46 : json_object_get (entry,
47 : "h_wire"))));
48 3 : GNUNET_assert (0 ==
49 : strcmp (exchange_url,
50 : json_string_value (
51 : json_object_get (entry,
52 : "exchange_url"))));
53 3 : }
54 :
55 :
56 : int
57 1 : main (int argc,
58 : char *const argv[])
59 : {
60 : json_t *first;
61 : json_t *second;
62 : char *first_canonical;
63 : char *second_canonical;
64 : struct GNUNET_ShortHashCode first_etag;
65 : struct GNUNET_ShortHashCode second_etag;
66 :
67 : (void) argc;
68 : (void) argv;
69 1 : first = json_pack (
70 : "[{s:s,s:s},{s:s,s:s},{s:s,s:s}]",
71 : "h_wire", "BBBB",
72 : "exchange_url", "https://b.example/",
73 : "h_wire", "AAAA",
74 : "exchange_url", "https://z.example/",
75 : "h_wire", "AAAA",
76 : "exchange_url", "https://a.example/");
77 1 : second = json_pack (
78 : "[{s:s,s:s},{s:s,s:s},{s:s,s:s}]",
79 : "h_wire", "AAAA",
80 : "exchange_url", "https://a.example/",
81 : "h_wire", "BBBB",
82 : "exchange_url", "https://b.example/",
83 : "h_wire", "AAAA",
84 : "exchange_url", "https://z.example/");
85 1 : GNUNET_assert (NULL != first);
86 1 : GNUNET_assert (NULL != second);
87 :
88 1 : TMH_kyc_data_sort (first);
89 1 : TMH_kyc_data_sort (second);
90 1 : check_entry (first,
91 : 0,
92 : "AAAA",
93 : "https://a.example/");
94 1 : check_entry (first,
95 : 1,
96 : "AAAA",
97 : "https://z.example/");
98 1 : check_entry (first,
99 : 2,
100 : "BBBB",
101 : "https://b.example/");
102 1 : GNUNET_assert (json_equal (first,
103 : second));
104 1 : first_canonical = TALER_JSON_canonicalize (first);
105 1 : second_canonical = TALER_JSON_canonicalize (second);
106 1 : GNUNET_assert (0 ==
107 : strcmp (first_canonical,
108 : second_canonical));
109 1 : GNUNET_assert (GNUNET_YES ==
110 : GNUNET_CRYPTO_hkdf_gnunet (&first_etag,
111 : sizeof (first_etag),
112 : "KYC-SALT",
113 : strlen ("KYC-SALT"),
114 : first_canonical,
115 : strlen (first_canonical)));
116 1 : GNUNET_assert (GNUNET_YES ==
117 : GNUNET_CRYPTO_hkdf_gnunet (&second_etag,
118 : sizeof (second_etag),
119 : "KYC-SALT",
120 : strlen ("KYC-SALT"),
121 : second_canonical,
122 : strlen (second_canonical)));
123 1 : GNUNET_assert (0 ==
124 : GNUNET_memcmp (&first_etag,
125 : &second_etag));
126 :
127 1 : GNUNET_free (first_canonical);
128 1 : GNUNET_free (second_canonical);
129 1 : json_decref (first);
130 1 : json_decref (second);
131 1 : return 0;
132 : }
|