Skip to content

Commit

Permalink
Test: adapt test_pam_srv to JSON message
Browse files Browse the repository at this point in the history
Include JSON message where applies.

Signed-off-by: Iker Pedrosa <[email protected]>
  • Loading branch information
ikerexxe committed May 13, 2024
1 parent 21dcf9e commit 30da196
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/responder/pam/pamsrv_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ json_format_mechanisms(bool password_auth, const char *password_prompt,
}

if (password_auth) {
json_pass = json_pack("{s:s,s:s,s:s}",
json_pass = json_pack("{s:s,s:s,s:b,s:s}",
"name", "Password",
"role", "password",
"selectable", true,
"prompt", password_prompt);
if (json_pass == NULL) {
DEBUG(SSSDBG_OP_FAILURE, "json_pack failed.\n");
Expand All @@ -238,9 +239,10 @@ json_format_mechanisms(bool password_auth, const char *password_prompt,
}

if (oauth2_auth) {
json_oauth2 = json_pack("{s:s,s:s,s:s,s:s,s:s,s:s,s:i}",
json_oauth2 = json_pack("{s:s,s:s,s:b,s:s,s:s,s:s,s:s,s:i}",
"name", "Web Login",
"role", "eidp",
"selectable", true,
"init_prompt", oauth2_init_prompt,
"link_prompt", oauth2_link_prompt,
"uri", uri,
Expand Down
6 changes: 6 additions & 0 deletions src/tests/cmocka/test_pam_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ static void mock_input_pam_passkey(TALLOC_CTX *mem_ctx,
pi.pam_rhost_size = strlen(pi.pam_rhost) + 1;
pi.requested_domains = "";
pi.cli_pid = 12345;
pi.json_auth_msg = discard_const("");
pi.json_auth_selected = "";

ret = pack_message_v3(&pi, &buf_size, &m_buf);
assert_int_equal(ret, 0);
Expand Down Expand Up @@ -707,6 +709,8 @@ static void mock_input_pam_ex(TALLOC_CTX *mem_ctx,
pi.pam_rhost_size = strlen(pi.pam_rhost) + 1;
pi.requested_domains = "";
pi.cli_pid = 12345;
pi.json_auth_msg = discard_const("");
pi.json_auth_selected = "";

ret = pack_message_v3(&pi, &buf_size, &m_buf);
assert_int_equal(ret, 0);
Expand Down Expand Up @@ -788,6 +792,8 @@ static void mock_input_pam_cert(TALLOC_CTX *mem_ctx, const char *name,
pi.pam_rhost_size = strlen(pi.pam_rhost) + 1;
pi.requested_domains = "";
pi.cli_pid = 12345;
pi.json_auth_msg = discard_const("");
pi.json_auth_selected = "";

ret = pack_message_v3(&pi, &buf_size, &m_buf);
free(pi.pam_authtok);
Expand Down
3 changes: 2 additions & 1 deletion src/tests/cmocka/test_pamsrv_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@

#define BASIC_PASSWORD "\"password\": {" \
"\"name\": \"Password\", \"role\": \"password\", " \
"\"prompt\": \"Password\"}"
"\"selectable\": true, \"prompt\": \"Password\"}"
#define BASIC_OAUTH2 "\"eidp\": {" \
"\"name\": \"Web Login\", \"role\": \"eidp\", " \
"\"selectable\": true, " \
"\"init_prompt\": \"" OAUTH2_INIT_PROMPT "\", " \
"\"link_prompt\": \"" OAUTH2_LINK_PROMPT "\", " \
"\"uri\": \"short.url.com/tmp\", \"code\": \"1234-5678\", " \
Expand Down

0 comments on commit 30da196

Please sign in to comment.