[testing] start an oauth2 server which returns static birthdates

This commit is contained in:
Özgür Kesim 2023-06-27 12:41:22 +02:00
parent 1be14a3416
commit d3d744a444
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
2 changed files with 38 additions and 15 deletions

View File

@ -2243,14 +2243,25 @@ TALER_TESTING_cmd_proof_kyc_oauth2 (
/** /**
* Starts a fake OAuth 2.0 service on @a port for testing * Starts a fake OAuth 2.0 service on @a port for testing
* KYC processes. * KYC processes which also provides a @a birthdate in a response
* *
* @param label command label * @param label command label
* @param port the TCP port to listen on * @param port the TCP port to listen on
*/ */
struct TALER_TESTING_Command struct TALER_TESTING_Command
TALER_TESTING_cmd_oauth (const char *label, TALER_TESTING_cmd_oauth_with_birthdate (const char *label,
uint16_t port); const char *birthdate,
uint16_t port);
/**
* Starts a fake OAuth 2.0 service on @a port for testing
* KYC processes.
*
* @param label command label
* @param port the TCP port to listen on
*/
#define TALER_TESTING_cmd_oauth(label, port) \
TALER_TESTING_cmd_oauth_with_birthdate ((label), NULL, (port))
/* ****************** P2P payment commands ****************** */ /* ****************** P2P payment commands ****************** */

View File

@ -39,6 +39,11 @@ struct OAuthState
*/ */
struct MHD_Daemon *mhd; struct MHD_Daemon *mhd;
/**
* Birthdate that the oauth server should return in a response, may be NULL
*/
const char *birthdate;
/** /**
* Port to listen on. * Port to listen on.
*/ */
@ -172,28 +177,33 @@ handler_cb (void *cls,
void **con_cls) void **con_cls)
{ {
struct RequestCtx *rc = *con_cls; struct RequestCtx *rc = *con_cls;
struct OAuthState *oas = cls;
unsigned int hc; unsigned int hc;
json_t *body; json_t *body;
(void) cls;
(void) version; (void) version;
if (0 == strcasecmp (method, if (0 == strcasecmp (method,
MHD_HTTP_METHOD_GET)) 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)
json_object_set_new (data,
"birthdate",
json_string_nocheck (oas->birthdate));
body = GNUNET_JSON_PACK ( body = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ( GNUNET_JSON_pack_string (
"status", "status",
"success"), "success"),
GNUNET_JSON_pack_object_steal ( GNUNET_JSON_pack_object_steal (
"data", "data", data));
GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("id",
"XXXID12345678"),
GNUNET_JSON_pack_string ("first_name",
"Bob"),
GNUNET_JSON_pack_string ("last_name",
"Builder")
)));
return TALER_MHD_reply_json_steal (connection, return TALER_MHD_reply_json_steal (connection,
body, body,
MHD_HTTP_OK); MHD_HTTP_OK);
@ -368,13 +378,15 @@ oauth_cleanup (void *cls,
struct TALER_TESTING_Command struct TALER_TESTING_Command
TALER_TESTING_cmd_oauth (const char *label, TALER_TESTING_cmd_oauth_with_birthdate (const char *label,
uint16_t port) const char *birthdate,
uint16_t port)
{ {
struct OAuthState *oas; struct OAuthState *oas;
oas = GNUNET_new (struct OAuthState); oas = GNUNET_new (struct OAuthState);
oas->port = port; oas->port = port;
oas->birthdate = birthdate;
{ {
struct TALER_TESTING_Command cmd = { struct TALER_TESTING_Command cmd = {
.cls = oas, .cls = oas,