xolvio / meteor-http-interceptor

Intercepts HTTP calls and allows fake implementations to take over entire domains. Used for testing.
13 stars 5 forks source link

Calling HTTP.Call with certain data options breaks insertion into HttpInterceptor.Calls collection #3

Closed fongandrew closed 9 years ago

fongandrew commented 9 years ago

Inserting a new call into the Calls collection throws an exception if one of the options passed to HTTP.call contains keys that are valid Javascript / JSON-able, but are not valid Mongo document field names.

In my particular case, I'm posting a query to ElasticSearch by calling HTTP.call with options.data set to a JSON-able object with "cards.label" as a key. HttpInterceptor tries to insert the options object as-is into Mongo, which causes Mongo to reject the insertion (because of the "." in the options.data field name).

Relevant piece of code appears to be here: https://github.com/xolvio/meteor-http-interceptor/blob/master/server.js#L143-152

Traceback below:

Exception from sub n9s9p33EJYm4MoNtC Error: key cards.label must not contain '.'
I20150303-23:40:49.420(0)?     at Object.Future.wait (/home/vagrant/.meteor/packages/meteor-tool/.1.0.41.he8l4j++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:323:16)
I20150303-23:40:49.420(0)?     at [object Object].<anonymous> (packages/meteor/helpers.js:119:1)
I20150303-23:40:49.420(0)?     at [object Object].MongoConnection.(anonymous function) (packages/mongo/mongo_driver.js:634:1)
I20150303-23:40:49.420(0)?     at [object Object].Mongo.Collection.(anonymous function) (packages/mongo/collection.js:574:1)
I20150303-23:40:49.420(0)?     at [object Object].Mongo.Collection.(anonymous function) [as insert] (packages/aldeed:collection2/collection2.js:159:1)
I20150303-23:40:49.421(0)?     at Object._init.Package.http.HTTP.call (packages/xolvio:http-interceptor/server.js:143:1)
I20150303-23:40:49.421(0)?     at Object.HTTP.call (packages/meteorhacks:kadira/lib/hijack/http.js:10:1)
I20150303-23:40:49.421(0)?     at Object.ES.call (packages/fongandrew:elasticsearch/elasticsearch_server.js:55:1)
I20150303-23:40:49.421(0)?     at Object.ES.search (packages/fongandrew:elasticsearch/elasticsearch_server.js:217:1)
I20150303-23:40:49.421(0)?     at [object Object].ES.Index.(anonymous function) [as search] (packages/fongandrew:elasticsearch/elasticsearch_server.js:243:1)
samhatoum commented 9 years ago

That's a bug indeed. I'm currently super swamped with other tasks. If you are able to put together a PR I'd be more than happy to merge. :)

fongandrew commented 9 years ago

If this looks fine to you, can you publish to atmosphere? Thanks!

samhatoum commented 9 years ago

Done, sorry for delays! 0.4.2 is published