Getting 503 error from Karate for API which works fine on Postman or Insomnia [duplicate] - karate

This question already has an answer here:
Karate DSL: Getting connection timeout error
(1 answer)
Closed 2 years ago.
While performing a get call for an api via karat observing DNS error when the proxies im using is commented but if i use the proxy it returns 401 error.
Below is the Following Code :
Feature File Code :
Background:
*url baseUrl
*def someData = { user:'"myemailid"','ContentType':'application/json',"Accept": "*/*"}
*headers someData
Scenario: SomeScenario
Given path '/clients'
When method GET
Then status 200
Karate Config :
function()
{
karate.configure('proxy','ip address')
var config = {
baseUrl:'some url'
}
return config;
}
Request Send to the server:
DEBUG com.intuit.karate - request:
1 > GET url
1 > Accept: */*
1 > Accept-Encoding: gzip,deflate
1 > Content-Type: application/json
1 > Host: scrbmapdk007182:8080
1 > Proxy-Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_141)
1 > user: "myemail"
Response is 502 with along with DNS error
Not sure where im going wrong because it is working via postman .Request send is same as in postman

Read the docs: https://github.com/intuit/karate#configure
Has to be in http: or https: URI form including port number if applicable:
karate.configure('proxy','http://myhost:80');
EDIT: for others landing here, besides the fact that an HTTP proxy may be in the picture - another place where Karate behaves a bit differently than Postman is that Karate does not auto-send an Accept header by default.

Related

Error: read ECONNRESET && node js do not make any post request

i have this issue in my API my node js do not make any post request
that what is shown in console
GET /api/user 200 37.328 ms - 195
GET /api/user 200 5.662 ms - 195
POST /api/category - - ms - -
POST /api/user/register - - ms - -
POST /api/user/login - - ms - -
like you see the all request but in the POST is not working I have this issue in POSTMAN when I make a post request
I don`t think that issue is cuz of code cuz I have build many post request
when I make a restart that message shown in POSTMAN console
Error: read ECONNRESET
Request Headers
x-auth-token: this is my token
Content-Type: application/json
User-Agent: PostmanRuntime/7.29.0
Accept: */*
Postman-Token: 2b4d5bc9-8bfc-4dc5-8608-24666dc5e754
Host: localhost:3000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

Is there any way to mask appKeys/passwords from [Jenkin] console for security purpose?

We have a good number of API Automation test cases running in lower environments with the Karate framework, and now we need to run all scenarios In Prod.
As of now, Karate has amazed us with its capabilities, but now We are facing a security issue.
When we are running scenarios with Jenkins, then in the Jenkins console, in the request body, we are showing the app key.
We want to mask the app key which we sent from the request body header from the console.
Is there a way to do it from the logback-test.xml file or any other alternate approach?
The Karate version which we are using is 0.9.6.
Below is one sample request:
1 > GET "URL"
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Host: qa-content.api.platts.com
1 > User-Agent: Apache-HttpClient/4.5.12 (Java/1.8.0_261)
1 > appkey: **"appkeyValue"**
07:39:31.636 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate - response time in milliseconds: 36.58
1 < 200
1 < Access-Control-Allow-Origin: *
1 < Connection: keep-alive
What I did so far:
I have added the DemoLogModifier java class in my project and in my feature file, I am calling it as (Added these 2 lines only) :
Java class URL; https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/headers/DemoLogModifier.java
* def LM = Java.type('allEndPoints.DemoLogModifier')
* configure logModifier = new LM()
But still, it's printing everything in the console.
Any lead/any help would be appreciated.
Edit -1: My feature file now looks like this:
Feature: Validate API metadata behavior
Background:
* def LM = Java.type('allEndPoints.DemoLogModifier')
* configure logModifier = new LM()
Scenario: Validate that API is responding 200 ok response with the correct id
Given url baseURL -> Reading from config file
And path abc -> Reading from config file
And param highlight = true
And header appkey = APIappKey -> Reading from config file (This value
need to mask)
When method get
Then status 200
In Java class, I have not done any change.

Karate UI - invalid cookie domain when setting cookie() [duplicate]

This question already has an answer here:
Karate UI - Maintain browser cookies/session/local storage variable value accorss different scnearios
(1 answer)
Closed 1 year ago.
I am setting the cookie for UI tests in a feature file using the existing login functionality implemented for API tests. Similar to what is described as 'hybrid approach' in karate docs and also in this thread - Karate UI - Maintain browser cookies/session/local storage variable value accorss different scnearios
My feature file is:
Feature: UI one time login test
Background:
# I am using the existing login functionality. I perform a onetime login in karate-config and store the cookie in a config variable and assign that to token variable defined below.
* def token = { value: '#(userAuthInfo.authSession)' }
# Then configure chromedriver
* configure driver = { type: 'chromedriver', showDriverLog: true, webDriverSession: { capabilities: { alwaysMatch: { acceptInsecureCerts: true } } } }
# Set the cookie
* driver 'about:blank'
* cookie({ name: 'SESSION', value: token.value, domain: 'localhost' })
Scenario: Visit url - 1
# webBaseUrl is defined in config
* driver webBaseUrl + 'url1'
When i run this feature and check the logs, I can see that correct request data is passed to /cookie endpoint and response from web driver api is error: 400 - invalid cookie domain. I also opened my site in chrome manually and checked how the cookie is set and its exactly the same as I am passing the json in cookie() method, including the domain. Even tried with a different domain on a different server and get the same error. Maybe it's not specific to domain as omitting the domain key in the request produces the same result.
Details below:
POST request to set cookie
14:06:36.495 [pool-1-thread-1] DEBUG com.intuit.karate - request:
4 > POST http://localhost:9515/session/c837c3e34a7dffa03fa4dc281ba0e3da/cookie
4 > Accept-Encoding: gzip,deflate
4 > Connection: Keep-Alive
4 > Content-Length: 97
4 > Content-Type: application/json; charset=UTF-8
4 > Host: localhost:9515
4 > User-Agent: Apache-HttpClient/4.5.11 (Java/1.8.0_262)
{"cookie":{"name":"SESSION","value":"cd02f1d7-6100-450b-bad9-edba8ead96b3","domain":"localhost"}}
Error 400 response:
14:06:36.501 [pool-1-thread-1] DEBUG com.intuit.karate - response time in milliseconds: 4.97
4 < 400
4 < Content-Length: 1696
4 < Content-Type: application/json; charset=utf-8
4 < cache-control: no-cache
{"value":{"error":"invalid cookie domain","message":"invalid cookie domain\n (Session info: chrome=86.0.4240.111)","stacktrace":"0 chromedriver 0x00000001080bbc29 chromedriver + 2464809\n1 chromedriver
Any ideas what could be going on?
Possibly an area where you can investigate and help us make changes. I've noticed chromedriver is fussy. Try with geckodriver and see if there is any difference. Would be great if you try with some other UI framework and see if we are missing any special handling.
One suggestion is add an etc/hosts entry to map localhost to something.com and use that domain.
Also see this: https://stackoverflow.com/a/59099843/143475

How to pass x-www-form-urlencoded - grant_type=client_credentials in Karate

How to pass x-www-form-urlencoded - grant_type=client_credentials in Karate.
Hi,
I am trying to pass value grant_type=client_credentials in the form of x-www-form-urlencoded in karate which i was doing with postman.
i know karate will default set the content type as x-www-form-urlencoded, but can u help what i am doing wrong here?
Karate script:
enter code here
Given url 'http://env/singlesignon/v1/access/token'
And header Authorization = 'Basic c2JsLWFwaWdlZS1lemJvYi1jbGllbnQ6c2JsLWFwaWdlZGllbnQ='
And header X-Correlation-Id = 'alibgefh'
And header X-Consumer = 'APIGEE'
And form field grant_type = 'client_credentials'
When method post
Then status 200
Request headers:
enter code here
Authorization: Basic c2JsLWFwaWdlZS1lemJvYi1jbGllbnQ6c2JsLWFwaWdlZGllbnQ=
Connection: Keep-Alive
Content-Length: 29
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Consumer: APIGEE
X-Correlation-Id: alibgefh
Response:
{"error_description":"Wrong Content Type","error":"Bad Request" }
Maybe your server doesn't like the charset=UTF-8 part (which is a bug on your server). Try adding this line before:
* configure charset = null
Else there is insufficient data in your question. Work with someone in your server-side team if possible. You can try to edit your question with a working cURL command, that might help.

DNS error observed while performing API testing using karate framework [duplicate]

This question already has an answer here:
Karate DSL: Getting connection timeout error
(1 answer)
Closed 2 years ago.
While performing a get call for an api via karat observing DNS error when the proxies im using is commented but if i use the proxy it returns 401 error.
Below is the Following Code :
Feature File Code :
Background:
*url baseUrl
*def someData = { user:'"myemailid"','ContentType':'application/json',"Accept": "*/*"}
*headers someData
Scenario: SomeScenario
Given path '/clients'
When method GET
Then status 200
Karate Config :
function()
{
karate.configure('proxy','ip address')
var config = {
baseUrl:'some url'
}
return config;
}
Request Send to the server:
DEBUG com.intuit.karate - request:
1 > GET url
1 > Accept: */*
1 > Accept-Encoding: gzip,deflate
1 > Content-Type: application/json
1 > Host: scrbmapdk007182:8080
1 > Proxy-Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_141)
1 > user: "myemail"
Response is 502 with along with DNS error
Not sure where im going wrong because it is working via postman .Request send is same as in postman
Read the docs: https://github.com/intuit/karate#configure
Has to be in http: or https: URI form including port number if applicable:
karate.configure('proxy','http://myhost:80');
EDIT: for others landing here, besides the fact that an HTTP proxy may be in the picture - another place where Karate behaves a bit differently than Postman is that Karate does not auto-send an Accept header by default.