Skip to content

AckeeCZ/xk6-google-iap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xk6-googleIap

⚠️This is proof of concept

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Download xk6:
$ go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
$ xk6 build --with github.com/AckeeCZ/xk6-google-iap

Example:

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

Typescript

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
}

About

K6 extension for providing Google Auth token

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published