To build a k6
binary with this extension, first ensure you have the prerequisites:
- Go toolchain
- Git
Then:
- Download
xk6
:
$ go install go.k6.io/xk6/cmd/xk6@latest
- Build the binary:
$ xk6 build --with github.com/AckeeCZ/xk6-google-iap
import googleIap from 'k6/x/googleIap';
import { check } from 'k6';
import http from 'k6/http';
const client_id = __ENV.CLIENT_ID;
const sa_key = __ENV.SA_KEY;
// URL protected by Google IAP
const url = __ENV.TARGET_URL;
export default function () {
const token = googleIap.getToken(client_id, sa_key);
const params = {
headers: {
'Proxy-Authorization': `Bearer ${token}`,
},
};
const response = http.get(url, params);
console.log(response.url)
check(response, { "URL doesn't begin with accounts.google.com": response => !response.url.startsWith("https://accounts.google.com") })
}
Run with
./k6 -e SA_KEY="SERVICE_ACCOUNT_KEY" -e CLIENT_ID="OAUTH_CLIENT_ID" -e TARGET_URL="YOUR_WEBSITE_URL" script.js
If you are using Typescript in your K6 tests, you can use this module for type hints:
declare module "k6/x/googleIap" {
function getToken(clientId: string, serviceAccountKey: string): string
}