Skip to content

Adding a route for Mandrill's url check. #38794

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

Merged
merged 1 commit into from
Apr 7, 2020

Conversation

cromulus
Copy link
Contributor

@cromulus cromulus commented Mar 22, 2020

Summary

Mandrill's Inbound API checks to see if a URL exists before it creates the web hook. It sends a HEAD request to "/mandrill/inbound_emails", which rails converts into a GET request. This simply returns 200, and the word 'OK'.

Now we can generate inbound API calls with ease on Mandrill, without having to shuffle around tokens.

Fixes #37609

Other Information

CHANGELOG
Simplifies the creation of Mandrill Inbound API urls, no longer have to set a temporary "test-webhook" token.

@cromulus cromulus force-pushed the mandrill-ingress-tokenfix branch from 2a821d7 to cfc3a07 Compare March 22, 2020 19:23
@@ -10,6 +10,13 @@ class ActionMailbox::Ingresses::Mandrill::InboundEmailsControllerTest < ActionDi
@events = JSON.generate([{ event: "inbound", msg: { raw_msg: file_fixture("../files/welcome.eml").read } }])
end

test "verifying existence of mandrill inbound route" do
# the first request has a default INGRESS_API_TOKEN of "test-webhook"
get rails_mandrill_inbound_emails_url,
Copy link
Member

Choose a reason for hiding this comment

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

This should be head, right?

My reading of the documentation is that the HEAD request won't be signed at all - it's only the fallback POST that uses the "test-webhook" key.

Would you be able to verify this behaviour with a real Mandrill account?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, looks like it. I'll make the change.

It also appears as if some of the tests in railties break as a result of this change:
railties/test/commands/routes_test.rb:166 railties/test/commands/routes_test.rb:202 activemodel/test/application/rake/routes_test.rb:20

Should I update those tests so that they pass?

There are other tests that fail and I can't quite figure out why...
Should I continue to attempt to debug them?

Copy link
Member

@eugeneius eugeneius Mar 23, 2020

Choose a reason for hiding this comment

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

Yes, please do update those tests to reflect the new route added here. Ideally those tests would be more resilient to incidental changes... but the easiest path here is to play along 🙂

The other failures are against the latest nightly snapshot of Ruby, and won't cause the build to fail on their own - you can see them also failing on the latest (passing) master build here:

https://buildkite.com/rails/rails/builds/67787

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the tests. I think all of the tests that this change broke are now passing. Lets see what the buildkite comes back with. Regarding the conflicts below, I assume the maintainers can fix those problems?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like the tests are indeed passing now! ⭐️

We can fix the conflicts when merging if necessary, but if you're able to, rebasing your branch and fixing them yourself would help us out:

https://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#update-your-branch

@rails-bot rails-bot bot added the railties label Apr 4, 2020
@cromulus cromulus force-pushed the mandrill-ingress-tokenfix branch 5 times, most recently from 8b1b460 to 7518f04 Compare April 4, 2020 21:28
@cromulus cromulus requested a review from eugeneius April 4, 2020 22:24
Copy link
Member

@eugeneius eugeneius left a comment

Choose a reason for hiding this comment

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

This is looking good; I left a few style comments.

@cromulus cromulus requested a review from eugeneius April 5, 2020 00:01
@cromulus cromulus force-pushed the mandrill-ingress-tokenfix branch 4 times, most recently from 8c9032b to 3d4e0e4 Compare April 5, 2020 19:23
@cromulus
Copy link
Contributor Author

cromulus commented Apr 5, 2020

@eugeneius
I think we're ready to go!

@eugeneius
Copy link
Member

I forgot to ask earlier: could you add an entry to the changelog?

@cromulus
Copy link
Contributor Author

cromulus commented Apr 6, 2020

Changelog updated. Thank you for all of your help with this!

Mandrill's Inbound API checks to see if a URL exists before it creates
the webhook. It sends a HEAD request, to which we now return a 200 OK
response to indicate that the route exists.

Now we can generate inbound API calls with ease on Mandrill, without
having to shuffle around tokens in production.

Fixes rails#37609.
@eugeneius eugeneius force-pushed the mandrill-ingress-tokenfix branch from b82c6f4 to fce29be Compare April 7, 2020 12:40
@eugeneius
Copy link
Member

I tweaked a few things on your branch and squashed to one commit again. This now looks good to me, but I'd like to see if George has any feedback before merging.

@eugeneius eugeneius requested a review from georgeclaghorn April 7, 2020 12:51
@cromulus
Copy link
Contributor Author

cromulus commented Apr 7, 2020

Thanks!

@eugeneius eugeneius merged commit 9d8763b into rails:master Apr 7, 2020
eugeneius added a commit that referenced this pull request Apr 7, 2020
Adding a route for Mandrill's url check.
@eugeneius
Copy link
Member

Backported to 6-0-stable in 5bf69b4.

Thanks for sticking with this @cromulus 🙏

@cromulus
Copy link
Contributor Author

cromulus commented Apr 7, 2020

Thanks for helping out! I'm thrilled to be able to contribute even in this small way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initial setup of Mandrill for Action Mailbox requires a specific token
3 participants