Comments (7)
Hi @pfunk1978
Normally the postman-to-k6 does some smart detection and insert the necessary libs, including the crypto-js.js
.
Could you share your Postman collection (or simplified version of it), with the crypto-js usage included? That way we can review the output of the conversion and improve where necessary.
from postman-to-k6.
Hi @thim81
as requested
-$ cat outs.js
// Auto-generated by the postman-to-k6 converter
import "./libs/shim/core.js";
import "./libs/shim/expect.js";
import { group } from "k6";
import * as CryptoJS from "./libs/crypto-js.js" // imported by me
export let options = { maxRedirects: 4 };
const Pre = Symbol.for("pre");
const Request = Symbol.for("request");
postman[Symbol.for("initial")]({
options,
collection: {
JWT_TOKEN: "",
APPROVER_TOKEN: "",
UPLOADER_TOKEN: ""
},
environment: {
host: "10.0.5.49:8081",
v7: "kmes/v7",
v6: "kmes/v6",
jwtIssuer: redacted,
hmacKey: redacted,
testUser: "testUser"
}
});
export default function() {
postman[Pre].push(() => {
function make_payload(name) {
let payload = {
iss: pm.environment.get("jwtIssuer"),
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000 + 100000),
sub: name
};
return payload;
}
function base64url(source) {
let encodedSource = CryptoJS.enc.Base64.stringify(source)
.replace(/=+$/, "")
.replace(/\+/g, "-")
.replace(/\//g, "_");
return encodedSource;
}
function build_token(payload) {
let hmac_key = pm.environment.get("hmacKey");
let header = {
alg: "HS256",
typ: "JWT"
};
let b64_header = base64url(
CryptoJS.enc.Utf8.parse(JSON.stringify(header))
);
let b64_data = base64url(
CryptoJS.enc.Utf8.parse(JSON.stringify(payload))
);
let message = b64_header + "." + b64_data;
let b64_signature = base64url(CryptoJS.HmacSHA256(message, hmac_key));
let jwt_token = [b64_header, b64_data, b64_signature].join(".");
return jwt_token;
}
function build_token_from_name(name) {
let payload = make_payload(name);
let token = build_token(payload);
return token;
}
let user = pm.environment.get("testUser");
pm.collectionVariables.set("JWT_TOKEN", build_token_from_name(user));
pm.collectionVariables.set(
"APPROVER_TOKEN",
build_token_from_name("approver")
);
pm.collectionVariables.set(
"UPLOADER_TOKEN",
build_token_from_name("uploader")
);
});
group("SymmetricKeyGeneration", function() {
postman[Request]({
...
from postman-to-k6.
Hi @pfunk1978, I was refering to the Postman collection. But I think I can build a Postman collection based on your output.
from postman-to-k6.
hi @pfunk1978
In the past you had to use "require" statements to use libraries like "crypto-js".
https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-external-libraries
The postman-to-k6 convertor, scanned for these "require" statements to trigger the automatic loading of the libraries used.
It seems that these Postman supports these libraries without the need of using "require", which means that the postman-to-k6 converter is not aware of these libraries being used.
I'll do some exploration to see if the convertor can detect the usage of libraries in another way.
from postman-to-k6.
hi @pfunk1978
We have enhanced support for the commonly supported libs: crypto, cheerio, lodash, xml2json.
The PR will be merged in and this enhancement will be part of the next release.
from postman-to-k6.
Closing the issue, since the latest postman-to-k6 version (1.8.5) contains this enhancement.
from postman-to-k6.
ty
from postman-to-k6.
Related Issues (20)
- Many converted tests have "::" in the request url HOT 2
- API Key Auth not correctly being assigned to header
- API Key Auth not correctly being assigned to header HOT 3
- Question: Hi, its possible for generate postman collection for separate output to multi endpoint file k6? HOT 3
- oauth2 pkce auth code flow support? HOT 2
- Question: how can I repeat a request depending on the response body content? HOT 1
- CI - docker build (and publish) failing HOT 3
- postman variables that reference broader scoped postman variables are not replaced HOT 10
- Support Alternate Environments Format HOT 6
- Post request incorrectly exported from Postman to k6 HOT 4
- Common for collection tests not running when no tests in API method HOT 1
- How to pass oauth credentials HOT 3
- The "path" argument must be of type string. Received type object HOT 5
- Can not use atob function because of different built-in libraries HOT 2
- Help wanted - Convert Ava test to Jest test
- Qustion - How to convert multiple postman collections at once..? HOT 1
- Won't run: Form item missing type (file) HOT 3
- Error: Cannot find module 'prettier' HOT 5
- Requests wrongly reusing headers from previous requests? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from postman-to-k6.