-- A plugin for the session tests. Its add_to_cart reads what to do from the -- URL's path. return { name = "shop", session_warning = "Automated logins can lock the account.", parse = function(doc, url) return { available = true } end, login = function(ctx, account) local page = ctx:get(account.site .. "signin") local code = ctx:prompt("code for " .. account.username, true) page = ctx:post(account.site .. "signin", { form = { user = account.username, password = account.password, code = code }, referer = page.url, }) if page.doc:text("#result") ~= "welcome" then error("refused: " .. tostring(page.doc:text("#result")), 0) end if ctx:cookies().session ~= "yes" then error("no session cookie", 0) end end, add_to_cart = function(ctx, url) local what = url:match("/(%a+)$") local site = ctx.account.site if ctx.account.password then error("ctx.account has the password", 0) end if what == "signedout" then return false end if what == "nonsense" then return "yes" end if what == "click" then local page = ctx:click(site .. "item", "#add") return page.headers["x-cart"] == "1", site .. "cart" end local page = ctx:post(site .. "cart", { form = { id = "X", quantity = 1 }, headers = { ["X-Test"] = "yes" } }) return page.status == 200 and page.headers["x-cart"] == "1", site .. "cart" end, }