Skip to content

Instantly share code, notes, and snippets.

@AntonioArts
Last active March 14, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntonioArts/7daa9523a8993a79a9cc7196dfbe20cc to your computer and use it in GitHub Desktop.
Save AntonioArts/7daa9523a8993a79a9cc7196dfbe20cc to your computer and use it in GitHub Desktop.
k6 prototype
import http from "k6/http"
import jwt from "./node-jsonwebtoken/jsonwebtoken.js"
const payloadTemplate = {
iss: 'barong',
sub: 'session',
aud: 'peatio',
role: 'member',
state: 'active',
level: 3,
}
const side = ["buy", "sell"]
export default function() {
const generatePayload = () => {
const ts = parseInt(Date.now() / 1000)
const rand_num = Math.round(Math.random() * 21) // MAGIC_CONST
return {
iat: ts,
exp: ts + 5000,
email: `user${rand_num}@gmail.com`,
uid: `ID00000000${rand_num}`,
market: 'ethusd',
side: side[Math.floor(Math.random()*side.length)],
volume: 1,
price: 1,
}
}
const combineJWTPayload = () => Object.assign({}, payloadTemplate, generatePayload())
const encodeJwt = () => jwt.sign(combineJWTPayload(), __ENV.K6_PRIVATE_KEY, {algorithm: 'RS256'})
var url = "http://localhost:8000/api/v2/public/version"
var payload = JSON.stringify(generatePayload())
var params = {
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${encodeJwt()}`,
}
}
http.post(url, payload, params)
};
$ K6_PRIVATE_KEY=$(cat path_to_barong_key) k6 run index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment