Last active
February 24, 2023 10:25
-
-
Save jasper07/300c27da99ccb53327fcbbeb7d1b181a to your computer and use it in GitHub Desktop.
This file contains 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 { check, group, sleep } from "k6"; | |
import { Counter, Rate, Trend } from "k6/metrics"; | |
const URL_LAUNCHPAD = 'https://secondphase.launchpad.cfapps.ap10.hana.ondemand.com'; | |
// 1. init code | |
export let options = { | |
// stages: [ | |
// { target: 200, duration: "1m" }, | |
// { target: 200, duration: "3m" }, | |
// { target: 0, duration: "1m" } | |
// ], | |
// thresholds: { | |
// "http_req_duration": ["p(95)<500"], | |
// "http_req_duration{staticAsset:yes}": ["p(95)<100"], | |
// "check_failure_rate": ["rate<0.3"] | |
// }, | |
// ext: { | |
// loadimpact: { | |
// insights: { | |
// disabledSets: ['best_practice', 'health'], | |
// } | |
// } | |
// } | |
}; | |
// 2. setup vu | |
export function setup() { | |
console.log("setup - btp launchpad authentication - default IDP"); | |
let vuJar = http.cookieJar(); | |
//const loginData = JSON.parse(open("./users.json")); | |
//let credentials = loginData.users[Math.floor(Math.random() * 10)]; | |
const credentials = { | |
username: 'john.patterson_at_secondphase.com.au', | |
password: '<<Password>>' | |
} | |
console.log("url 1 " + URL_LAUNCHPAD) //https://secondphase.launchpad.cfapps.ap10.hana.ondemand.com | |
let res = http.get(URL_LAUNCHPAD); | |
// extract values from the javascript in response which would normally set needed cookies | |
let [groupinput, signature, redirect] = /signature=(.*?);path=\/;Secure;SameSite=None;";location="(.*)"/.exec(res.body); | |
check(res, { | |
"has value 'signature'": (r) => signature.length > 0, | |
"has value 'redirect '": (r) => redirect.length > 0 | |
}); | |
// set cookies so the auth remembers the location to goto at the end of saml oauth dance | |
vuJar.set(URL_LAUNCHPAD, 'signature', signature); | |
vuJar.set(URL_LAUNCHPAD, 'fragmentAfterLogin', ''); | |
vuJar.set(URL_LAUNCHPAD, 'locationAfterLogin', '%2Fsite'); //this got me good | |
console.log("url 2 " + redirect) // https://secondphase.authentication.ap10.hana.ondemand.com/oauth/authorize?response_type=code.. | |
res = http.get(redirect); | |
console.log("url 3 " + res.url) //https://secondphase.authentication.ap10.hana.ondemand.com/login | |
// get redirect from meta tag | |
redirect = decodeURI(res.html().find('meta[name=redirect]').attr('content')); | |
console.log("url 4 " + redirect) //https://accounts.sap.com/oauth2/authorize?client_id=.... | |
res = http.get(redirect); | |
console.log("url 5 " + res.url) //https://accounts.sap.com/saml2/idp/sso?sp=uaa | |
res = res.submitForm(); | |
console.log("url 6 " + res.url) //https://accounts.sap.com/saml2/idp/sso | |
res = res.submitForm({ | |
fields: { j_username: credentials.username, j_password: credentials.password } | |
}); | |
console.log("url 7 " + res.url) //https://secondphase.launchpad.cfapps.ap10.hana.ondemand.com/site | |
check(res, { | |
"status is 200'": (r) => res.status === 200 | |
}); | |
// share this users VCAP and JSESSION cookies for launchpad only | |
return vuJar.cookiesForURL(res.url); | |
} | |
// 3. virtual user tests | |
export default function main(cookiesForURL) { | |
let vuJar = http.cookieJar(); | |
for (const property in cookiesForURL) { | |
vuJar.set(URL_LAUNCHPAD, property, cookiesForURL[property]); | |
} | |
// use har converter or browser recorder to capture tests based on actual user input | |
// a nice feature for generating tests from swagger / openai also | |
group('inital load of sflight app', () => { | |
const processorApp = `${URL_LAUNCHPAD}/0fa46d3c-d474-4562-9139-2ad535d3015c.sapfecapsflight.sapfecaptravel/~131222090331+0000~/processor/`; | |
console.log('inital load of sflight app') | |
// get metadata | |
let res = http.get(`${processorApp}/$metadata?sap-language=EN`); | |
/// initial get | |
res = http.get(`${processorApp}/Travel?$count=true&$skip=0&$top=30`); | |
//console.log(res.body) | |
}); | |
} | |
// 4. teardown code | |
export function teardown() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment