From 380046d2c839b074a239cc4c8b866e647ec82eea Mon Sep 17 00:00:00 2001 From: David Levine Date: Thu, 15 Sep 2016 20:00:02 -0400 Subject: [PATCH] Added 2 second timeout to curl command in post() in oauth.c, for localhost requests only, because the default timeout on Cygwin is 5 minutes. --- sbr/oauth.c | 8 ++++++++ test/oauth/test-mhlogin | 16 +++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) mode change 100644 => 100755 sbr/oauth.c diff --git a/sbr/oauth.c b/sbr/oauth.c old mode 100644 new mode 100755 index ae745fcf..3433fba0 --- a/sbr/oauth.c +++ b/sbr/oauth.c @@ -961,6 +961,14 @@ post(struct curl_ctx *ctx, const char *url, const char *req_body) curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, ctx); + if (strncmp(url, "http://127.0.0.1:", 17) == 0) { + /* Hack: on Cygwin, curl doesn't fail to connect with ECONNREFUSED. + Instead, it waits to timeout. So set a really short timeout, but + just on localhost (for convenience of the user, and the test + suite). */ + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2L); + } + status = curl_easy_perform(curl); /* first check for error from callback */ if (ctx->too_big) { diff --git a/test/oauth/test-mhlogin b/test/oauth/test-mhlogin index 7454576b..682fbc86 100755 --- a/test/oauth/test-mhlogin +++ b/test/oauth/test-mhlogin @@ -303,11 +303,17 @@ mhlogin: bad OAuth request; re-run with -snoop and send REDACTED output to nmh-w # TEST start_test 'mhlogin -browser' -run_test "eval echo code | mhlogin -saslmech xoauth2 -authservice test\ - -user nobody@example.com -browser 'echo \$@ > ${MHTMPDIR}/$$.browser'" \ -"Follow the prompts in your browser to authorize nmh to access test. -Enter the authorization code: mhlogin: error exchanging code for OAuth2 token -mhlogin: error making HTTP request to OAuth2 authorization endpoint: Failed to connect to 127.0.0.1 port ${http_port}: Connection refused" +#### Strip off the error string because it can vary, e.g., +#### "Failed to connect to 127.0.0.1 port 64546: Connection refused", or +#### "Connection timed out after 1004 milliseconds" +echo code | mhlogin -saslmech xoauth2 -authservice test -user nobody@example.com \ + -browser "echo \$@ > ${MHTMPDIR}/$$.browser" 2>&1 1>/dev/null | \ + sed 's/\( endpoint:\) .*/\1/' > "${MHTMPDIR}/$$.mhlogin.err" +cat > "${MHTMPDIR}/$$.mhlogin.err.expected" < "${MHTMPDIR}/$$.browser.expected" <