I'm trying to do some basic authorization by using the javascript function (basic-auth.js) here to encode:
function fn(creds) {
var temp = creds.USER_NAME + ':' + creds.PASSWORD;
var Base64 = Java.type('java.util.Base64');
var encoded = Base64.getEncoder().encodeToString(temp.toString().getBytes());
return 'Basic ' + encoded;
}
Here is my authorization feature file:
@tests=auth
Feature: Auth Management
Background:
* url baseUrl
@test=accessToken
Scenario: generate access token
Given path '/oauth2' + '/token'
And header Authorization = call read('basic-auth.js') { username: '#(USER_NAME)', password: '#(PASSWORD)' }
And form field grant_type = 'client_credentials'
When method POST
Then status 200
* def accessToken = response.access_token
I'm trying to call in the username and password from a stored .yml (karate-config-stg.yml) using the format of #(USER_NAME)
isn't pulling in the variable from the config file even through from that same config I'm getting the baseUrl without issue. Any help on this one is very appreciated! this is a new concept I'm trying to learn.
karate-config-stg.yml all fields are deleted for this post, in my local they have the appropriate values for staging:
baseUrl: ''
USER_NAME: ''
PASSWORD: ''