Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Send Test Mail] Use json MimeType, send data via POST method and catch json response errors #9685

Merged
merged 14 commits into from
Apr 12, 2016

Conversation

andrepereiradasilva
Copy link
Contributor

Summary of Changes

  • Adds the correct HTTP header mimetype for json in sendmail test response and changes the HTTP method from GET to POST so the smtp server details (host, port, user, password) doesn't appear in the server/proxies log files.
  • Catch HTTP or json failure errors and display error message when that happens.

Testing Instructions

Correct HTTP header mimetype and HTTP method
  1. Go to global config in the admin panel
  2. Open the console in the chrome (F12)
  3. Select "Network" tab, "XHR" separator in Chrome console
  4. Click the "Send Test Mail" button. You will see a new URI in the Chrome console, click on it. Check in the "Response headers" the "Content type" HTTP header is content-type:text/html; charset=UTF-8 and the HTTP method is GET
  5. Apply patch
  6. Repeat steps 1 (clear javascript cache Ctrl+F5) to 4, you will see in the "Response headers" the content type HTTP header is content-type:application/json; charset=utf-8 and the HTTP method is POST
Catch HTTP or json failure errors
trigger_error('aaa', E_USER_WARNING);
  • Go to global config in the admin panel and send a test mail
  • You will get an error message (without this patch you get no message - javascript error).
    image

@brianteeman
Copy link
Contributor

is #5238 related?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@andrepereiradasilva
Copy link
Contributor Author

i think that's unrelated to this issue.

@brianteeman
Copy link
Contributor

brianteeman commented Mar 31, 2016 via email

@mbabker
Copy link
Contributor

mbabker commented Mar 31, 2016

Being completely honest with you, the last time I tried working with JDocumentJson it just felt completely broken (like it doesn't even JSON encode the data buffer for starters). Also seems pretty stupid if it forces downloads (which it didn't in that case where I was using it in Chrome, and this was last month I was working with it).

BTW, this is just me being nit-picky for the sake of being nit-picky, but headers should be consistently set and sent through the application like https://github.com/joomla/joomla-cms/blob/staging/components/com_finder/controllers/suggestions.json.php does (the day components ever get real automated tests written for them using PHP's header() function will just make things act up).

@andrepereiradasilva
Copy link
Contributor Author

ok just changed jquery javascript to handle the json object data without the need to use parseJSON (it's already fetched as a json object).

ready for testing.

NOTE: i also changed the HTTP method to POST so the smtp server password doesn't appear in the server/proxies log files.

@andrepereiradasilva andrepereiradasilva changed the title Use correct mimetype in HTTP headers for the json result in send mail test [Send Test Mail] Use json MimeType and send data via POST method Mar 31, 2016
@andrepereiradasilva
Copy link
Contributor Author

@piotrmocko please try now i have added some ajax fail treatments in this PR.

Don't forgot to clear the browser cache.

@andrepereiradasilva
Copy link
Contributor Author

no it also works on malformed json , just tested.

to trown a warning i added

trigger_error('aaa', E_USER_WARNING);

in https://github.com/joomla/joomla-cms/pull/9685/files#diff-f0600c10281461980c2770b1951d453eR42

Result:
image

HTTP status 200. Page:

Warning: aaa in /path/to/joomla-staging/administrator/components/com_config/controller/application/sendtestmail.php on line 42
{"success":true,"message":null,"messages":{"success":["The email was sent successfully to <strong>test@test.com<\/strong> using <strong>SMTP<\/strong>. You should check that you've received the test email."]},"data":true}

@piotrmocko
Copy link
Contributor

I will test it again

@andrepereiradasilva
Copy link
Contributor Author

ok, don't forget to clear the browser cache

@andrepereiradasilva andrepereiradasilva changed the title [Send Test Mail] Use json MimeType and send data via POST method [Send Test Mail] Use json MimeType, send data via POST method and catch json response errors Mar 31, 2016
@richard67
Copy link
Member

I have tested this item ✅ successfully on 6d22f55

Tested as described in the instructions, but with Firefox/Firebug and not Chrome console 👅


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@piotrmocko
Copy link
Contributor

Finally it helped :) It looks like it has changed in jQuery in last years.
You may consider to display in the message:
(jqXHR.responseText.indexOf('<html') === -1 ? jqXHR.responseText : error)

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @richard67


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @richard67


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@andrepereiradasilva
Copy link
Contributor Author

@richard67 @piotrmocko
Added better error reporting,Test instructions updated. Please test now.

@richard67
Copy link
Member

If you explain me what "mimified" means 😄


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@andrepereiradasilva
Copy link
Contributor Author

If you explain me what "mimified" means 😄

copy pasting ... errors... and lack of sleep

@richard67
Copy link
Member

Ah, I thought maybe it has to do with a girl named "Mimi"


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @mikeveeckmans, @richard67


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @mikeveeckmans, @richard67


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @mikeveeckmans, @richard67


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@andrepereiradasilva
Copy link
Contributor Author

ok. language variables added.

@@ -229,6 +229,11 @@ COM_CONFIG_SAVE_SUCCESS="Configuration successfully saved."
COM_CONFIG_SENDMAIL_ACTION_BUTTON="Send Test Mail"
COM_CONFIG_SENDMAIL_BODY="This is a test mail sent using "_QQ_"%s"_QQ_". If you receive it, then your email settings are correct!"
COM_CONFIG_SENDMAIL_ERROR="Test mail could not be sent."
COM_CONFIG_SENDMAIL_JS_ERROR_CONNECTION_ABORT="A connection abort as occured while fetching the JSON data."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAS not AS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all corrected

@brianteeman
Copy link
Contributor

Removed the RTC label and made some comments on the language strings


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 7, 2016
@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @mikeveeckmans, @richard67


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@andrepereiradasilva
Copy link
Contributor Author

The latest change was adding javascript language vars as @wilsonge requested.

@mikeveeckmans, @richard67, @brianteeman can you retest to get this RTC again?

@wilsonge
Copy link
Contributor

wilsonge commented Apr 7, 2016

This looks MUCH better - thankyou!

@richard67
Copy link
Member

I have tested this item ✅ successfully on f56e8c8


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@anibalsanchez
Copy link
Contributor

I have tested this item ✅ successfully on f56e8c8

Test OK


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@brianteeman
Copy link
Contributor

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Apr 8, 2016
@anibalsanchez
Copy link
Contributor

I have updated #9768 with the code from this issue.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9685.

@rdeutz rdeutz merged commit d5a0c4b into joomla:staging Apr 12, 2016
@andrepereiradasilva andrepereiradasilva deleted the patch-6 branch April 12, 2016 21:12
@rdeutz rdeutz modified the milestones: Joomla 3.5.2, Joomla! 3.6.0 May 1, 2016
@brianteeman brianteeman removed the RTC This Pull Request is Ready To Commit label May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Change This is for Translators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants