0

I have a set of API tests which are failing on a Jenkins run via the MSTest runner plugin. On investigation, the exception message returned is the following

Status: BadRequest. Reason: {"Message":"The request is invalid."}

The encoded url is getting the %20 stripped from DateTime type'd parameters and the request url at this point now is attempting to post with spaces.

Example of query string /GenerateReport?startDate=09/05/2017 09:58:45&endDate=14/05/2017 09:58:45

If I run these tests directly from Visual Studio they pass and on capturing the post request, it is passed encoded as expected.

Anyone able to explain why this would be happening when executing these tests only via Jenkins/MSTest plugin? And if so, do you have a work around/config change available?

Sibeesh Venu
  • 18,755
  • 12
  • 103
  • 140
jwelsh
  • 1
  • It would help if you showed the test case. – nbokmans May 15 '17 at 10:16
  • what happens if you change the spaces in your query string to actually ahve %20 not spaces in? – BugFinder May 15 '17 at 10:30
  • @BugFinder - The post returns a 200 so it goes through successfully. This is what actually happens when executing the test through VS test explorer directly (the url stays encoded) – jwelsh May 15 '17 at 10:32
  • because you actually sent a valid query string, proper spaces arent valid, Id agree with your test case, its not valid until you have encoded the string. – BugFinder May 15 '17 at 10:35
  • Hi @nbokmans, thanks for the reply. We have our own internal sdk which I'm hooking into for these tests, these sdk classes/methods expose our logic. Example of one of the async test calls - *bool result = await Referral.GenerateReport(DateTime.Parse("2017-05-09"), DateTime.Parse("2017-05-14"))* edit: updated comment, passed in wrong test example – jwelsh May 15 '17 at 10:37
  • @BugFinder - yeah i would expect it to fail if the url wasn't encoded, i'm trying to figure out why Jenkins/MSTest plugin is doing this? if indeed that is the cause of the problem – jwelsh May 15 '17 at 10:39
  • @SibeeshVenu - thank you – jwelsh May 15 '17 at 10:42
  • @jwelsh but with the info you've given us all to work with - you arent encoding it - only that the query string has spaces in. – BugFinder May 15 '17 at 11:02
  • **1.** Is it possible your machine and the server are using different locale (`CultureInfo.CurrentCulture` / Region and Language, date format)? **2.** I've had a similar problem in the past where line ending changed automatically *on code checkout*, failing some tests (probably not your case). – Kobi May 15 '17 at 11:19
  • @Kobi - **1.** i'm currently running these tests on a local instance of jenkins against a QA test environment. Tests run locally via VS Test Explorer pass and encode the url correctly. Tests run locally via Jenkins/MSTest plugin are failing and not encoding the url as it should be expecting. – jwelsh May 15 '17 at 12:43
  • @BugFinder - yeah it's obviously not getting encoded somewhere along the line. We have our own internal SDK which has set up authentication etc as if you were connecting as a 3rd party. All I'm doing is passing in parameters to a method which then builds up a url and the get/post request is sent to our QA environment. Url encoding is working fine when running these tests against our QA envinroment via VS test explorer directly and command line (on my local machine), but only fails when this process is done via Jenkins/MSTest plugin (also on my local machine). – jwelsh May 16 '17 at 08:55

1 Answers1

0

@Kobi - you were correct, sorry I haven't replied earlier.

  1. Is it possible your machine and the server are using different locale (CultureInfo.CurrentCulture / Region and Language, date format)?

I'm now parsing the DateTime param with the culture specific format (CultureInfo.CurrentCulture). I hadn't also hadn't read your response properly, our development environment is on a US server and I'm UK based so that would be expected.

Thank you.

jwelsh
  • 1