Authentication TestCafe如何对IAP安全应用程序进行身份验证
有人可以指导TestCafe如何通过IAP安全服务/应用的身份验证吗?我试着阅读这本指南,但对我来说似乎有点复杂。如果以前有人这样做过,如果你能分享,那就太好了。提前感谢您。我们已经通过在Testcafe中使用和扩展实现了它Authentication TestCafe如何对IAP安全应用程序进行身份验证,authentication,testing,automated-tests,testcafe,identity-aware-proxy,Authentication,Testing,Automated Tests,Testcafe,Identity Aware Proxy,有人可以指导TestCafe如何通过IAP安全服务/应用的身份验证吗?我试着阅读这本指南,但对我来说似乎有点复杂。如果以前有人这样做过,如果你能分享,那就太好了。提前感谢您。我们已经通过在Testcafe中使用和扩展实现了它 您需要具有Google IAP凭据(您的应用程序中的步骤1和步骤2) )获取JWT令牌 获得JWT令牌后,添加它 作为对应用程序执行的每个请求的授权标头 (通过扩展实现) 辅助函数的代码大致如下所示: import { RequestHook } from 'testc
- 您需要具有Google IAP凭据(您的应用程序中的步骤1和步骤2) )获取JWT令牌
- 获得JWT令牌后,添加它 作为对应用程序执行的每个请求的授权标头 (通过扩展实现)
import { RequestHook } from 'testcafe';
import { GoogleAuth } from 'google-auth-library';
export class GoogleIapJWTAuthorization extends RequestHook {
constructor () {
// No URL filtering applied to this hook
// so it will be used for all requests.
super();
const auth = new GoogleAuth({
credentials: serviceGoogleAccount
});
console.log('Google Authentication');
console.log(`Loaded Service Account ${GoogleAccount.client_email}`);
auth.getClient()
.then(client => client.fetchIdToken(`${GoogleAccount.targetAudience}`))
.then(token => {
console.log(`Successfully authenticated with Identity Aware Proxy. Id Token: ${token}`);
this._token = token;
return token;
})
.catch(err => {
console.log(`Identity Aware Proxy Authentication Failed. Id Token: ${token}`);
console.log(JSON.stringify(err));
process.exitCode = 1;
});
}
getGoogleJwtToken() {
return this._token;
}
onRequest (e) {
//Authorization header for authentication into Google Auth IAP
e.requestOptions.headers['Authorization']= `Bearer ${this._token}`;
}
onResponse (e) {
// This method must also be overridden,
// but you can leave it blank.
}
}
TestCafe在Node.js上运行测试。因此,您可以使用与Node.js应用程序相同的方式访问任何安全服务。请更详细地描述您的场景。您需要在测试中执行哪些操作?您需要从用户帐户或服务帐户进行身份验证吗?