Created
March 25, 2019 09:30
-
-
Save robingustafsson/6bd1ed07009e4ed9fb73ffedfbdfc38c to your computer and use it in GitHub Desktop.
Postman-to-k6 PR review: OAuth1 auth
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
{ | |
"info": { | |
"_postman_id": "c0b1dbfb-78eb-4b1d-9f64-4b2e881d90ec", | |
"name": "Postman-to-k6: OAuth", | |
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | |
}, | |
"item": [ | |
{ | |
"name": "OAuth1", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"id": "2f5fac63-f3d7-476b-b1fe-0c5df8fff1bc", | |
"exec": [ | |
"pm.test(\"OAuth1 body is correct\", function () {", | |
" pm.response.to.have.body(\"method=foo&bar=baz\");", | |
"});" | |
], | |
"type": "text/javascript" | |
} | |
} | |
], | |
"request": { | |
"auth": { | |
"type": "oauth1", | |
"oauth1": [ | |
{ | |
"key": "tokenSecret", | |
"value": "accesssecret", | |
"type": "string" | |
}, | |
{ | |
"key": "token", | |
"value": "accesskey", | |
"type": "string" | |
}, | |
{ | |
"key": "consumerSecret", | |
"value": "secret", | |
"type": "string" | |
}, | |
{ | |
"key": "consumerKey", | |
"value": "key", | |
"type": "string" | |
}, | |
{ | |
"key": "signatureMethod", | |
"value": "HMAC-SHA1", | |
"type": "string" | |
}, | |
{ | |
"key": "version", | |
"value": "1.0", | |
"type": "string" | |
}, | |
{ | |
"key": "addParamsToHeader", | |
"value": false, | |
"type": "boolean" | |
}, | |
{ | |
"key": "addEmptyParamsToSign", | |
"value": false, | |
"type": "boolean" | |
} | |
] | |
}, | |
"method": "GET", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "" | |
}, | |
"url": { | |
"raw": "http://oauthbin.com/v1/echo?method=foo&bar=baz", | |
"protocol": "http", | |
"host": [ | |
"oauthbin", | |
"com" | |
], | |
"path": [ | |
"v1", | |
"echo" | |
], | |
"query": [ | |
{ | |
"key": "method", | |
"value": "foo" | |
}, | |
{ | |
"key": "bar", | |
"value": "baz" | |
} | |
] | |
} | |
}, | |
"response": [] | |
} | |
] | |
} |
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
// Auto-generated by the Load Impact converter | |
import "./libs/shim/core.js"; | |
import OAuth from "./libs/oauth-1.0a.js"; | |
import { hmac } from "k6/crypto"; | |
export let options = { maxRedirects: 4 }; | |
const Request = Symbol.for("request"); | |
export default function() { | |
postman[Request]({ | |
name: "OAuth1 Copy", | |
method: "GET", | |
address: "http://oauthbin.com/v1/echo?method=foo&bar=baz", | |
post(response) { | |
pm.test("OAuth1 body is correct", function() { | |
pm.response.to.have.body("method=foo&bar=baz"); | |
}); | |
}, | |
auth(config, Var) { | |
const options = { | |
consumer: { | |
key: "key", | |
secret: "secret" | |
}, | |
signature_method: "HMAC-SHA1", | |
hash_function(data, key) { | |
return hmac("sha1", key, data, "base64"); | |
}, | |
version: "1.0" | |
}; | |
const request = { | |
method: config.method, | |
url: config.address | |
}; | |
const token = { | |
key: "accesskey", | |
secret: "accesssecret" | |
}; | |
const oauth = OAuth(options); | |
const auth = oauth.authorize(request, token); | |
Object.assign(config.data, auth); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment