Why does Karate strip chars from the front of my field names? - graphql

There is something strange going on with one of my Karate tests. I have quite a few I've inherited (rather than written myself) and they mostly all work fine. My application uses GraphQL and I'm changing an existing mutation function to add an argument. The new argument is a list of DestinationInput defined like this:
createScheduledTitles(titles: [ScheduledTitleInput!]!, destinations: [DestinationInput]!): [ScheduledTitle!]!
This is how I set up my arguments in my Karate script:
* def input =
"""
{titles: [ {
...
],
destinations: [
{
'destinationType': "od",
'brightcovePublish': "true"
}
]
}
"""
This gets rejected by the server end (java) with:
The variables input contains a field name 'stinationType' that is not defined for input object type 'DestinationInput'
Well, yes, of course but I'm supplying 'destinationType' not 'stinationType'. When I check the log of what was sent though I see this:
"destinations": [
{
"stinationType": "od",
"ightcovePublish": "true"
}
]
Huh? Where'd those initial characters go? I've since tried every combination of quotes (double, single, none) on field names and arguments. I've tried different line formatting etc. Some slight differences, some combinations leave the quotes in the field name so I see stinationtype\' as the field name in error, and sometimes it chews more letters off the front. I've retyped the field names in case I'd edited some hidden chars in there. So far nothing gets me to success. I've other working examples of this kind of thing and I've copied their format, but still no joy. Whatever is happening is at the client end because the log is showing the bad field names as being sent. Anyone know what I'm doing wrong?

Dev of Karate here - this is weird, never seen anything like it. Do keep in mind this may be a genuine server-side bug - but I guess you have looked at the request / http log.
My other guess without seeing the whole project structure is there may be some custom Java / JS code that is pre-processing the request, common for GraphQL projects. Try forming a cURL request that works, step 2 is convert that to a simple (hard-coded) karate test. and if you can manage this process, we can look at it: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
But I just tried using your sample JSON in a test you can replicate (even the HTTP POST). So try pasting this into a fresh Scenario:
Scenario:
* def input =
"""
{titles: [
{}
],
destinations: [
{
'destinationType': "od",
'brightcovePublish': "true"
}
]
}
"""
* print input
* url 'https://httpbin.org/post'
* request input
* method post
Which results in:
14:26:59.370 [main] INFO com.intuit.karate - [print] {
"titles": [
{
}
],
"destinations": [
{
"destinationType": "od",
"brightcovePublish": "true"
}
]
}
14:26:59.614 [main] DEBUG com.intuit.karate - request:
1 > POST https://httpbin.org/post
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 84
1 > Content-Type: application/json; charset=UTF-8
1 > Host: httpbin.org
1 > User-Agent: Apache-HttpClient/4.5.11 (Java/1.8.0_231)
{"titles":[{}],"destinations":[{"destinationType":"od","brightcovePublish":"true"}]}
14:27:00.890 [main] DEBUG com.intuit.karate - response time in milliseconds: 1274.99
1 < 200
1 < Access-Control-Allow-Credentials: true
1 < Access-Control-Allow-Origin: *
1 < Connection: keep-alive
1 < Content-Length: 696
1 < Content-Type: application/json
1 < Date: Thu, 13 Feb 2020 08:57:00 GMT
1 < Server: gunicorn/19.9.0
{
"args": {},
"data": "{\"titles\":[{}],\"destinations\":[{\"destinationType\":\"od\",\"brightcovePublish\":\"true\"}]}",
"files": {},
"form": {},
"headers": {
"Accept-Encoding": "gzip,deflate",
"Content-Length": "84",
"Content-Type": "application/json; charset=UTF-8",
"Host": "httpbin.org",
"User-Agent": "Apache-HttpClient/4.5.11 (Java/1.8.0_231)",
"X-Amzn-Trace-Id": "Root=1-5e450f5c-18d2618834da3a7afdd3402a"
},
"json": {
"destinations": [
{
"brightcovePublish": "true",
"destinationType": "od"
}
],
"titles": [
{}
]
},
"origin": "103.15.250.10",
"url": "https://httpbin.org/post"
}

Related

ES query from a golang server to ES returning error while the postman request directly to ES returns the expected results

This is the request body that I for this endpoint using Postman localhost:9201/response_v2_862875ee3a88a6d09c95bdbda029ce2b/_search
{
"_source": ["_id"],
"from": 1,
"size": 10,
: {
"should": {
"match": {
}
}, {
"range": {
"_updated_at": {
"from": "36163",
"include_lower": true,
"include_upper": true,
"to": null
}
}
}]
}
}
}
To this url localhost:9201/rensedbda029ce2b/_search
And I get the results https://gist.gith
But when I make the same request from my server to ES I get an error saying "elastic: Error 400 (Bad Request): Expected [START_OBJECT] but found [START_ARRAY] [type=parsing_exception]"
These are some snippets of my code. I get the query from another util function and use that while making the call to ES.
This is the call to ES res, err = r.esConn.Search(indexName).e(requestBody.ResponsePageLength).Do(ctx)
and the query builder function is this, it takes arguments which are extracted from the body of the request to my server and builds a query based on that.
func CreateMonitoringPipeline(maxResponseTime string, responseQueries []ResponseQuery, baselineFormId string) *elastic.BoolQuery {
finalQuery := elastic.NewBoolQuery()
dateRangeMatchQuery := elastic.NewRangeQuery("_updated_at").
Gte(maxResponseTime)
finalQuery.Filter(dateRangeMatchQuery)
}
return finalQuery
}
I can't figure out why is this happening? my ES is running using the ES binary and my server runs in a docker container.
Completely new to ES and golang so please help.
UPDATE:
This is what I got when I logged my request using SetTraceLog
| ELASTICPOST /resp8ecf8427e/_search HTTP/1.1
| Host: 172.17.0.1:9201
| User-Agent: elastic/5.0.81 (linux-amd64)
| Transfer-Encoding: chunked
| Accept: application/json
| Content-Type: application/json
| Accept-Encoding: gzip
|
| 7
| ["_id"]
| 0
I can't understand what do the 7 and ["_id"] mean. Is this my request body that ES received?
Thanks for uploading the logs, you are right that the ["_id"] is the request being sent. The problem is in the request line as Source([]string{"_id"}) does not set the source field to ["_id"] as you intended but instead:
Source allows the user to set the request body manually without using
any of the structs and interfaces in Elastic.
https://godoc.org/github.com/olivere/elastic#SearchService.Source
You want to use FetchSourceContext instead:
res, err = r.esConn.Search(indexName).From(requestBody.MaxResponseTimestampCount).FetchSourceContext(elastic.NewFetchSourceContect(true). Include("_id")).Query(query).Size(requestBody.ResponsePageLength).Do(ctx)
https://godoc.org/github.com/olivere/elastic#SearchService.FetchSourceContext

laravel JSON validation rule

I'm trying to use the 'json' validation rule in a form request, but I constantly get an invalid JSON message. I havent found any examples on how to use this rule, so I'm a bit lost here.
My rules function looks like this:
public function rules()
{
return [
'userData'=>'json',
'securityChanges'=>'json'
]
}
And my JSON looks like this:
{
"userData":{
"domicilio":"nowere",
"empresa":"Burgerking",
"name":"zorgito",
"surname": "perez",
"cuit":"10101010"
},
"securityChanges":{
"email": "flasheadas#lolo.com",
"password": "777777777777",
"passwordConfirmation":"777777777777"
}
}
My headers are properly set:
Accept: application/json
Content-Type: application/json
It should work, but I get:
"The user data must be a valid JSON string."
Any idea what's wrong here?
EDIT:
as requested n one of the answers, I'm putting the output of a dd($this->all()); in my form request class
array:2 [
"userData" => array:5 [
"domicilio" => "nowere"
"empresa" => "Burgerking"
"name" => "zorgito"
"surname" => "perez"
"cuit" => "10101010"
]
"securityChanges" => array:3 [
"email" => "flasheaasddas#lolo.com"
"password" => "777777777777"
"passwordConfirmation" => "777777777777"
]
]
The whole HTTP request is:
PATCH /api/users/me HTTP/1.1
Host: DOMAIN REMOVED
Authorization: Bearer (TOKEN REMOVED.)
Accept: application/json
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 73516b63-8556-4c21-9050-7a4fa3a83cb1
{
"userData":{
"domicilio":"nowere",
"empresa":"Burgerking",
"name":"zorgito",
"surname": "perez",
"cuit":"10101010"
},
"securityChanges":{
"email": "flasheaasddas#lolo.com",
"password": "777777777777",
"passwordConfirmation":"777777777777"
}
}
Nothing clear here, please make dd($request->all()) or dd($this->all()) (if you are in request class directly) and make sure you have that fields, and then make sure that fields are valid json strings. You can check it here https://jsonlint.com/

APIGILITY + Doctrine: cannot find entities = "No result was found for query although at least one row was expected"

I have a service, doctrine related, completely created by Apigility, with no modifications what so ever. The code was never modified, it works just as Apigility created it.
When requesting a collection:
myapi.local/path
{
"count": 25,
"total": 13562,
"collectionTotal": 13562,
"_links":
{ ... more stuff here
},
"_embedded":
{
"path":
[
{
"pathid": 1,
"dev": 51729,
"inode": "2",
"path": "/disk1",
"online": true,
"fileid": "0",
"_links":
{
"self":
{
"href": "http://imageadministration.local/path/1"
}
}
},
... and so on
When requesting that very same entity myapi.local/path/1:
{
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "Not Found",
"status": 404,
"detail": "Entity was not found"
}
Response headers:
Status Code: 404 Not Found
Access-Control-Allow-Headers: Authorization, Origin, Content-Type, Accept
Access-Control-Allow-Methods: PUT, GET, POST, PATCH, DELETE
Connection: Keep-Alive
Content-Type: application/problem+json
Date: Fri, 08 Apr 2016 08:40:35 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.10 (Debian)
Transfer-Encoding: chunked
X-Powered-By: PHP/5.6.17
access-control-allow-origin: *
Debuging the code step by step, I could find a "No result was found for query although at least one row was expected". This message is inside a Doctrine object and never gets back to the user. No PHP erros, no exceptions, nothing. Indeed, the registry can be found in the DB with a simple select.
The error message itself is explained in other posts, but since this service is 100% created by Apigility and the exception ocurs inside the Doctrine module and there is not a single line of code of my own, I don´t even know where to start. Entity has no relations and it was automatically created by Doctrine via orm-module.
Any direction will be much appreciated, czr.
SOLVED: it happened to be a very strange encoding error with üäö. when removed, it went back to normal. Unfortunately is still don´t know why.

How to validate response with dredd?

I'm trying to check my api implementation with my documentation written in blueprint. I've expected that dredd will fail when json returned from server will be different than specified in documentation. To check this I've copied dredd-example. First I've run dredd with original apib file to make sure that all is green. Then I've modified response in documentation and expected dredd to show me some red... But it doesn't.... it looks like tool is only checking response headers but not the response body. Here is output from console:
pass: GET /machines duration: 18ms
request:
host: localhost
port: 3000
path: /machines
method: GET
headers:
User-Agent: Dredd/0.2.1 (Darwin 13.0.0; x64)
expected:
headers:
Content-Type: application/json
body:
[
{
"_id": "52341870ed55224b15ff07ef",
"type": "bulldozer",
"name": "willyxxxxxx" #HERE IS WHERE I CHANGED RESPONSE IN DOCUMENTATION
}
]
status: 200
actual:
headers:
x-powered-by: Express
content-type: application/json
content-length: 95
date: Thu, 20 Mar 2014 08:22:40 GMT
connection: keep-alive
body:
[
{
"_id": "532aa5507dcdfff362931799",
"type": "bulldozer",
"name": "willy"
}
]
status: 200
Can I check response body using dredd? And how can I do this?
In JSON bodies Dredd is checking only for keys not for values. When you change key in the expected JSON body document, it will definitely fails.

Jmeter HTTP request java.net.URISyntaxException: Illegal character in query at index 71

It's the first time I'm encountering this error for HTTP request (POST).
I'm trying to do a simple post request, not sure why it doesn't work using the Jmeter.
please help :-)
URL:
https://connect-qa.bglobale.com:4453/Checkout/SendCart?shippingDetails={"CountryCode":"LI"}&clientIP=79.120.71.29&priceCoefficientRate=1&includeVAT=0&discountsList={"DiscountValue":29.028122604,"OriginalDiscountValue":122.838,"Name":"Cart Discount","DiscountType":1,"VATRate":18}&merchantCartToken=1294&currencyCode=CHF&originalCurrencyCode=ILS&cultureCode=en-GB&preferedCultureCode=en_US&shippingOptionsList={"Carrier":"flatrate","CarrierTitle":"Flat Rate","CarrierName":"Flat Rate","Code":"flatrate_flatrate","Method":"flatrate","MethodTitle":"Fixed","MethodDescription":null,"Price":0}&hubId=1&merchantGUID=0f4eec24-8988-4361-be9a-a7468d05f1fe
Headers:
Content-Type: application/json; charset=utf-8
Body:
[
{
"ProductCode":"7290012491047",
"ProductGroupCode":null,
"Name":"Natural and Organic Calendula Shampoo 400ml",
"Keywords":null,
"ProductURL":null,
"Description":"Natural and Organic Calendula Shampoo 400ml",
"GenericHSCode":"",
"Weight":"0.5000",
"Height":null,
"Length":null,
"Width":null,
"Volume":null,
"ImageURL":"/c/a/calendula_shampoo.jpg",
"ImageWidth":"",
"ImageHeight":"",
"OriginCountryCode":"",
"ListPrice":"8.90",
"OriginalListPrice":"47.2",
"SalePrice":"8.90",
"OriginalSalePrice":"47.2",
"UnitSalePriceForDuties":null,
"OriginalSalePriceAfterGlobalEDiscount":null,
"VATRateType":{
"VATRateTypeCode":"2",
"Name":"VAT",
"Rate":18
},
"Brand":null,
"Categories":[
{
"CategoryCode":"4",
"Name":"Baby"
},
{
"CategoryCode":"18",
"Name":"Calendula"
},
{
"CategoryCode":"20",
"Name":"Chamomile"
},
{
"CategoryCode":"24",
"Name":"​Coconut Oil"
},
{
"CategoryCode":"26",
"Name":"Geranium Oil"
},
{
"CategoryCode":"29",
"Name":"Jojoba"
},
{
"CategoryCode":"30",
"Name":"Lavender"
},
{
"CategoryCode":"38",
"Name":"Rosemary"
},
{
"CategoryCode":"39",
"Name":"Sea Buckthorn"
},
{
"CategoryCode":"42",
"Name":"Soapwort"
},
{
"CategoryCode":"45",
"Name":"Sunflower Oil"
}
],
"OrderedQuantity":1,
"IsBlockedForGlobalE":null
}
]
The error you're receiving indicates that you're sending a GET request, not POST. Make sure that you have selected POST method in HTTP Sampler.
You may also find Testing SOAP/REST Web Services Using JMeter guide useful.

Resources