Wrong Behavior

29 views
Skip to first unread message

A L

unread,
Mar 1, 2022, 11:29:52 AM3/1/22
to mountebank-discuss
Currently I am trying to use the value of the request of my mountebank script, but for no reason when I try to do a basic substr the script add an space or "\n" and I am sure that's not the normal behavior of javascript, I will let you my script if someone knows how solve this.


"port":8091,
"protocol": "tcp",
"mode": "text",
"numberOfRequests": 1,
"stubs": [
{
"responses": [
{
"is": {
"data": "${GENERATED_KEY}"
},
"behaviors": [
{ "decorate": "(config) => { var generateKey = config.request.data.substr(0, 64) + config.request.data.substr(64, 94) + Array(2).fill(0).map(x => Math.random().toString(36).charAt(2)).join('') + 'AA' + Array(17).fill(0).map(x => Math.random().toString(36).charAt(2)).join(''); config.response.data = config.response.data.replace('${GENERATED_KEY}', generateKey); }" }
]
}
]
}
]
}

The problem it is in the substr method, but if I put that at the end of the script I don't have any problem at all, no add any space, or "\n" but if I put that at the beginning, the result its altered, so... that's all, thank you

Brandon Byars

unread,
Mar 5, 2022, 4:30:54 PM3/5/22
to A L, mountebank-discuss
Hi there,
It's unclear to me what's going wrong too, but it seems to me that you could easily solve it by adding a .trim() function to swallow the newline:

config.response.data = config.response.data.replace('${GENERATED_KEY}', generateKey.trim();

Tanto este mensaje como todos los posibles documentos adjuntos al mismo, son confidenciales y están dirigidos exclusivamente a los destinatarios de los mismos. Por favor, si Usted no es uno de dichos destinatarios, notifíquenos este hecho y elimine el mensaje de su sistema. Queda prohibida la copia, difusión o revelación de su contenido a terceros sin el previo consentimiento por escrito de “SNGULAR.”. En caso contrario, vulnerará la legislación vigente. Sus datos figuran en un fichero automatizado propiedad de “SNGULAR.”. Si desea acceder a sus datos, rectificarlos, cancelarlos u oponerse a su tratamiento, diríjase a “SNGULAR.”, Calle Labastida 1, provincia de Madrid, con Código Postal 28034. Entendiendo por SNGULAR al grupo empresarial encabezado por Singular People S.L. y compuesto por todas sus filiales. Singular People S.L. y todas sus filiales mantienen un compromiso claro con el establecimiento y desarrollo de políticas que integren la igualdad de trato y oportunidades entre todas las personas. Por ello, impulsa medidas para lograr la igualdad efectiva y contribuir a la eliminación de cualquier discriminación, especialmente aquellas directa o indirectamente causadas por razón de género. Antes de imprimir este mensaje, por favor comprueba que es necesario hacerlo. 


The contents of this email, including any attachments, are confidential and are intended only for the person or entity to which it is addressed. If it was not addressed to you and you think you received it in error, please notify the sender and delete it from your computer. The use, copying, or distribution of the contents of this email, or any attachments hereto, to third parties without SNGULAR's consent or approval is strictly prohibited. Failing to comply with this rule could mean that you are violating the applicable laws and regulations. Your data is stored in an automated file owned by "SNGULAR.” If you want to access, modify, cancel or deny the treatment of your data, please contact "SNGULAR,” Calle Labastida 1, Madrid, Postal Code 28034 (Community of Madrid - Spain). SNGULAR is considered as the business group of the parent company Singular People S.L. and all its subsidiaries. Singular People S.L. and its subsidiaries are firmly committed to developing and implementing policies that promote equal rights and opportunities for all. To this end, the company promotes actions to ensure equality and, thus, contribute to eliminating any kind of discrimination, especially those directly or indirectly caused by gender. Please verify if it is necessary before printing this message.

--
You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mountebank-discuss/92c3e42f-69ed-4208-bf55-8dfce08389c4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages