Skip to content

Commit

Permalink
Fix wrk scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Serious-senpai committed Oct 25, 2024
1 parent e2d1c47 commit 19f0740
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 40 deletions.
36 changes: 14 additions & 22 deletions scripts/wrk/api/v1/admin/login.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
local utils = require("utils")
local pre_request

local user_agent = utils.random_user_agent()
print("User-Agent: " .. user_agent)

wrk.scheme = "http"
wrk.host = "localhost"
wrk.port = 8000
wrk.method = "POST"
wrk.path = "/api/v1/admin/login"
wrk.headers = {
["Username"] = "incorrect",
["Password"] = "incorrect",
["User-Agent"] = user_agent,
}
wrk.body = nil

local request

function init(args)
-- Pre-generate the request
request = string.format("%s %s HTTP/1.1\r\n", wrk.method, wrk.path) ..
"Host: localhost:8000\r\n" ..
payload = "grant_type=password&username=admin&password=NgaiLongGey"
pre_request = "POST /api/v1/admin/login HTTP/1.1\r\n" ..
"Accept: application/json\r\n" ..
"Connection: keep-alive\r\n" ..
string.format("Username: %s\r\n", wrk.headers["username"]) ..
string.format("Password: %s\r\n", wrk.headers["password"]) ..
"\r\n"
string.format("Content-Length: %d\r\n", string.len(payload)) ..
"Content-Type: application/x-www-form-urlencoded\r\n" ..
"Host: localhost:8000\r\n" ..
"Origin: http://localhost:8000\r\n" ..
string.format("User-Agent: %s\r\n", utils.random_user_agent()) ..
"\r\n" ..
payload

print(string.format("Sending requests:\n%s\n", pre_request))

response = nil
end

function request()
return request
return pre_request
end
27 changes: 9 additions & 18 deletions scripts/wrk/root.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
local utils = require("utils")
local pre_request

local user_agent = utils.random_user_agent()
print("User-Agent: " .. user_agent)

wrk.scheme = "http"
wrk.host = "localhost"
wrk.port = 8000
wrk.method = "GET"
wrk.path = "/"
wrk.headers = {
["User-Agent"] = user_agent,
}
wrk.body = nil

local request

function init(args)
-- Pre-generate the request
-- Usage of \r\n: RFC2616 explicitly stated that header lines must end with a CRLF sequence
request = string.format("%s %s HTTP/1.1\r\n", wrk.method, wrk.path) ..
"Host: localhost:8000\r\n" ..
pre_request = "GET / HTTP/1.1\r\n" ..
"Accept: application/json\r\n" ..
"Connection: keep-alive\r\n" ..
"Host: localhost:8000\r\n" ..
"Origin: http://localhost:8000\r\n" ..
string.format("User-Agent: %s\r\n", utils.random_user_agent()) ..
"\r\n"

print(string.format("Sending requests:\n%s\n", pre_request))

response = nil
end

function request()
return request
return pre_request
end

0 comments on commit 19f0740

Please sign in to comment.