2021-07-01 13:53:13 +00:00
|
|
|
import { sleep, check, group } from "k6";
|
|
|
|
import http from "k6/http";
|
2021-07-13 14:54:23 +00:00
|
|
|
import { Trend } from "k6/metrics";
|
2021-07-01 13:53:13 +00:00
|
|
|
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";
|
|
|
|
import {
|
2021-07-13 14:54:23 +00:00
|
|
|
base_url,
|
|
|
|
admin_username,
|
|
|
|
admin_password,
|
|
|
|
think_time_min,
|
|
|
|
think_time_max,
|
|
|
|
} from "../../config.js";
|
2021-07-01 13:53:13 +00:00
|
|
|
import {
|
2021-07-13 14:54:23 +00:00
|
|
|
htmlRequestHeader,
|
|
|
|
commonRequestHeaders,
|
|
|
|
commonGetRequestHeaders,
|
|
|
|
commonNonStandardHeaders,
|
|
|
|
} from "../../headers.js";
|
2021-07-01 13:53:13 +00:00
|
|
|
|
2021-07-13 14:54:23 +00:00
|
|
|
// Custom metrics to add to standard results output.
|
|
|
|
let wpLoginTrend = new Trend("wc_get_wp_login");
|
|
|
|
let wpLoginWPAdminTrend = new Trend("wc_post_wp_login");
|
2021-07-01 13:53:13 +00:00
|
|
|
|
2021-07-13 14:54:23 +00:00
|
|
|
export function wpLogin() {
|
|
|
|
let response;
|
|
|
|
let testcookie;
|
2021-07-01 13:53:13 +00:00
|
|
|
|
2021-07-13 14:54:23 +00:00
|
|
|
group("Login Page", function () {
|
2021-07-30 19:38:31 +00:00
|
|
|
var requestHeaders = Object.assign({},
|
2021-07-13 14:54:23 +00:00
|
|
|
htmlRequestHeader,
|
|
|
|
commonRequestHeaders,
|
|
|
|
commonGetRequestHeaders,
|
|
|
|
commonNonStandardHeaders
|
|
|
|
);
|
2021-07-01 13:53:13 +00:00
|
|
|
|
2021-07-13 14:54:23 +00:00
|
|
|
response = http.get(`${base_url}/wp-login.php`, {
|
|
|
|
headers: requestHeaders,
|
|
|
|
});
|
|
|
|
wpLoginTrend.add(response.timings.duration);
|
|
|
|
check(response, {
|
|
|
|
"is status 200": (r) => r.status === 200,
|
2021-07-30 19:38:31 +00:00
|
|
|
"body contains: 'Log in' title": (response) =>
|
2021-07-13 14:54:23 +00:00
|
|
|
response.body.includes("<title>Log In"),
|
|
|
|
});
|
2021-07-01 13:53:13 +00:00
|
|
|
|
2021-07-13 14:54:23 +00:00
|
|
|
// Correlate cookie value for use in subsequent requests.
|
|
|
|
testcookie = response
|
|
|
|
.html()
|
|
|
|
.find("input[name=testcookie]")
|
|
|
|
.first()
|
|
|
|
.attr("value");
|
|
|
|
});
|
2021-07-01 13:53:13 +00:00
|
|
|
|
2021-07-13 14:54:23 +00:00
|
|
|
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
|
2021-07-01 13:53:13 +00:00
|
|
|
|
2021-07-13 14:54:23 +00:00
|
|
|
group("Login to WP Admin", function () {
|
2021-07-30 19:38:31 +00:00
|
|
|
var requestHeaders = Object.assign({},
|
2021-07-13 14:54:23 +00:00
|
|
|
htmlRequestHeader,
|
|
|
|
commonRequestHeaders,
|
|
|
|
commonGetRequestHeaders,
|
|
|
|
commonNonStandardHeaders
|
|
|
|
);
|
2021-07-01 13:53:13 +00:00
|
|
|
|
2021-07-13 14:54:23 +00:00
|
|
|
response = http.post(
|
|
|
|
`${base_url}/wp-login.php`,
|
|
|
|
{
|
|
|
|
log: `${admin_username}`,
|
|
|
|
pwd: `${admin_password}`,
|
|
|
|
"wp-submit": "Log%20In",
|
|
|
|
redirect_to: `${base_url}/wp-admin`,
|
|
|
|
testcookie: `${testcookie}`,
|
|
|
|
},
|
|
|
|
{
|
2021-07-30 19:38:31 +00:00
|
|
|
headers: requestHeaders,
|
2021-07-13 14:54:23 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
wpLoginWPAdminTrend.add(response.timings.duration);
|
|
|
|
check(response, {
|
|
|
|
"is status 200": (r) => r.status === 200,
|
2021-07-30 19:38:31 +00:00
|
|
|
"body contains: wp-admin 'Dashboard' header": (response) =>
|
2021-07-13 14:54:23 +00:00
|
|
|
response.body.includes("<h1>Dashboard</h1>"),
|
|
|
|
});
|
|
|
|
});
|
2021-07-01 13:53:13 +00:00
|
|
|
|
2021-07-13 14:54:23 +00:00
|
|
|
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
|
|
|
|
}
|
2021-07-01 13:53:13 +00:00
|
|
|
|
|
|
|
export default function () {
|
2021-07-13 14:54:23 +00:00
|
|
|
wpLogin();
|
|
|
|
}
|