sideshowcoder / canned

Server to respond with fake API responses, by using a directory of files for finding out what to say!
213 stars 46 forks source link

File name is interpreted as regular expression #49

Closed mamtasuri-coraid closed 9 years ago

mamtasuri-coraid commented 9 years ago

Canned is working great for simple file names such as v1/info/index.get.json. But when we have complicated names that we are testing from influxdb, it's giving an error saying that can't interpret as regular expression. Please suggest!

curl -sLGw "\n%{http_code} %{url_effective}\n" "http://localhost:17022/db/EtherCloudStats/series?u=root&p=root&q=select+mean(value)+from+%22Coraid.1Controller.ZFS.VOps-3008.gauge.wlat%22+where+time+%3E++now()+-+86400000000u+and+time+%3C+now()+-+0u+group+by+time(240000000u)+fill(null)"

Message from canned: request: get /db/EtherCloudStats/series?u=root&p=root&q=select+mean(value)+from+%22Coraid.1Controller.ZFS.VOps-3008.gauge.wlat%22+where+time+%3E++now()+-+86400000000u+and+time+%3C+now()+-+0u+group+by+time(240000000u)+fill(null) /home/msuri/ec/testeng/data/mock/canned/canned.js:29 new RegExp(fname + "(?=." + queryString.split("&").join(")(?=.") + ").+" ^ SyntaxError: Invalid regular expression: /(?=._u=root)(?=._p=root)(?=.*q=select+mean(value)+from+%22Coraid.1Controller.ZFS.VOps-3008.gauge.wlat%22+where+time+%3E++now()+-+86400000000u+and+time+%3C+now()+-+0u+group+by+time(240000000u)+fill(null)).+get/: Nothing to repeat at new RegExp () at matchFileWithExactQuery (/home/msuri/ec/testeng/data/mock/canned/canned.js:29:5) at getFileFromRequest (/home/msuri/ec/testeng/data/mock/canned/canned.js:51:13) at Canned._responseForFile (/home/msuri/ec/testeng/data/mock/canned/canned.js:123:20) at /home/msuri/ec/testeng/data/mock/canned/canned.js:168:10 at Object.oncomplete (fs.js:107:15)

sideshowcoder commented 9 years ago

I think this is a bug which I didn't encounter, yet. Sorry about that! I think the problem is that you request contains regex special characters which are not escaped by canned. Could you try to use the master branch and try to put the query string into the file itself using the new multiple responses per file capability? Also could you maybe put an example in a gist so I can reproduce it locally? Oh and happy holidays!

mamtasuri-coraid commented 9 years ago

Thanks for your quick response. For some reason, when I try to use master even the simple case that used to work is not working anymore, so not sure if there is some additional config required as it's not getting the canned responses. So I have switched back to the branch I was using from couple of weeks ago.

Here is the gist, and the steps I am using. Happy Holidays! Your help is much appreciated.

https://gist.github.com/mamtasuri-coraid/0ec6f95fd96cebe9e720

sideshowcoder commented 9 years ago

Thanks for the gist I will look into it as soon as possible but won't be able to until Monday most likely. Sorry about that.

sideshowcoder commented 9 years ago

This was indeed a bug, and I hopefully fixed in with the latest master. Also I would like to add that you should name your files besides the querystring, instead of ?foo=bar.get.json to get a match for localhost:4567/?foo=bar you can use the special index keyword making it index?foo=bar.get.json to get the same match.

Also since you said the current version is not working for you for other cases do you mind filing another issue for the things which are broken? That would help me very much to make sure canned stays compatible.

mamtasuri-coraid commented 9 years ago

Thanks Philipp for the quick fix. I'll try it out tomorrow and will let you know.

Thanks, Mamta

On Dec 28, 2014, at 10:47 AM, Philipp Fehre notifications@github.com<mailto:notifications@github.com> wrote:

This was indeed a bug, and I hopefully fixed in with the latest master. Also I would like to add that you should name your files besides the querystring, instead of ?foo=bar.get.json to get a match for localhost:4567/?foo=bar you can use the special index keyword making it index?foo=bar.get.json to get the same match.

Also since you said the current version is not working for you for other cases do you mind filing another issue for the things which are broken? That would help me very much to make sure canned stays compatible.

— Reply to this email directly or view it on GitHubhttps://github.com/sideshowcoder/canned/issues/49#issuecomment-68215488.