Skip to content

Instantly share code, notes, and snippets.

@hannesl
Created September 8, 2016 10:50
Show Gist options
  • Select an option

  • Save hannesl/346e1e691f824f5267945d776349f7ce to your computer and use it in GitHub Desktop.

Select an option

Save hannesl/346e1e691f824f5267945d776349f7ce to your computer and use it in GitHub Desktop.
Testing http basic authentication in Rails 5
class MyControllerTest < ActionDispatch::IntegrationTest
test "authentication" do
params = {test: "object"}
auth_headers = {"Authorization" => "Basic #{Base64.encode64('test:test')}"}
post '/my-controller', params: params, as: :json
assert_response 401
post '/my-controller', params: params, as: :json, headers: auth_headers
assert_response :success
end
end
@jkeam
Copy link
Copy Markdown

jkeam commented Oct 26, 2017

Woot woot, very nice!

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