Skip to content

Commit 33be128

Browse files
authored
Fix enrollment URL display in interactive mode (#338)
1 parent 45908f9 commit 33be128

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

lib/duo.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,18 @@ _duo_preauth(struct duo_ctx *ctx, const char *username,
491491
}
492492
ret = DUO_ABORT;
493493
} else if (strcasecmp(result, "enroll") == 0) {
494+
/* For enrollment, check if prompt.text exists and use it instead of status_msg */
495+
const char *enrollment_msg = output; // default to status_msg
496+
JSON_Object *prompt_obj = json_object_get_object(response, "prompt");
497+
if (prompt_obj != NULL) {
498+
const char *prompt_text = json_object_get_string(prompt_obj, "text");
499+
if (prompt_text != NULL) {
500+
enrollment_msg = prompt_text;
501+
}
502+
}
503+
494504
if (ctx->conv_status != NULL) {
495-
ctx->conv_status(ctx->conv_arg, output);
505+
ctx->conv_status(ctx->conv_arg, enrollment_msg);
496506
}
497507
_duo_seterr(ctx, "User enrollment required");
498508
ret = DUO_ABORT;

tests/common_suites.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,19 @@ def test_autopush_nomenu(self):
781781
0,
782782
)
783783

784+
def test_enrollment_shows_url(self):
785+
"""Test that enrollment URL is displayed in interactive mode - reproduces issue #336"""
786+
with TempConfig(MOCKDUO_CONF) as temp:
787+
process = self.call_binary(
788+
["-d", "-c", temp.name, "-f", "enroll", "true"],
789+
)
790+
self.assertEqual(
791+
process.expect(r"https://.*?/portal", timeout=5),
792+
0,
793+
)
794+
# The process should terminate
795+
self.assertEqual(process.expect(EOF), 0)
796+
784797
class InvalidBSON(CommonTestCase):
785798
def run(self, result=None):
786799
with MockDuo(NORMAL_CERT):

tests/mockduo.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,15 @@ def do_POST(self):
305305
elif self.args["username"] == "gecos/6":
306306
ret["response"] = {"result": "allow", "status_msg": "gecos/6"}
307307
elif self.args["username"] == "enroll":
308-
ret["response"] = {"result": "enroll", "status_msg": "please enroll"}
308+
ret["response"] = {
309+
"enroll_portal_url": "https://api-abcd1234.duosecurity.com/portal?code=48bac5d9393fb2c2&akey=DIXXXXXXXXXXXXXXXXXX",
310+
"result": "enroll",
311+
"status_msg": "Enroll an authentication device to proceed"
312+
}
313+
if self.args["text_prompt"]:
314+
ret["response"]["prompt"] = {
315+
"text": "Please enroll at https://api-abcd1234.duosecurity.com/portal?code=48bac5d9393fb2c2&akey=DIXXXXXXXXXXXXXXXXXX"
316+
}
309317
elif self.args["username"] == "bad-json":
310318
buf = b""
311319
elif self.args["username"] == "retry-after-3-preauth-allow":

0 commit comments

Comments
 (0)