Created
September 8, 2016 10:50
-
-
Save hannesl/346e1e691f824f5267945d776349f7ce to your computer and use it in GitHub Desktop.
Testing http basic authentication in Rails 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Woot woot, very nice!