summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_oauth.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_oauth.c')
-rw-r--r--src/testing/testing_api_cmd_oauth.c58
1 files changed, 43 insertions, 15 deletions
diff --git a/src/testing/testing_api_cmd_oauth.c b/src/testing/testing_api_cmd_oauth.c
index 9c2fef8e4..80d38e4c8 100644
--- a/src/testing/testing_api_cmd_oauth.c
+++ b/src/testing/testing_api_cmd_oauth.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -40,6 +40,11 @@ struct OAuthState
struct MHD_Daemon *mhd;
/**
+ * Birthdate that the oauth server should return in a response, may be NULL
+ */
+ const char *birthdate;
+
+ /**
* Port to listen on.
*/
uint16_t port;
@@ -79,7 +84,7 @@ append (char **target,
}
-static enum MHD_Result
+static MHD_RESULT
handle_post (void *cls,
enum MHD_ValueKind kind,
const char *key,
@@ -131,16 +136,17 @@ handle_post (void *cls,
*
* @param cls argument given together with the function
* pointer when the handler was registered with MHD
+ * @param connection the connection being handled
* @param url the requested url
* @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
* #MHD_HTTP_METHOD_PUT, etc.)
* @param version the HTTP version string (i.e.
- * #MHD_HTTP_VERSION_1_1)
+ * MHD_HTTP_VERSION_1_1)
* @param upload_data the data being uploaded (excluding HEADERS,
* for a POST that fits into memory and that is encoded
* with a supported encoding, the POST data will NOT be
* given in upload_data and is instead available as
- * part of #MHD_get_connection_values; very large POST
+ * part of MHD_get_connection_values(); very large POST
* data *will* be made available incrementally in
* @a upload_data)
* @param[in,out] upload_data_size set initially to the size of the
@@ -153,14 +159,14 @@ handle_post (void *cls,
* with plenty of upload data) this allows the application
* to easily associate some request-specific state.
* If necessary, this state can be cleaned up in the
- * global #MHD_RequestCompletedCallback (which
+ * global MHD_RequestCompletedCallback (which
* can be set with the #MHD_OPTION_NOTIFY_COMPLETED).
* Initially, `*con_cls` will be NULL.
* @return #MHD_YES if the connection was handled successfully,
* #MHD_NO if the socket must be closed due to a serious
* error while handling the request
*/
-static enum MHD_Result
+static MHD_RESULT
handler_cb (void *cls,
struct MHD_Connection *connection,
const char *url,
@@ -171,23 +177,36 @@ handler_cb (void *cls,
void **con_cls)
{
struct RequestCtx *rc = *con_cls;
+ struct OAuthState *oas = cls;
unsigned int hc;
json_t *body;
- (void) cls;
(void) version;
if (0 == strcasecmp (method,
MHD_HTTP_METHOD_GET))
{
+ json_t *data =
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("id",
+ "XXXID12345678"),
+ GNUNET_JSON_pack_string ("first_name",
+ "Bob"),
+ GNUNET_JSON_pack_string ("last_name",
+ "Builder"));
+
+ if (NULL != oas->birthdate)
+ GNUNET_assert (0 ==
+ json_object_set_new (data,
+ "birthdate",
+ json_string_nocheck (
+ oas->birthdate)));
+
body = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string (
"status",
"success"),
GNUNET_JSON_pack_object_steal (
- "data",
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("id",
- "XXXID12345678"))));
+ "data", data));
return TALER_MHD_reply_json_steal (connection,
body,
MHD_HTTP_OK);
@@ -210,7 +229,7 @@ handler_cb (void *cls,
}
if (0 != *upload_data_size)
{
- enum MHD_Result ret;
+ MHD_RESULT ret;
ret = MHD_post_process (rc->pp,
upload_data,
@@ -304,6 +323,7 @@ cleanup (void *cls,
(void) toe;
if (NULL == rc)
return;
+ MHD_destroy_post_processor (rc->pp);
GNUNET_free (rc->code);
GNUNET_free (rc->client_id);
GNUNET_free (rc->redirect_uri);
@@ -327,12 +347,18 @@ oauth_run (void *cls,
struct OAuthState *oas = cls;
(void) cmd;
- oas->mhd = MHD_start_daemon (MHD_USE_AUTO_INTERNAL_THREAD,
+ oas->mhd = MHD_start_daemon (MHD_USE_AUTO_INTERNAL_THREAD | MHD_USE_DEBUG,
oas->port,
NULL, NULL,
&handler_cb, oas,
MHD_OPTION_NOTIFY_COMPLETED, &cleanup, NULL,
NULL);
+ if (NULL == oas->mhd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
TALER_TESTING_interpreter_next (is);
}
@@ -361,13 +387,15 @@ oauth_cleanup (void *cls,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_oauth (const char *label,
- uint16_t port)
+TALER_TESTING_cmd_oauth_with_birthdate (const char *label,
+ const char *birthdate,
+ uint16_t port)
{
struct OAuthState *oas;
oas = GNUNET_new (struct OAuthState);
oas->port = port;
+ oas->birthdate = birthdate;
{
struct TALER_TESTING_Command cmd = {
.cls = oas,