How to deal with hashed js and css in gatling? - javascript

I am trying to create a scenario that will work every time but I do not know how to deal with the uniquely hashed javascript and CSS. I could not find any answer in the documentation about that.
What I want specifically is the ability to pass a regex into my get but that is not possible since it only takes a string.
.get("/dist/precache-manifest.3efd6185a8d8559962673d45aed7ae98.js")
.headers(headers_0)
I expect a way to be able to somehow get the URL with a regex and then use it in my get above. Is there a way to do that in a Gatling scenario.

I found a way but its a hack and it takes a lot of time I am answering this because someone might want to use this way. However this could be considered a bug.
.get("").queryParam("", _ =>regex("""\/dist\/precache-manifest.[A-Za-z0-9]+.js"""))
.headers(headers_0),

Related

How to remove unwanted namespaces from xmlns in Node.js?

First, I want to start off that I am really new with stackoverflow. I'm normally a viewer and this is my first time to ask here. Second, please do excuse me if there are terminologies, which I might later use incorrectly or if I am asking in the wrong place. Lastly, I would appreciate it if everyone would use less, or possibly, no negative comments or statements, and if there are less links (to answer my question) and instead more explanation.
So, I've been working on a system. However I'm having trouble with giving request to a wsdl. Normally, I get enough namespaces for me to provide the needed information to get the proper response. However, in my case with this specific wsdl, I'm getting a lot of namespaces. I've tried using soapUI to see if I would get a response, but the problem here is that, it works if I remove enough number of namespaces.
Here is a sample:
<qr2:Envelope
xmlns:qr1="http://qr1/sample"
xmlns:qr2="http://qr2/sample"
xmlns:qr3="http://qr3/sample"
xmlns:qr4="http://qr4/sample"
xmlns:qr5="http://qr5/sample"
xmlns:qr6="http://qr6/sample">
xmlns:qr7="http://qr7/sample">
xmlns:qr8="http://qr8/sample">
xmlns:qr9="http://qr9/sample">
xmlns:qr10="http://qr10/sample">
xmlns:qr11="http://qr11/sample">
<qr2:Header>
</qr2:Header>
<qr2:Body>
</qr2:Body>
</qr2:Envelope>
What I want to happen is to lessen the number of namespaces. In my sample above, instead of getting eleven namespaces, I want it to have, say five, as so:
<qr2:Envelope
xmlns:qr1="http://qr1/sample"
xmlns:qr2="http://qr2/sample"
xmlns:qr3="http://qr3/sample"
xmlns:qr4="http://qr4/sample"
xmlns:qr5="http://qr5/sample">
<qr2:Header>
</qr2:Header>
<qr2:Body>
</qr2:Body>
</qr2:Envelope>
Is there a way for me to do this using node.js?
I'm already at this point of my code:
soap.createClient(https://sampleLinkOf.wsdl, wsdlOptions, function(err, client) {
}
I'd appreciate an answer instead of a workaround (deleting files, downloading files, etc).

Is there a way to decode html entities using javascript without there being a document or jQuery

I'm working in a system where there is no document and no jQuery, but
I do have to present html entities in an understandable way. So the trick of putting the string in an element and then taking the .text() won't work.
I need a pure JavaScript solution. The system isn't reachable from the outside, there is no user-input so security is not really an issue.
Thanks for any help, I'm out of ideas (not that I had to many to begin with)...
Perhaps I should clarify, what I am looking for is a function (or pointers to get me pointing in the right direction) which is able to translate a string with substrings that should translate to characters. So it should be able to translate "blah < blahblah" into "blah < blahblah".
There are no additional frameworks I can use other than pure javascript.
UPDATE:
I've got the html4 part working, not extremely difficult, but I have been busy with other things. Here's the fiddle:html4 entities to characters.
You could have done the same with a dictionary with just the characters already in there, but I didn't feel like making such a dictionary. The function is fairly simple but I guess it could do with some refactoring, can't really be bothered at the moment...
This function exists in PHP (htmlspecialchars_decode). As such, you'll find a javascript port from PHPJS. This is based on a very established codebase, and should be better than rolling something on your own.
Edit / Add:
Flub on my part. I didn't read the entities part properly. You want the equiv of html_entity_decode:
http://phpjs.org/functions/html_entity_decode/
Assuming you are using nodejs, cheerio is exactly what you need. I have used it myself a couple of times with great success for off-browser testing of HTML structures returned from servers.
https://github.com/cheeriojs/cheerio
The most awesome part is that it uses jQuery API.

Error detection algorithm for a URL

I was wondering about some possible ideas on how I can implement an error detection algorithm for a URL. My url can work as follows:
http://changes.html?Type=Production&Item=Tires&Type=Winter
My Url can have the following forms:
http://changes.html?Type=Production //which gets you to the base page
http://changes.html?Type=Production&Item=Tires //which gives you all the tire options
http://changes.html?Type=Production&Item=Tires&Type=Winter //which gives you a specific tire
My question here is that say I spelled Type=Production wrong in a way such that I spelled it as Tzxpe=Poductaion then I may think of having a default page. Also if say everything is correct until Type such that you have the following URL:
http://changes.html?Type=Production&Item=Tires&TZAe=Wter then I am thinking of just cutting off the string at Tires until where its correct and programming a page re-direct to that working part. My solutions seem a bit odd and inefficient. Is there a better way to perhaps have the URL fix itself, or yet even a better implementation of my idea, or just a completely different way of approaching this problem? Error checking is a must for this project so just receiving a bad url message is not going to cut it!
Maybe I am misunderstanding your question but what you could do would be to split the URL you receive on the back end on ? = and & and then check the values for Type against possible correct values (an enum class or just an array of predefined possibilities) and the same with Item. This is dependent on how you are dealing with your service calls though.
I don't know that regex is entirely a good idea. You are looking to make sure things are spelled right which doesn't really fit regex in my experience.

Reducing Query string size of PHP form [duplicate]

This question already has answers here:
How to compress/decompress a long query string in PHP?
(9 answers)
Closed 8 years ago.
I current have a URL like this
http://blahblah.com/process.php?q=[HUGEEEEEEEEEEEEEEEEEEEEEEEE STRING of 5000 chars]
My goal is to convert this something like
http://blahblah.com/process.php?q=[less charcters]
The first question:
How do I perform a function (encryption function for instance) on my GET variables before it is sent to the action page?
I've seen many questions asked with a similar topic.
The second question:
Assuming, I can do the above by some means (maybe by jQuery/JavaScript or something). How do I compress in the index.php page and decompress in the process.php page?
My attempt:
Searching for functions with fixed lengths:
I've looked at some encryptions that maintain the string size for ex. md5() gives a standard length that is short and tidy even for an extremely huge string. But unfortunately md5 cannot be decoded easily. Is there any other such function that I decode and which has a fixed length? If so, I could use that assuming I know a way to do Step 1.
EDIT: I write a request not to mark as a duplicate of that question and a question which hasn't been answered have specifically been asked again.. Please read #Jeremy 's comments, he was following this post.
I personally think it is best to use POST to send the data to the page. I am pretty much sure you can not use anything like MD5 to 'compress' the data because what MD5 does is hash the data, so it will look at your data run an algorithm to create this fixed length hash.
However, there is an extremely small possibility that two data sets will create the same hash, therefore it seems to me impossible to reliably decrypt MD5 or other similar hashes. Check out this page for more on hash collisions.
Your problem is that you are using the internet the wrong way. The URL is limited (and it depends on the browser), so don't event to try to use long URLs - even when you want to shorten it.
Please keep in mind, that we are using the WordWideWeb for a long time and if you come into a deadend you just have to rethink your problem. Maybe you are using your current technology the wrong way.
So, use POST instead to transfer your data (as others mentioned before).
If you want to "compress" your data you should use a zip like thing and then you must make that URL confirm like BASE64 afterwards. This is not suitable in any way and completly hideous. (And of course it can not guarantee the length of your URL).
MD5 is a hash not a compression thing. MD5 is not reversable. Once you hash something you can not go back again. This is not a magical way to compress tons of megabytes into a single short number. This is to have a short thing that can tell if the original data was modified (if you do that twice).
See http://en.wikipedia.org/wiki/Hash_function
See http://en.wikipedia.org/wiki/MD5
BTW: It is the same as How to compress/decompress a long query string in PHP?

Call a function if a valid URL is found in a textarea

What would be the best way to immediately call a function (myFunction()) as soon as a valid URL has been typed into a textfield? I've googled around but I haven't found anything that helps. Using a regular expression would probably be best but I need one that recognizes all sorts of URLs:
http://google.tld, www.google.tld, http://www.google.tld
But still doesn't consider things like "index.php" to be a URL. Does anyone know about such an expression?
^((?:https?|ftp):\/\/)?([\w\.]+.)([a-z]{2,4})$
Supports ftp as well ;)
You might struggle a bit as there would be so many different possibilities. This one will match any url that is technically a valid http or https path (which includes any character in the path after the domain name, any number of subdomains, etc)
((http)s?(://))?[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*(/(.*))?
Of if you'd like to exclude intranets, you can force a tld using the following:
((http)s?(://))?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9]+)*(\.[a-zA-Z0-9]{2,4})+(/(.*))?
this will match any URL that ends with something like '.com' or '.ch' (you have to maintain the list of valid TLDs)
^(http:\/\/)?([\w\.]+\.)((com)|(ch))$
with javascript the forwardslash doesn't need escaping and TLDs could be less strict e.g. just something with 2-4 characters.
^(https?://)?([\w\.]+\.)([a-z]{2,4})$
Considering a comment to this question by CanSpice the idea of allowing TLDs with different length is difficult to cover as the event trigger may fire too early. A time delay upon the onchange trigger may solve this kind of issues.
Precise requirements and pros/cons of each solution should be weighted.
example at rubular

Categories