diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-09-15 17:27:02 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-09-15 17:27:02 +0200 |
commit | e68446e0a8a4a54b99ba5773a9f7ff17837a393b (patch) | |
tree | d35410d8a0d4e3ea00de8cad8f671ce5f5e5bbbe /src/mint-lib | |
parent | 1b0f8609901eb8184194144cc20a194534c81a4a (diff) |
adding tests for /wire
Diffstat (limited to 'src/mint-lib')
-rw-r--r-- | src/mint-lib/mint_api_context.c | 23 | ||||
-rw-r--r-- | src/mint-lib/mint_api_wire.c | 9 | ||||
-rw-r--r-- | src/mint-lib/test-mint-home/config/mint-common.conf | 15 | ||||
-rw-r--r-- | src/mint-lib/test-mint-home/sepa.json | 6 | ||||
-rw-r--r-- | src/mint-lib/test_mint_api.c | 35 |
5 files changed, 80 insertions, 8 deletions
diff --git a/src/mint-lib/mint_api_context.c b/src/mint-lib/mint_api_context.c index 9beeef149..5a14b4a46 100644 --- a/src/mint-lib/mint_api_context.c +++ b/src/mint-lib/mint_api_context.c @@ -435,6 +435,29 @@ MAC_download_get_result (struct MAC_DownloadBuffer *db, { json_t *json; json_error_t error; + char *ct; + + if ( (CURLE_OK != + curl_easy_getinfo (eh, + CURLINFO_CONTENT_TYPE, + &ct)) || + (NULL == ct) || + (0 != strcasecmp (ct, + "application/json")) ) + { + /* No content type or explicitly not JSON, refuse to parse + (but keep response code) */ + if (CURLE_OK != + curl_easy_getinfo (eh, + CURLINFO_RESPONSE_CODE, + response_code)) + { + /* unexpected error... */ + GNUNET_break (0); + *response_code = 0; + } + return NULL; + } json = NULL; if (0 == db->eno) diff --git a/src/mint-lib/mint_api_wire.c b/src/mint-lib/mint_api_wire.c index 7641af7ad..f1bbb0997 100644 --- a/src/mint-lib/mint_api_wire.c +++ b/src/mint-lib/mint_api_wire.c @@ -284,6 +284,7 @@ handle_wire_method_finished (void *cls, NULL); json_decref (json); TALER_MINT_wire_cancel (wh); + return; } /* pass on successful reply */ wh->cb (wh->cb_cls, @@ -345,6 +346,11 @@ request_wire_method (struct TALER_MINT_WireHandle *wh) curl_easy_setopt (eh, CURLOPT_WRITEDATA, &wh->db)); + /* The default is 'disabled', but let's be sure */ + GNUNET_assert (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_FOLLOWLOCATION, + (long) 0)); ctx = MAH_handle_to_context (wh->mint); wh->job = MAC_job_add (ctx, eh, @@ -514,7 +520,8 @@ handle_wire_finished (void *cls, 0, NULL, NULL); - json_decref (json); + if (NULL != json) + json_decref (json); TALER_MINT_wire_cancel (wh); } diff --git a/src/mint-lib/test-mint-home/config/mint-common.conf b/src/mint-lib/test-mint-home/config/mint-common.conf index 1b8aa4218..eb2f7e90b 100644 --- a/src/mint-lib/test-mint-home/config/mint-common.conf +++ b/src/mint-lib/test-mint-home/config/mint-common.conf @@ -2,9 +2,12 @@ # Currency supported by the mint (can only be one) CURRENCY = EUR -# Wire format supproted by the mint -# TEST is used for testing... (what a shock) -WIREFORMAT = TEST +# Wire format supported by the mint +# We use 'test' for testing, in principle we should +# run tests for all supported wire formats... +# (we should first implement support for a mint running +# with multiple formats at the same time). +WIREFORMAT = test # HTTP port the mint listens to PORT = 8081 @@ -21,3 +24,9 @@ TESTRUN = YES [mintdb-postgres] DB_CONN_STR = "postgres:///talercheck" + +[mint-wire-sepa] +SEPA_RESPONSE_FILE = "test-mint-home/sepa.json" + +[mint-wire-test] +REDIRECT_URL = "http://www.taler.net/" diff --git a/src/mint-lib/test-mint-home/sepa.json b/src/mint-lib/test-mint-home/sepa.json new file mode 100644 index 000000000..36d12f661 --- /dev/null +++ b/src/mint-lib/test-mint-home/sepa.json @@ -0,0 +1,6 @@ +{ + "receiver_name": "Max Mustermann", + "iban": "DE89370400440532013000", + "bic": "COBADEFF370", + "sig": "8M5YJXM68PRAXKH76HYEBCJW657B23JA0RFGNDMZK2379YZMT626H1BN89KC0M1KJBWGYEN5Z763Q0Y7MCTZQ6BPPT7D9KFCTW60C10" +}
\ No newline at end of file diff --git a/src/mint-lib/test_mint_api.c b/src/mint-lib/test_mint_api.c index fdadcd2ca..cd1a094c6 100644 --- a/src/mint-lib/test_mint_api.c +++ b/src/mint-lib/test_mint_api.c @@ -26,6 +26,15 @@ #include <gnunet/gnunet_util_lib.h> #include <microhttpd.h> +/** + * Is the configuration file is set to include wire format 'test'? + */ +#define WIRE_TEST 1 + +/** + * Is the configuration file is set to include wire format 'sepa'? + */ +#define WIRE_SEPA 0 /** * Main execution context for the main loop. @@ -1357,7 +1366,6 @@ interpreter_run (void *cls, &coin_pub.eddsa_pub); cmd->details.withdraw_sign.blinding_key.rsa_blinding_key = GNUNET_CRYPTO_rsa_blinding_key_create (GNUNET_CRYPTO_rsa_public_key_len (cmd->details.withdraw_sign.pk->key.rsa_public_key)); - cmd->details.withdraw_sign.wsh = TALER_MINT_withdraw_sign (mint, cmd->details.withdraw_sign.pk, @@ -1442,7 +1450,6 @@ interpreter_run (void *cls, fail (is); return; } - GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, &coin_pub.eddsa_pub); @@ -1464,6 +1471,7 @@ interpreter_run (void *cls, { struct TALER_DepositRequestPS dr; + memset (&dr, 0, sizeof (dr)); dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS)); dr.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT); dr.h_contract = h_contract; @@ -1482,7 +1490,6 @@ interpreter_run (void *cls, GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv, &dr.purpose, &coin_sig.eddsa_signature)); - } cmd->details.deposit.dh = TALER_MINT_deposit (mint, @@ -1980,6 +1987,26 @@ run (void *cls, }; static struct Command commands[] = { + /* *************** start of /wire testing ************** */ + +#if WIRE_TEST + { .oc = OC_WIRE, + .label = "wire", + /* /wire/test replies with a 302 redirect */ + .expected_response_code = MHD_HTTP_FOUND }, +#endif +#if WIRE_SEPA + { .oc = OC_WIRE, + .label = "wire", + /* /wire/sepa replies with a 200 redirect */ + .expected_response_code = MHD_HTTP_OK }, +#endif + /* *************** end of /wire testing ************** */ + +#if WIRE_TEST + /* None of this works if 'test' is not allowed as we do + /admin/add/incoming with format 'test' */ + /* Fill reserve with EUR:5.01, as withdraw fee is 1 ct per config */ { .oc = OC_ADMIN_ADD_INCOMING, .label = "create-reserve-1", @@ -2126,8 +2153,8 @@ run (void *cls, // FIXME: also test with coin that was already melted // (signature differs from coin that was deposited...) - /* *************** end of /refresh testing ************** */ +#endif { .oc = OC_END } }; |