From b0d205c4dad353e725b80bb7795d2e8b8927acb7 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 29 Mar 2023 13:36:23 +0200 Subject: [PATCH] refs #5464 fix: utiliza una sola cookie --- back/methods/osticket/closeTicket.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/back/methods/osticket/closeTicket.js b/back/methods/osticket/closeTicket.js index 32b369c8d..aa827bbbb 100644 --- a/back/methods/osticket/closeTicket.js +++ b/back/methods/osticket/closeTicket.js @@ -69,15 +69,15 @@ module.exports = Self => { const result = response.headers.get('set-cookie'); const [firtHeader] = result.split(' '); - const firtCookie = firtHeader.substring(0, firtHeader.length - 1); + const cookie = firtHeader.substring(0, firtHeader.length - 1); const body = await response.text(); const dom = new jsdom.JSDOM(body); const token = dom.window.document.querySelector('[name="__CSRFToken__"]').value; - await login(token, firtCookie); + await login(token, cookie); } - async function login(token, firtCookie) { + async function login(token, cookie) { const data = { __CSRFToken__: token, do: 'scplogin', @@ -90,21 +90,18 @@ module.exports = Self => { body: new URLSearchParams(data), headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', - 'Cookie': firtCookie + 'Cookie': cookie } }; - const response = await fetch(ostUri, params); - const result = response.headers.get('set-cookie'); - const [firtHeader] = result.split(' '); - const secondCookie = firtHeader.substring(0, firtHeader.length - 1); + await fetch(ostUri, params); - await close(token, secondCookie); + await close(token, cookie); } - async function close(token, secondCookie) { + async function close(token, cookie) { for (const ticketId of ticketsId) { try { - const lock = await getLockCode(token, secondCookie, ticketId); + const lock = await getLockCode(token, cookie, ticketId); if (!lock.code) { let error = `Can't get lock code`; if (lock.msg) error += `: ${lock.msg}`; @@ -127,7 +124,7 @@ module.exports = Self => { method: 'POST', body: form, headers: { - 'Cookie': secondCookie + 'Cookie': cookie } }; await fetch(ostUri, params); @@ -139,13 +136,13 @@ module.exports = Self => { } } - async function getLockCode(token, secondCookie, ticketId) { + async function getLockCode(token, cookie, ticketId) { const ostUri = `${config.host}/ajax.php/lock/ticket/${ticketId}`; const params = { method: 'POST', headers: { 'X-CSRFToken': token, - 'Cookie': secondCookie + 'Cookie': cookie } }; const response = await fetch(ostUri, params);