How to validate response with dredd? - apiblueprint

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.

Related

Email rejected by the Gmail API because of To header

I'm trying to send a simple email via the Gmail API that's failing because of the RFC822-compliant To: undisclosed-recipients:; header. Sending with a regular address in the To header works fine. The RFC822 message is created by PHPMailer and recovered using preSend() and getSentMIMEMessage().
What am I doing wrong?
The message
Date: Tue, 21 Sep 2021 09:13:17 +0000
From: Rec1 <fictive1#gmail.com>
Cc: "Rec2 (fictive2#gmail.com)" <fictive2#gmail.com>
Bcc: fictive3#gmail.com
Message-ID: <vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg#vps>
X-Mailer: PHPMailer 6.5.1 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="b1_vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg"
Content-Transfer-Encoding: 8bit
To: undisclosed-recipients:;
Subject: test
This is a multi-part message in MIME format.
--b1_vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg
Content-Type: text/plain; charset=us-ascii
body
--b1_vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg
Content-Type: text/html; charset=us-ascii
<div dir="ltr">body</div>
--b1_vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg--
The answer
{
"error": {
"code": 400,
"message": "Invalid To header",
"errors": [
{
"message": "Invalid To header",
"domain": "global",
"reason": "invalidArgument"
}
],
"status": "INVALID_ARGUMENT"
}
}
Try manually adding undisclosed-recipients:; then add bcc.
$mail->AddAddress("undisclosed-recipients:;");
$mail->AddBCC("username#domain.com");
Worked on this post:
Sending mail with Phpmailer, BCC only, hiding TO header field
You have different issues but it might also solve the issue regarding invalid to header if set manually.

Comment on a post using linkedin api returns 403 Although i have all permissions required

i am trying to comment on a post using SocailActions Api
i am using the following permissions w_organization_social r_organization_social w_member_social
and i am logged in as a an admin of the page that i am trying to comment on its behalf
my request is :
POST https://api.linkedin.com/v2/socialActions/urn%3Ali%3Ashare%3AXXXXXXXXXX/comments HTTP/1.1
Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Host: api.linkedin.com
cache-control: no-cache,
X-Restli-Protocol-Version: 2.0.0
Accept: application/json
Content-Type: application/json
Content-Length: 136
{
"actor":"urn:li:organization:23741470",
"object" :"urn:Al:share:6664163994204549120",
"message":{
"text":"tessst"
}
}
and i am getting 403
{
"serviceErrorCode": 100,
"message": "Field Value validation failed in REQUEST_BODY: Data Processing Exception while processing fields [/actor]",
"status": 403
}
the same thing happened when i tried to use the ugcPost Api to post an new comment
any ideas what might cause this ?
i was able to solve this finally, i remove all header property except the content type and content length then it worked

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

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"
}

Unable to start processor using Nifi curl command

I am trying to run the below curl command to start and stop my processor in Nifi:
curl -i -H 'Content-Type: application/json' -XPUT -d '{"id":"016a1048-82dc-1262-fc26-ffcac4e76c1a","status":"Running"}' http://localhost:9090/nifi-api/processors/016a1048-82dc-1262-fc26-ffcac4e76c1a
But I am getting the below error:
HTTP/1.1 400 Bad Request
Date: Fri, 26 Apr 2019 07:41:09 GMT
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-XSS-Protection: 1; mode=block
Content-Type: text/plain
Vary: Accept-Encoding
Content-Length: 423
Server: Jetty(9.4.11.v20180605)
Cannot construct instance of `org.apache.nifi.web.api.dto.status.ProcessorStatusDTO` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('Running')
at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 55] (through reference chain: org.apache.nifi.web.api.entity.ProcessorEntity["status"])
What am I doing wrong?
see the api documentation: https://nifi.apache.org/docs/nifi-docs/rest-api/index.html
you need to call PUT /processors/{id}/run-status
and body should be like this:
{
"revision": {
"clientId": "value",
"version": 0,
"lastModifier": "value"
},
"state": "value",
"disconnectedNodeAcknowledged": true
}
you also could see the correct request in your browser dev-tools

500 Internal Server Error when trying to delete certain courses

Example:
Courses.Get successfully gets the course like this:
Request
GET https://classroom.googleapis.com/v1/courses/1053592526?key={YOUR_API_KEY}
Response
200
- HIDE HEADERS -
cache-control: private
content-encoding: gzip
content-length: 232
content-type: application/json; charset=UTF-8
date: Wed, 27 Apr 2016 11:45:29 GMT
server: ESF
vary: Origin, X-Origin, Referer
{
"id": "1053592526",
"name": "Test course 18",
"ownerId": "118150671162893595524",
"creationTime": "2016-03-11T12:49:19.459Z",
"updateTime": "2016-03-11T12:49:18.734Z",
"enrollmentCode": "aaiauvf",
"courseState": "ACTIVE",
"alternateLink": "http://classroom.google.com/c/MTA1MzU5MjUyNlpa"
}
Deleting it however gives the following:
Request
DELETE https://classroom.googleapis.com/v1/courses/1053592526?key={YOUR_API_KEY}
Response
500
- HIDE HEADERS -
cache-control: private
content-encoding: gzip
content-length: 104
content-type: application/json; charset=UTF-8
date: Wed, 27 Apr 2016 11:47:21 GMT
server: ESF
vary: Origin, X-Origin, Referer
{
"error": {
"code": 500,
"message": "Internal error encountered.",
"status": "INTERNAL"
}
}
Result is the same through code or through the web interface at https://developers.google.com/classroom/reference/rest/v1/courses/delete?authuser=0#try-it
This seems to happen if the user behind the OwnerId no longer exists. It only happens to some old courses that have been lying around for some time, and the owner have been deleted long ago. I also tried adding a teacher to the course, but the result is still the same. I did also try to create a new course with an ownerId referencing an existing user, deleting the user and finally deleting the course. Works.
There are 20 something courses on the domain that this happens for. I was able to delete another 50 something courses where the owning users still existed.
So, is this a bug that we can have fixed? And if not, how do I get rid of the courses?
It looks like this is a bug. Can you please file an issue for it?

Resources