Testing webhooks - brownfield-team/anacapa-github-linker GitHub Wiki

When testing with webhooks, one challenge is that you webhooks need to have a publicly available web address to send their replies back to.

Of course, if your server is running on localhost, that won't work. For example:

POST https://api.github.com/orgs/ucsb-cs48-s20/hooks: 422 - Validation Failed
Error summary:
  resource: Hook
  code: custom
  message: Sorry, the URL host localhost is not supported because it isn't reachable over the public Internet // See: https://docs.github.com/rest/reference/orgs#create-an-organization-webhook
   (0.2ms)  COMMIT
Redirected to http://localhost:3000/courses/1
Completed 302 Found in 1057ms (ActiveRecord: 4.8ms)

So, one solution might be ngrok. As yet, that's untested, but it's a candidate. That way you don't have to keep deploying on an Heroku instance to test webhook functionality.

The idea with ngrok is that you first create an account at ngrok.com (you can use GitHub as your login). Then you can register a localhost server "as if" it's on the public internet.

You download ngrok, and do a one time configuration step where you type a command such as this:

./ngrok authtoken 9zuvs_FAKE_s98_TOKEN_89vjsdlv8sjoev

The actual value of the token associated with your account can be found on this page once you are logged in: https://dashboard.ngrok.com/get-started/setup

  • Then, you start your rails server, say, on port 3000 with bundle exec rails s
  • And then start ngrok with ./ngrok http 3000

You'll be given a URL such as http://abcd1234.ngrok.io that will proxy to your running localhost. (Your URL will vary).

You'll also then notice that OAuth doesn't work. Womp-womp, you need to get a new client id and client secret that does a callback to http://abcd1234.ngrok.io/users/auth/github/callback instead of http://localhost:3000/users/auth/github/callback, and then update the values in .env and restart your rails server.

But then, with luck, it should all work.