Skip to content

Commit

Permalink
loop: add support for FLUX_OPT_TESTING cred access
Browse files Browse the repository at this point in the history
Problem: rpc unit tests test relies on connector level accessors for
credentials but loop:// doesn't implement them.

Add support for FLUX_OPT_TESTING_USERID and FLUX_OPT_TESTING_ROLEMASK
options, as implemented in loopback_create().
  • Loading branch information
garlick committed Oct 5, 2023
1 parent 750e558 commit 9eea0bf
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/common/libflux/connector_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <flux/core.h>

#include "ccan/str/str.h"

typedef struct {
flux_t *h;

Expand Down Expand Up @@ -87,6 +89,56 @@ static flux_msg_t *op_recv (void *impl, int flags)
return msg;
}

static int op_getopt (void *impl, const char *option, void *val, size_t size)
{
loop_ctx_t *c = impl;

if (option && streq (option, FLUX_OPT_TESTING_USERID)) {
if (size != sizeof (c->cred.userid))
goto error;
memcpy (val, &c->cred.userid, size);
}
else if (option && streq (option, FLUX_OPT_TESTING_ROLEMASK)) {
if (size != sizeof (c->cred.rolemask))
goto error;
memcpy (val, &c->cred.rolemask, size);
}
else
goto error;
return 0;
error:
errno = EINVAL;
return -1;
}

static int op_setopt (void *impl,
const char *option,
const void *val,
size_t size)
{
loop_ctx_t *c = impl;
size_t val_size;

if (option && streq (option, FLUX_OPT_TESTING_USERID)) {
val_size = sizeof (c->cred.userid);
if (size != val_size)
goto error;
memcpy (&c->cred.userid, val, val_size);
}
else if (option && streq (option, FLUX_OPT_TESTING_ROLEMASK)) {
val_size = sizeof (c->cred.rolemask);
if (size != val_size)
goto error;
memcpy (&c->cred.rolemask, val, val_size);
}
else
goto error;
return 0;
error:
errno = EINVAL;
return -1;
}

static void op_fini (void *impl)
{
loop_ctx_t *c = impl;
Expand Down Expand Up @@ -129,8 +181,8 @@ static const struct flux_handle_ops handle_ops = {
.pollevents = op_pollevents,
.send = op_send,
.recv = op_recv,
.getopt = NULL,
.setopt = NULL,
.getopt = op_getopt,
.setopt = op_setopt,
.impl_destroy = op_fini,
};

Expand Down

0 comments on commit 9eea0bf

Please sign in to comment.