# TEST
start_test 'no service definition'
-run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice bogus -user nobody@example.com" 'send: incomplete OAuth2 service definition: scope is missing'
+run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice bogus -user nobody@example.com" 'send: Unable to retrieve oauth profile entries: scope is missing'
# TEST
start_test 'no creds file -- should tell user to mhlogin'
rm -f "${MHTMPDIR}/oauth-test"
-test_send_no_servers 'send: no credentials -- run mhlogin -saslmech xoauth2 -authservice test'
+test_send_only_fakesmtp 'post: no credentials -- run mhlogin -saslmech xoauth2 -authservice test
+send: message not delivered to anyone'
# TEST
start_test 'empty creds file -- should tell user to mhlogin'
fake_creds < /dev/null
-test_send_no_servers 'send: user not found in cred file: nobody@example.com'
+test_send_only_fakesmtp 'post: user not found in cred file: nobody@example.com
+send: message not delivered to anyone'
# TEST
start_test 'garbage creds file'
echo bork | fake_creds
-test_send_no_servers 'send: eof encountered in field "bork"
-send: error loading cred file'
+test_send_only_fakesmtp 'post: eof encountered in field "bork"
+post: error loading cred file
+send: message not delivered to anyone'
# TEST
start_test 'unexpected field in creds file'
access-nobody@example.com: test-access
EOF
-test_send_no_servers 'send: error loading cred file: unexpected field'
+test_send_only_fakesmtp 'post: error loading cred file: unexpected field
+send: message not delivered to anyone'
# TEST
start_test 'garbage expiration time'
expire-nobody@example.com: 99999999999999999999999999999999
EOF
-test_send_no_servers 'send: error loading cred file: invalid expiration time'
+test_send_only_fakesmtp 'post: error loading cred file: invalid expiration time
+send: message not delivered to anyone'
# TEST
start_test 'refresh response has no access token'
}
EOF
-test_send_only_fakehttp 'send: error refreshing OAuth2 token
-send: invalid response: no access token'
+test_send 'post: error refreshing OAuth2 token
+post: invalid response: no access token
+send: message not delivered to anyone'
# TEST
start_test 'expired access token, no refresh token -- tell user to mhlogin'
expire-nobody@example.com: 1414303986
EOF
-test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
+test_send_only_fakesmtp 'post: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test
+send: message not delivered to anyone'
# TEST
start_test 'access token has no expiration, no refresh token -- tell user to mhlogin'
access-nobody@example.com: test-access
EOF
-test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
+test_send_only_fakesmtp 'post: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test
+send: message not delivered to anyone'
# TEST
start_test 'refresh finds no http server'
EOF
cat > "${testname}.expected-send-output" <<EOF
-send: error refreshing OAuth2 token
-send: error making HTTP request to OAuth2 authorization endpoint: [details]
+post: error refreshing OAuth2 token
+post: error making HTTP request to OAuth2 authorization endpoint: [details]
+send: message not delivered to anyone
EOF
+start_fakesmtp
run_prog send -draft -server 127.0.0.1 -port ${smtp_port} \
-saslmech xoauth2 -authservice test -user nobody@example.com > "${testname}.send-output" 2>&1 || true
# Clear out an error message we get from libcurl on some systems (seen at least
# 3 different versions of this error message, on FreeBSD 10.1, Ubuntu 12.04, and
# Ubuntu 14.04).
f="${testname}.send-output"
-sed 's/\(send: error making HTTP request to OAuth2 authorization endpoint:\).*/\1 [details]/' "$f" > "$f".clean
+sed 's/\(post: error making HTTP request to OAuth2 authorization endpoint:\).*/\1 [details]/' "$f" > "$f".clean
check "$f".clean "${testname}.expected-send-output"
rm "$f"
<html>doh!</htmxl>
EOF
-test_send_only_fakehttp 'send: error refreshing OAuth2 token
-send: invalid response'
+test_send 'post: error refreshing OAuth2 token
+post: invalid response
+send: message not delivered to anyone'
# TEST
start_test 'refresh gets 500 response from http server'
<html>doh!</html>
EOF
-test_send_only_fakehttp 'send: error refreshing OAuth2 token
-send: invalid response'
+test_send 'post: error refreshing OAuth2 token
+post: invalid response
+send: message not delivered to anyone'
# TEST
start_test 'refresh gets proper error from http'
}
EOF
-test_send_only_fakehttp 'send: credentials rejected -- run mhlogin -saslmech xoauth2 -authservice test'
+test_send 'post: credentials rejected -- run mhlogin -saslmech xoauth2 -authservice test
+send: message not delivered to anyone'
# TEST
start_test 'refresh gets response too big'
awk 'BEGIN { for (i = 0; i < 8192; i++) { print "." } }' \
>> "${testname}.http-res"
-test_send_only_fakehttp 'send: error refreshing OAuth2 token
-send: refusing to process response body larger than 8192 bytes'
+test_send 'post: error refreshing OAuth2 token
+post: refusing to process response body larger than 8192 bytes
+send: message not delivered to anyone'
# TEST
start_test 'smtp server rejects token'
test_send_only_fakesmtp 'post: problem initializing server; [BHST] Not no way, not no how!
send: message not delivered to anyone'
-# TEST
-start_test "smtp server doesn't support oauth"
-
-unset XOAUTH
-
-test_send_only_fakesmtp 'post: problem initializing server; [BHST] SMTP server does not support SASL XOAUTH2
-send: message not delivered to anyone'
-
# TEST
start_test 'botched json response'
}
EOF
-test_send_only_fakehttp 'send: error refreshing OAuth2 token
-send: invalid response'
+test_send 'post: error refreshing OAuth2 token
+post: invalid response
+send: message not delivered to anyone'
+
+# TEST
+start_test "smtp server doesn't support oauth"
+
+unset XOAUTH
+
+test_send_only_fakesmtp 'post: problem initializing server; [BHST] SMTP server does not support SASL XOAUTH2
+send: message not delivered to anyone'
clean_fakesmtp
clean_fakehttp
X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
X("messageid localname|random", 2, MESSAGEIDSW) \
- X("oauthcredfile", OAUTHminc(-7), OAUTHCREDFILESW) \
- X("oauthclientid", OAUTHminc(-12), OAUTHCLIDSW) \
- X("oauthclientsecret", OAUTHminc(-12), OAUTHCLSECSW) \
- X("oauthauthendpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
- X("oauthredirect", OAUTHminc(-6), OAUTHREDIRSW) \
- X("oauthtokenendpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
- X("oauthscope", OAUTHminc(-6), OAUTHSCOPESW) \
+ X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
+ X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
+ X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
+ X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
+ X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
+ X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
+ X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
+ X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
#define X(sw, minchars, id) id,
DEFINE_SWITCH_ENUM(POST);
const char *profname;
int switchnum;
} oauthswitches[] = {
- { "oauth-post-credential-file", OAUTHCREDFILESW },
- { "oauth-post-client_id", OAUTHCLIDSW },
- { "oauth-post-client_secret", OAUTHCLSECSW },
- { "oauth-post-auth_endpoint", OAUTHAUTHENDSW },
- { "oauth-post-redirect_url", OAUTHREDIRSW },
- { "oauth-post-token_endpoint", OAUTHTOKENDSW },
- { "oauth-post-scope", OAUTHSCOPESW },
+ { "oauth-%s-credential-file", OAUTHCREDFILESW },
+ { "oauth-%s-client_id", OAUTHCLIDSW },
+ { "oauth-%s-client_secret", OAUTHCLSECSW },
+ { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW },
+ { "oauth-%s-redirect_uri", OAUTHREDIRSW },
+ { "oauth-%s-token_endpoint", OAUTHTOKENDSW },
+ { "oauth-%s-scope", OAUTHSCOPESW },
{ NULL, 0 }
};
static void p_refile (char *);
static void fcc (char *, char *);
static void die (char *, char *, ...);
-static void post (char *, int, int, char *, int);
+static void post (char *, int, int, char *, int, char *);
static void do_text (char *file, int fd);
static void do_an_address (struct mailname *, int);
static void do_addresses (int, int);
{
int state, compnum, dashstuff = 0, swnum, oauth_flag = 0;
char *cp, *msg = NULL, **argp, **arguments, *envelope;
- char buf[BUFSIZ], name[NAMESZ];
+ char buf[BUFSIZ], name[NAMESZ], *auth_svc = "post";
FILE *in, *out;
m_getfld_state_t gstate = 0;
adios (NULL, "missing argument to %s", argp[-2]);
continue;
+ case AUTHSERVICESW:
+ if (!(auth_svc = *argp++) || *auth_svc == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ continue;
+
case OAUTHCREDFILESW:
case OAUTHCLIDSW:
case OAUTHCLSECSW:
case OAUTHSCOPESW:
{
int i;
+ char sbuf[128];
if (!(cp = *argp++) || *cp == '-')
adios (NULL, "missing argument to %s", argp[-2]);
for (i = 0; oauthswitches[i].profname != NULL; i++) {
if (oauthswitches[i].switchnum == swnum) {
- add_profile_entry(oauthswitches[i].profname, cp);
+ snprintf(sbuf, sizeof(sbuf),
+ oauthswitches[i].profname, auth_svc);
+ sbuf[sizeof(sbuf) - 1] = '\0';
+ add_profile_entry(sbuf, cp);
break;
}
}
that spost didn't verify addresses. */
verify_all_addresses (verbose, envelope, oauth_flag);
}
- post (tmpfil, 0, verbose, envelope, oauth_flag);
+ post (tmpfil, 0, verbose, envelope, oauth_flag, auth_svc);
}
- post (bccfil, 1, verbose, envelope, oauth_flag);
+ post (bccfil, 1, verbose, envelope, oauth_flag, auth_svc);
(void) m_unlink (bccfil);
} else {
- post (tmpfil, 0, isatty (1), envelope, oauth_flag);
+ post (tmpfil, 0, isatty (1), envelope, oauth_flag, auth_svc);
}
p_refile (tmpfil);
*/
static void
-post (char *file, int bccque, int talk, char *envelope, int oauth_flag)
+post (char *file, int bccque, int talk, char *envelope, int oauth_flag,
+ char *auth_svc)
{
int fd;
int retval, i;
if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch,
verbose, snoop, sasl, saslssf,
saslmech, user,
- oauth_flag ? "post" : NULL, tls))
+ oauth_flag ? auth_svc : NULL, tls))
|| rp_isbad (retval = sm_winit (envelope)))
die (NULL, "problem initializing server; %s", rp_string (retval));