Last active
March 14, 2019 14:22
-
-
Save AntonioArts/7daa9523a8993a79a9cc7196dfbe20cc to your computer and use it in GitHub Desktop.
k6 prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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