How to disable encoding while passing a form field in karate - karate

I am using the following code for oauth.
Feature: Verify Generate Token Email api is up and running
Scenario: Verify Generate Token Email api
Given url 'demourl'
And header Content-Type = 'application/x-www-form-urlencoded; charset=utf-8'
And form field grant_type = 'password'
And form field client_id = 'democlientid'
And form field client_secret = 'democlientsecret'
And form field password = 'randompass123'
And form field username = 'hello#someone.com'
When method post
Then status 200
* print response
The username field is getting encoded which results in =>
grant_type=password&client_id=democlientid&client_secret=democlientsecret&password=randompass123&username=hello%40someone.com
The name is getting encoded as "hello%40someone.com" while being passed because of which the api call fails. How do I disable encoding so that "hello#someone.com" is passes.

Karate is doing the right thing, it is most likely you have mis-understood the issue - or you have a bug in your server: https://www.w3schools.com/Tags/ref_urlencode.asp
Anyway if you insist on NOT encoding, you have to provide the request body manually. Use this example as a reference: https://github.com/intuit/karate/commit/58eeec344eb6b4194a7d5aa9bc5b2f0e934372ed

Related

How to retrieve body form-data in key value pair and use it in postman test script

request body form-data
I tried the following but didnot work
pm.request.body.data
pm.request.data
Access this format
pm.request.body.formdata.get("name")
pm.request.body.formdata.get("last_name")
pm.request.body.formdata.get("other_name")
Documentation in here
formdata :PropertyList.<FormParam>
Form data parameters for this request are held in this field.
Type:
PropertyList.<FormParam>
Usage in Tests tab.

Authorization Header and Base64 Encoding in VimeoAPI

I am new to the world of APIs and Auth, and would certainly appreciate any help. I am attempting to authorize and receive a token through the Vimeo API (OAuth2). My question is how to properly set the value of the Authorization Header. (Table below from: https://developer.vimeo.com/api/authentication)
Header
Set value to
Authorization
basic base64_encode(x:y), where x is the client identifier and y is the client secret
In this table is base64_encode plain text that I need to write, or does this denote a function I need to use in my language that converts x:y into Base64? M Language, in my case.
Also, are my clientID and clientSecret ready to put into the header "as-is" or do they themselves need to be converted into Base64 before being used as auth for the token endpoint?
The gist of my confusion is how exactly I should write the authorization header, because I keep getting the error "[invalid_client] A valid client ID must be provided along with any request made to Vimeo's API" when trying to POST to the token endpoint.
Thank you for any help!
The idea that you should use some sort of function to encode your clientID and secret is correct.
If you are using javascript the code might looks something like this
const clientId = 'client_id';
const clientSecret = 'client_secret';
// btoa() is a javascript built-in that base64 encodes a string
const authorizationValue = 'Basic ' + btoa( clientId + ':' + clientSecret );
You can read more about btoa() on Mozilla's documentation website.
https://developer.mozilla.org/en-US/docs/Web/API/btoa

Defining target URL client in java and using that client in karate feature file

In most of the example in the feature file of karate as:
Background:
* url authURL
* path 'token'
* form field grant_type = 'password'
* form field username = 'username'
* form field password = 'password'
* form field client_id = 'appId'
* form field client_secret = 'appSecret'
* form field scope = 'your_App_Scope'
I wanted to write only GET/POST related tests in karate and define this client in Java code and just use that in GET/POST call in karate feature file. Is there any way to do this?
Note: I do not want to replace just URL rather I want to use the whole HTTP client which is defined in java code in karate test file.

Delphi RESTClient Joomla get user token

I am attempting to use TRESTClient/REST Debugger to get the User ID and token from a Joomla website.
The url is as follows:
For the Login API Call Please provide the Username and password in the API request body - https://thesite.com/index.php?app=users&resource=login&option=com_api&format=raw
The request must contain 2 values:
key-> username, value-> exampleUser
key-> password, value-> xyz
I am failing to get the correct response. I am able to get results from other resources from the same website, but this I am only getting an empty body.
You need to change the parameter type of the username and password parameter to BODY instead of GET/POST. This will place them into the request body instead of the URL.

in Karate DSL, is there a way to have redirects perform a POST request instead of a GET request? [duplicate]

This question already has an answer here:
Post method gets converted to GET after redirection
(1 answer)
Closed 2 years ago.
I have the following Karate script that by default has redirects turned on.
Scenario: First Test
Given path 'somePath'
And request ''
And header Content-Type = 'text/html'
And param _csrf = csrf
And param username = 'username'
And param password = 'password'
When method post
Then status 200
The issue is after getting a 302 from the API, the next request automatically submits a GET request. I would like it to submit a POST request instead.
in cURL, there is an existing parameter that allows users to do that. see below.
--post302 Do not switch to GET after following a 302
is there anyway to do that in Karate DSL?
Yes please read the docs for configure folowRedirects. There is also an example on how to read the Location response header to manually make the request you want.
Scenario: get redirects can be disabled
* configure followRedirects = false
Given path 'redirect'
When method get
Then status 302
And match header Location == demoBaseUrl + '/search'
* def location = responseHeaders['Location'][0]
Given url location