# HG changeset patch # User Ben Bucksch # Date 1546581480 -3600 # Node ID 2e41ec4a6a37e96dd741245cb51c2a75d58f4217 # Parent 6a01ea0a8850e01fd0a1789f5027b3e5f3662fee Bug 1516229 - [autoconfig] Beautify the account config debug output and avoid logging the password. r=Neil a=jorgk * * * Bug 1516229 - Follow-up: Fix linting errors. r=me DONTBUILD * * * Bug 1516229 - Follow-up: Remove fetchhttp debug output. r+a=jorgk diff --git a/mail/components/accountcreation/content/accountConfig.js b/mail/components/accountcreation/content/accountConfig.js --- a/mail/components/accountcreation/content/accountConfig.js +++ b/mail/components/accountcreation/content/accountConfig.js @@ -144,32 +144,111 @@ AccountConfig.prototype = /** * Returns a deep copy of this object, * i.e. modifying the copy will not affect the original object. */ copy : function() { // Workaround: deepCopy() fails to preserve base obj (instanceof) - var result = new AccountConfig(); - for (var prop in this) + let result = new AccountConfig(); + for (let prop in this) result[prop] = deepCopy(this[prop]); return result; }, isComplete : function() { return (!!this.incoming.hostname && !!this.incoming.port && !!this.incoming.socketType && !!this.incoming.auth && !!this.incoming.username && (!!this.outgoing.existingServerKey || (!!this.outgoing.hostname && !!this.outgoing.port && !!this.outgoing.socketType && !!this.outgoing.auth && !!this.outgoing.username))); }, + + toString() { + function sslToString(socketType) { + switch (socketType) { + case 0: + return "undefined"; + case 1: + return "no SSL"; + case 2: + return "SSL"; + case 3: + return "STARTTLS"; + default: + return "invalid"; + } + } + function authToString(authMethod) { + switch (authMethod) { + case 0: + return "undefined"; + case 1: + return "none"; + case 2: + return "old plain"; + case 3: + return "plain"; + case 4: + return "encrypted"; + case 5: + return "Kerberos"; + case 6: + return "NTLM"; + case 7: + return "external/SSL"; + case 8: + return "any secure"; + case 10: + return "OAuth2"; + default: + return "invalid"; + } + } + function usernameToString(username) { + if (!username) { + return "undefined"; + } + let domain = username.split("@")[1]; + return domain ? "(redacted)@" + domain : "(redacted)"; + } + function passwordToString(password) { + return password ? "set" : "not set"; + } + function configToString(config) { + return config.type + + ", " + config.hostname + ":" + config.port + + ", " + sslToString(config.socketType) + + ", auth: " + authToString(config.auth) + + ", username: " + usernameToString(config.username) + + ", password: " + passwordToString(config.password); + } + + let result = + "Incoming: " + configToString(this.incoming) + + "\nOutgoing: "; + if (this.outgoing.useGlobalPreferredServer) { + result += "Use global server"; + } else if (this.outgoing.existingServerKey) { + result += "Use existing server " + this.outgoing.existingServerKey; + } else { + result += configToString(this.outgoing); + } + for (let config of this.incomingAlternatives) { + result += "\nIncoming alt: " + configToString(config); + } + for (let config of this.outgoingAlternatives) { + result += "\nOutgoing alt: " + configToString(config); + } + return result; + }, }; // enum consts // .source AccountConfig.kSourceUser = 1; // user manually entered the config AccountConfig.kSourceXML = 2; // config from XML from ISP or Mozilla DB diff --git a/mail/components/accountcreation/content/emailWizard.js b/mail/components/accountcreation/content/emailWizard.js --- a/mail/components/accountcreation/content/emailWizard.js +++ b/mail/components/accountcreation/content/emailWizard.js @@ -33,16 +33,18 @@ ChromeUtils.import("resource:///modules/ // from http://xyfer.blogspot.com/2005/01/javascript-regexp-email-validator.html var emailRE = /^[-_a-z0-9\'+*$^&%=~!?{}]+(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*@(?:[-a-z0-9.]+\.[a-z]{2,20}|\d{1,3}(?:\.\d{1,3}){3})(?::\d+)?$/i; if (typeof gEmailWizardLogger == "undefined") { ChromeUtils.import("resource:///modules/gloda/log4moz.js"); var gEmailWizardLogger = Log4Moz.getConfiguredLogger("mail.wizard"); + // Bug 1516229 + // - gEmailWizardLogger.addAppender(new Log4Moz.DumpAppender(new Log4Moz.BasicFormatter())); // stdout } var gStringsBundle; var gMessengerBundle; var gBrandShortName; /********************* TODO for bug 549045 @@ -661,17 +663,19 @@ EmailConfigWizard.prototype = }, /** * When findConfig() was successful, it calls this. * This displays the config to the user. */ foundConfig : function(config) { - gEmailWizardLogger.info("foundConfig()"); + // Bug 1516229 + // - gEmailWizardLogger.info(debugObject(config, "foundConfig")); + gEmailWizardLogger.info("found config:\n" + config); assert(config instanceof AccountConfig, "BUG: Arg 'config' needs to be an AccountConfig object"); this._haveValidConfigForDomain = this._email.split("@")[1]; if (!this._realname || !this._email) { return; } @@ -1020,18 +1024,20 @@ EmailConfigWizard.prototype = e("incoming_port").value = config.incoming.port; } else { this.adjustIncomingPortToSSLAndProtocol(config); } this.fillPortDropdown(config.incoming.type); // If the hostname supports OAuth2 and imap is enabled, enable OAuth2. let iDetails = OAuth2Providers.getHostnameDetails(config.incoming.hostname); - gEmailWizardLogger.info("OAuth2 details for incoming hostname " + - config.incoming.hostname + " is " + iDetails); + if (iDetails) { + gEmailWizardLogger.info("OAuth2 details for incoming server " + + config.incoming.hostname + " is " + iDetails); + } e("in-authMethod-oauth2").hidden = !(iDetails && e("incoming_protocol").value == 1); if (!e("in-authMethod-oauth2").hidden) { config.oauthSettings = {}; [config.oauthSettings.issuer, config.oauthSettings.scope] = iDetails; // oauthsettings are not stored nor changeable in the user interface, so just // store them in the base configuration. this._currentConfig.oauthSettings = config.oauthSettings; } @@ -1049,18 +1055,20 @@ EmailConfigWizard.prototype = if (config.outgoing.port) { e("outgoing_port").value = config.outgoing.port; } else { this.adjustOutgoingPortToSSLAndProtocol(config); } // If the hostname supports OAuth2 and imap is enabled, enable OAuth2. let oDetails = OAuth2Providers.getHostnameDetails(config.outgoing.hostname); - gEmailWizardLogger.info("OAuth2 details for outgoing hostname " + - config.outgoing.hostname + " is " + oDetails); + if (oDetails) { + gEmailWizardLogger.info("OAuth2 details for outgoing server " + + config.outgoing.hostname + " is " + oDetails); + } e("out-authMethod-oauth2").hidden = !oDetails; if (!e("out-authMethod-oauth2").hidden) { config.oauthSettings = {}; [config.oauthSettings.issuer, config.oauthSettings.scope] = oDetails; // oauthsettings are not stored nor changeable in the user interface, so just // store them in the base configuration. this._currentConfig.oauthSettings = config.oauthSettings; } @@ -1424,17 +1432,17 @@ EmailConfigWizard.prototype = * as given and will not second-guess them, to respect the user wishes. * (Yes, Sir! Will do as told!) * The values that the user left empty or on "Auto" will be guessed/probed * here. We will also check that the user-provided values work. */ onHalfManualTest : function() { var newConfig = this.getUserConfig(); - gEmailWizardLogger.info(debugObject(newConfig, "manualConfigToTest")); + gEmailWizardLogger.info("manual config to test:\n" + newConfig); this.startSpinner("looking_up_settings_halfmanual"); this.switchToMode("manual-edit-testing"); // if (this._userPickedOutgoingServer) TODO var self = this; this._abortable = guessConfig(this._domain, function(type, hostname, port, ssl, done, config) // progress { gEmailWizardLogger.info("progress callback host " + hostname + diff --git a/mail/components/accountcreation/content/fetchhttp.js.1516229.later b/mail/components/accountcreation/content/fetchhttp.js.1516229.later new file mode 100644 --- /dev/null +++ b/mail/components/accountcreation/content/fetchhttp.js.1516229.later @@ -0,0 +1,40 @@ +--- fetchhttp.js ++++ fetchhttp.js +@@ -163,19 +163,16 @@ FetchHTTP.prototype = + } else if (this._args.bodyFormArgs) { + mimetype = "application/x-www-form-urlencoded; charset=UTF-8"; + body = ""; + for (let name in this._args.bodyFormArgs) { + body += (body ? "&" : "") + name + "=" + + encodeURIComponent(this._args.bodyFormArgs[name]); + } + } +- if (body) { +- this._logger.info("with body:\n" + body); +- } + + // Headers + if (mimetype && !("Content-Type" in this._args.headers)) { + request.setRequestHeader("Content-Type", mimetype); + } + if (username && password) { + // workaround, because open(..., username, password) does not work. + request.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password)); +@@ -185,17 +182,16 @@ FetchHTTP.prototype = + if (name == "Cookie") { + // Websites are not allowed to set this, but chrome is. + // Nevertheless, the cookie lib later overwrites our header. + // request.channel.setCookie(this._args.headers[name]); -- crashes + // So, deactivate that Firefox cookie lib. + request.channel.loadFlags |= Ci.nsIRequest.LOAD_ANONYMOUS; + } + } +- this._logger.info(debugObject(this._args, "args")); + + var me = this; + request.onload = function() { me._response(true); }; + request.onerror = function() { me._response(false); }; + request.ontimeout = function() { me._response(false); }; + request.send(body); + // Store the original stack so we can use it if there is an exception + this._callStack = Error().stack; diff --git a/mail/components/accountcreation/content/guessConfig.js b/mail/components/accountcreation/content/guessConfig.js --- a/mail/components/accountcreation/content/guessConfig.js +++ b/mail/components/accountcreation/content/guessConfig.js @@ -167,18 +167,19 @@ function guessConfig(domain, progressCal server.auth = chooseBestAuthMethod(thisTry.authMethods); server.authAlternatives = thisTry.authMethods; // TODO // cert is also bad when targetSite is set. (Same below for incoming.) // Fix SSLErrorHandler and security warning dialog in emailWizard.js. server.badCert = thisTry.selfSignedCert; server.targetSite = thisTry.targetSite; logger.info("CHOOSING " + server.type + " "+ server.hostname + ":" + - server.port + ", auth method " + server.auth + " " + - server.authAlternatives.join(",") + ", SSL " + server.socketType + + server.port + ", auth method " + server.auth + + (server.authAlternatives.length ? " " + server.authAlternatives.join(",") : "") + + ", SSL " + server.socketType + (server.badCert ? " (bad cert!)" : "")); }; var outgoingSuccess = function(thisTry, alternativeTries) { assert(thisTry.protocol == SMTP, "I only know SMTP for outgoing"); // Ensure there are no previously saved outgoing errors, if we've got // success here. diff --git a/mail/components/accountcreation/content/util.js b/mail/components/accountcreation/content/util.js --- a/mail/components/accountcreation/content/util.js +++ b/mail/components/accountcreation/content/util.js @@ -243,16 +243,20 @@ function deepCopy(org) for (var prop in org) result[prop] = deepCopy(org[prop]); return result; } if (typeof gEmailWizardLogger == "undefined") { ChromeUtils.import("resource:///modules/gloda/log4moz.js"); var gEmailWizardLogger = Log4Moz.getConfiguredLogger("mail.wizard"); + // Bug 1516229 + // - gEmailWizardLogger.addAppender(new Log4Moz.DumpAppender(new Log4Moz.BasicFormatter())); // stdout + // + //gEmailWizardLogger.addAppender(new Log4Moz.DumpAppender(new Log4Moz.BasicFormatter())); // stdout + } function ddump(text) { gEmailWizardLogger.info(text); } function debugObject(obj, name, maxDepth, curDepth) { diff --git a/mail/components/accountcreation/content/verifyConfig.js b/mail/components/accountcreation/content/verifyConfig.js --- a/mail/components/accountcreation/content/verifyConfig.js +++ b/mail/components/accountcreation/content/verifyConfig.js @@ -34,17 +34,17 @@ ChromeUtils.import("resource:///modules/ if (typeof gEmailWizardLogger == "undefined") { ChromeUtils.import("resource:///modules/gloda/log4moz.js"); var gEmailWizardLogger = Log4Moz.getConfiguredLogger("mail.wizard"); } function verifyConfig(config, alter, msgWindow, successCallback, errorCallback) { - ddump(debugObject(config, "config", 3)); + ddump("verify config:\n" + config); assert(config instanceof AccountConfig, "BUG: Arg 'config' needs to be an AccountConfig object"); assert(typeof(alter) == "boolean"); assert(typeof(successCallback) == "function"); assert(typeof(errorCallback) == "function"); if (MailServices.accounts.findRealServer(config.incoming.username, config.incoming.hostname,