diff options
author | Christian Blättler <blatc2@bfh.ch> | 2024-03-20 07:53:49 +0100 |
---|---|---|
committer | Christian Blättler <blatc2@bfh.ch> | 2024-03-20 07:53:49 +0100 |
commit | a4c5cda0a40ef1987d93b7aacaa7caa993f8b838 (patch) | |
tree | b58e42d775d9d8cbd83b5d6cb2db00391fc6a8c8 /src/backend | |
parent | 4ebac01e89badb29d361b49310cdd1cc6397b563 (diff) |
first smoke tests
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders.c | 152 |
1 files changed, 78 insertions, 74 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index cf32f886..3a64d5a3 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -1434,6 +1434,8 @@ serialize_order (struct OrderContext *oc) } oc->serialize_order.contract = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_int64 ("version", + oc->parse_order.version), GNUNET_JSON_pack_string ("summary", oc->parse_order.summary), GNUNET_JSON_pack_allow_null ( @@ -1480,7 +1482,7 @@ serialize_order (struct OrderContext *oc) GNUNET_JSON_pack_array_incref ("exchanges", oc->set_exchanges.exchanges), TALER_JSON_pack_amount ("max_fee", - &oc->parse_order.max_fee), + &oc->set_max_fee.max_fee), TALER_JSON_pack_amount ("amount", &oc->parse_order.brutto), GNUNET_JSON_pack_allow_null ( @@ -1748,7 +1750,7 @@ parse_order (struct OrderContext *oc) ret); return; } - if (NULL == version || 0 == strcmp("v0", version)) + if (NULL == version || 0 == strcmp("0", version)) { oc->parse_order.version = TALER_MCV_V0; @@ -1774,9 +1776,32 @@ parse_order (struct OrderContext *oc) return; } } - else if (0 != strcmp("v1", version)) + else if (0 == strcmp("1", version)) { oc->parse_order.version = TALER_MCV_V1; + + if (! json_is_array(oc->parse_order.choices)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + reply_with_error (oc, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "order.choices is not a valid array"); + return; + } + + if (oc->parse_order.token_types != NULL && + ! json_is_object(oc->parse_order.token_types)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + reply_with_error (oc, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "order.token_types is not a valid object"); + return; + } } else { @@ -1785,17 +1810,7 @@ parse_order (struct OrderContext *oc) reply_with_error (oc, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_VERSION_MALFORMED, - "invalid version specified in order, supported are null, 'v0' or 'v1'"); - return; - } - if (NULL == oc->parse_order.choices && TALER_MCV_V0 != oc->parse_order.version) - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - reply_with_error (oc, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_UNEXPECTED_REQUEST_ERROR, - "choices array must not be null for v1 contracts"); + "invalid version specified in order, supported are null, '0' or '1'"); return; } if (! TMH_test_exchange_configured_for_currency ( @@ -2101,73 +2116,60 @@ parse_token_types (struct OrderContext *oc) const char *key; json_t *value; - GNUNET_array_grow (oc->parse_token_types.authorities, - oc->parse_token_types.authorities_len, - json_object_size(oc->parse_order.token_types)); - json_object_foreach ((json_t*) oc->parse_order.token_types, key, value) { struct TALER_MerchantContractTokenAuthority authority; - const struct json_t *pub_key; - - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_object_const ("key", &pub_key), - GNUNET_JSON_spec_bool ("critical", &authority.critical), - }; + const json_t *jpublic_key = NULL; - if (GNUNET_OK != - GNUNET_JSON_parse (value, - spec, - NULL, - NULL)) { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - reply_with_error (oc, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "token_types"); - return; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_object_const ("key", &jpublic_key), + GNUNET_JSON_spec_bool ("critical", &authority.critical), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (value, + spec, + NULL, + NULL)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + reply_with_error (oc, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "token_types failed to parse"); + return; + } } - const char *cipher = NULL; - - struct GNUNET_JSON_Specification kspec[] = { - GNUNET_JSON_spec_string ("cipher", &cipher), - GNUNET_JSON_spec_rsa_public_key("public_key", &authority.key.public_key.details.rsa_public_key), - }; - if (GNUNET_OK != - GNUNET_JSON_parse (pub_key, - kspec, - NULL, - NULL)) { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (kspec); - reply_with_error (oc, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "token_types.key"); - return; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_rsa_public_key ("rsa_pub", &authority.key.public_key.details.rsa_public_key), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (jpublic_key, + spec, + NULL, + NULL)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + reply_with_error (oc, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "key object of token type is invalid"); + return; + } } - if (0 == strcmp("rsa", cipher)) - { - authority.key.public_key.cipher = GNUNET_CRYPTO_BSA_RSA; - } - else - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (kspec); - reply_with_error (oc, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "token_types.key.cipher"); - return; - } + authority.key.public_key.cipher = GNUNET_CRYPTO_BSA_RSA; GNUNET_CRYPTO_rsa_public_key_hash ( authority.key.public_key.details.rsa_public_key, @@ -2209,17 +2211,16 @@ parse_token_types (struct OrderContext *oc) /* case listed to make compilers happy */ GNUNET_assert (0); } - json_decref (oc->merge_inventory.products); reply_with_error (oc, http_status, ec, - "token family public key unknown"); + "token type public key unknown"); return; } + // TODO: Copy relevant fields from key_details to authority strcpy((char *) authority.label, key); strcpy((char *) authority.summary, key_details.token_family.description); - // TODO: Copy summary_i18n switch (key_details.token_family.kind) { case TALER_MERCHANTDB_TFK_Subscription: @@ -2264,13 +2265,14 @@ parse_choices (struct OrderContext *oc) &jinputs), GNUNET_JSON_spec_array_const ("outputs", &joutputs), + GNUNET_JSON_spec_end () }; enum GNUNET_GenericReturnValue ret; ret = GNUNET_JSON_parse (json_array_get (oc->parse_order.choices, i), - spec, - &error_name, - &error_line); + spec, + &error_name, + &error_line); if (GNUNET_OK != ret) { GNUNET_JSON_parse_free (spec); @@ -2314,6 +2316,7 @@ parse_choices (struct OrderContext *oc) GNUNET_JSON_spec_uint32 ("number", &input.details.token.number), &no_number), + GNUNET_JSON_spec_end() }; const char *ename; @@ -2425,6 +2428,7 @@ parse_choices (struct OrderContext *oc) GNUNET_JSON_spec_uint32 ("number", &output.details.token.number), &no_number), + GNUNET_JSON_spec_end() }; const char *ename; |