I'm trying to write a test for my server side form validation but I keep getting a Forbidden error. It seems that this needs to be a 2 step process. Step 1, acquire the CSRF value from the form. Step 2, use the CSRF value to post to the form handler. However no matter how I try to post I get a forbidden error.
--full test: https://github.com/socketwiz/swblog/blob/master/test/contact.js#L57-L100
I've tried changing the following line thusly: https://github.com/socketwiz/swblog/blob/master/test/contact.js#L85
.send({name: 'foo', 'X-CSRF-Token': token})
.set('X-CSRF-Token', token)
.set('Cookie', ['X-CSRF-Token=' + token])
But nothing I try will seem to satisfy the CSRF requirement. The more I try the more complex this gets for what seems like a simple thing. Maybe I'm going about this all wrong. Any ideas?