如何使用空手道实施基本身份验证?

时间:2018-07-09 11:42:48

标签: karate

1 个答案:

答案 0 :(得分:2)

是的,此JS函数就是您所需要的:

function(creds) {
  var temp = creds.username + ':' + creds.password;
  var Base64 = Java.type('java.util.Base64');
  var encoded = Base64.getEncoder().encodeToString(temp.bytes);
  return 'Basic ' + encoded;
}

然后使用此函数来构建Authorization标头的值:

* header Authorization = call read('basic-auth.js') { username: 'john', password: 'secret' }

在此处参考文档:https://github.com/intuit/karate#http-basic-authentication-example