Pact & Multipart/Form-Data

786 views
Skip to first unread message

Behdad

unread,
May 18, 2016, 7:58:01 PM5/18/16
to Pact
Hi all,

I am trying to test a scenario where the request contains Multipart/Form-Data.
This of-course is not a standard JSON and it is not supported by Pact.

However, does anyone have any suggestion on how to test this via pact? 

The data being send looks like:

------WebKitFormBoundaryAo5ACaMXzKRL2lFA
Content-Disposition: form-data; name="file"; filename="AResume.txt"
Content-Type: text/plain

My resume
------WebKitFormBoundaryAo5ACaMXzKRL2lFA--

The two problems with the above is:

1) Send this as part of pact
2) Mock server matching the request to what we program it with due to the dynamic values of the Boundary

I thought of one approach which is a bit complicated is to specify the Boundary in the header:

headers: {
'Content-Type': 'multipart/form-data; boundary="test"'
}

Then specify the body to be 

------test
Content-Disposition: form-data; name="file"; filename="AResume.txt"
Content-Type: text/plain

My resume
------test

Then when the request is being send to the mock server, intercept it and replace:

------WebKitFormBoundaryAo5ACaMXzKRL2lFA

with 

------test

This will get a bit more complex when dealing with .doc, .pdf, .etc and doesn't really feel right.

There possibly is a simpler solution.

I appreciate your thoughts.

Thanks.
Behdad.






Ronald Holshausen

unread,
May 18, 2016, 10:32:17 PM5/18/16
to Behdad, Pact
There is no current way of intercepting and changing the request before it is sent to the mock server. This is definitely a problem. I think a better solution would be to specify that the content type is 'multipart/form-data' and then have the mock server write out the actual content type received and not match on the content type attributes. That way the boundary in the header will match the boundary in the body. 

Which language implementation are you using?


--
You received this message because you are subscribed to the Google Groups "Pact" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pact-support...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Ronald Holshausen

DiUS Computing Pty Ltd

Level 10, 99 Queens Street
Melbourne, VIC 3000

Phone: +61 3 9008 5400
Mobile: +61 413 162 439

http://www.diuscomputing.com.au

Behdad

unread,
May 18, 2016, 11:24:56 PM5/18/16
to Pact, behdad.w...@gmail.com
I understand that mock server/pact doesn't currently have the intercept but I think we should be able to configure the test environment to let the requests
go through a handler to modify it. Sort of like using a DelegatingHandler in .Net:


The language is jscript(nodejs + angular).

Ronald Holshausen

unread,
May 18, 2016, 11:53:59 PM5/18/16
to Behdad, Pact
The big problem we have with interceptors is that they can change things, which can make the contract being generated different than the test expectations.
Reply all
Reply to author
Forward
0 new messages