DNS error observed while performing API testing using karate framework [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

Getting 503 error from Karate for API which works fine on Postman or Insomnia [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.

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.

Vue Firebase Verify ID Token CORS issue

I am trying to verify an ID Token using the Firebase Admin SDK as per instructions. My current auth code looks like this (in Vue):
// Auth.vue, inside the firebaseui config callback
signInSuccessWithAuthResult: function(authResult, redirectUrl) {
authResult.user
.getIdToken(/* forceRefresh */ true)
.then(function(idToken) {
// Send token to your backend via HTTPS
// ...
console.log(idToken);
})
.catch(function(error) {
// Handle error
console.log(error);
});
The login works fine and I can get authResult perfectly. However, it seems the function getIdToken is the problem, as I get the following error on my console:
Cross-Origin Request Blocked:
The Same Origin Policy disallows reading the remote resource at
https://securetoken.googleapis.com/v1/token?key=AIzaSyApp5yu051vMJlNLoQ1ngVSd-f2k7Pdavc.
(Reason: CORS request did not succeed).
In my request list, the one hanging is an OPTIONS method, with the following headers:
OPTIONS /v1/token?key=AIzaSyApp5yu051vMJlNLoQ1ngVSd-f2k7Pdavc HTTP/1.1
Host: securetoken.googleapis.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:62.0) Gecko/20100101 Firefox/62.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.8,pt-BR;q=0.5,de;q=0.3
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: POST
Access-Control-Request-Headers: x-client-version
Origin: http://localhost:8080
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
I am not even sure where the problem lies. Is it coming from the Vue side? I am running it in a dev server (by simple yarn serve, vue cli 3). Would the solution be when I run Vue on a production server where I can actually configure cors?
Any light on the matter is extremely welcome...
Thanks!!
Figured it out.
I was calling it in the wrong place. What helped was this thread, which pointed me out to Preflighted Requests which is what the OPTIONS request is:
"preflighted" requests first send an HTTP request by the OPTIONS method to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data.
So I realized I should not be sending this request within my Post request where I got the authorization in the first place. Moving it to another method made it work.