azrosen92
azrosen92

Reputation: 9117

Stubbing protect_from_forgery in rspec for API specs

I'm building an api for my Rails app and would like to protect it from CSRF attacks, using protect_from_forgery. I'm writing request specs for the ApiController, and would like to write specs for the response I get when the CSRF in the request is invalid. My question is how do I stub the behavior of protect_from_forgery to mimic an invalid CSRF token?

Upvotes: 2

Views: 1625

Answers (1)

Jonas Meinerz
Jonas Meinerz

Reputation: 622

allow(ApiController).to receive(:protect_from_forgery).and_return(false)

Upvotes: 3

Related Questions