JMeter - get value from href - testing

I am load testing an application that has a link that looks like this:
https://example.com/myapp/table?qid=1434e99d-5b7c-4e74-b64e-c24e9564514d&rsid=5c94ddc7-e2e4-4e69-8547-49572486f4d1
I need to get the dynamic value of the rsid so I can use it later in my script.
So far I have tried using the regex extractor and I am probably doing it wrong.
I have tried things like:
name = myvar
regular expression = rsid=(.*?) # didnt work
regular expression = <a href=".*?rsid=(.*?)"> # didnt work
Template = $1$
I have one extractor set up to get the csrf value and that one works as expected but that is also because the csrf value is in the page source.
The above link is NOT in the page source as far as I can see but it DOES show up when I inspect the link. I dont know if that is obfuscation or something else?
How can I extract the value of the rsid? Is the regular expression extractor the right one to use for this?
Should I be using something else?
Is it just a formula issue?
Thanks in advance.

Try something like:
rsid=[0-9A-Fa-f\-]{36}
the above regular expression should match a GUID-like structure and your rsid seems to be an instance of it.
Demo:
Also be aware of the Boundary Extractor, it's sufficient to specify "left" and "right" boundaries and it will extract everything in-between. In general coming up with "boundaries" is much easier than creating a regular expression, it's more readable and JMeter processes the Boundary Extractors much faster. More information: The Boundary Extractor vs. the Regular Expression Extractor in JMeter

Related

regex limitations within live template / can use live-template functions as replacement?

I'm removing builder pattern on multiple places. Following example would help me with the task, but mainly I'd like to learn how to use live templates more.
Preexisting code:
Something s = s.builder
.a(...)
.b(bbb)
.build();
and I'd like to remove it to:
Something s = new Something();
s.setA(...);
s.setB(bbb);
part of it can be trivially done using intellij regex, pattern: \.(.*)$ and replacement .set\u$1. Well it could be improved, but lets keep it simple.
I can create surround live template using variable:
regularExpression(SELECTION, "\\.(.*)", "\\u$1")
but \\u will be evaluated as u.
question 1: is it possible to get into here somehow \u functionality?
but I might get around is differently, so why not try to use live temlate variable:
regularExpression(SELECTION, "\\.(.)(.*)", concat(capitalize($1), "$2"))
but this does not seem to work either. .abc is replaced to bc
question 2: why? How would correct template look like? And probably, if it worked, this would behave incorrectly for multiline input. How to make it working and also for multiline inputs?
sorry for questions, I didn't find any harder examples of live templates than trivial replacements.
No, there is no \u functionality in the regularExpression() Live Template macro. It is just a way to call String.replaceAll(), which doesn't support \u.
You can create a Live Template like this:
set$VAR$
And set the following expression for the $VAR$ variable:
capitalize(regularExpression(SELECTION, "\\.(.*)", "$1"))

How i get a continuation of a value with Extractor (JMETER)?

I am trying to take the Information from an element from the middle on.
And this value is only displayed this way
see image:
It would be the value "info_se"
You need to escape ? sign (as well as other meta characters) in your regular expression with a back slash so the whole expression would be something like:
a href="#" data-url="Cervello/Release.aspx\?info_s=(.+?)"
Demo:
References:
JMeter Regular Expressions
Using RegEx (Regular Expression Extractor) with JMeter
Perl 5 Regex Cheat sheet
Use regular expression extractor under your sampler that return the full html. Save in reference name as info and then use it later ${info}
info_s=(\S+)"
Template $1$
Match No. 1
My error was another, this "info_s" field was decoded, so the system needs this coded encoding.
I managed to find several that stored this value, and in the parameters of HTTP request, I was informed to code the extracted value of the Extractor
I get, finding in the html the field that stored this value "info_s", decoded, then using the encoder option of jmeter, I was able to capture the correct value.

Find string that is not between specific html tag

I'm being required to use regular expressions to parse HTML. I do realize regular expressions are bad for HTML matching.
I would like to find a specific string and evaluate whether or not its between two strings.
In this example ® must be immediately between <sup> and </sup>
Example:
<sup>®</sup>
I believe this would involve using negative lookaheads and lookbehinds. My first thought would be:
(?<!<sup>)®(?!<\/sup>)
Unfortunately this fails as I don't believe you can do a lookahead and lookbehind in this combination.
Just using the negative-lookahead does work and is probably good enough for my purposes...
®(?!<\/sup>)
...but I'd like to know if it's possible to combine a lookahead and lookbehind in this way. Or is there another technique I should be using?
Thanks in advance
Your initial regex (i.e. (?<!<sup>)®(?!<\/sup>)) is correct, as demonstrated in the example usage at https://www.debuggex.com/r/WyY9y0Zq2Krz_3Xm
However, it works in Python and PCRE, but not in Javascript (you can check by choosing each of them in the dropdown). Javascript does not have negative lookbehind support.

SQL injection on clean url

I would like to test my website for SQL injection using sqlmap. I'm using mod_rewrite and my URL looks like this:
http://www.example.com/forum/&nav_page=1
(where nav_page is the parameter name and 1 is value)
The problem I'm having is that I can't find a way to tell sqlmap to perform the injection test just on the value.
The URL also not contain the ? sign because it's SEO friendly.
Your ideas of seo-frienliness are quite vague. It is not symbols that make an url look "seo-friendly". It's technology that doesn't involve parameter names and values.
So, you have to decide either you are using query string parameters or not.
If not - make your urls real seo-friendly. like http://www.example.com/forum/nav_page1/
If you still want to use query string variables - then use them properly, using ? mark to define a query string.

Change Url using Regex

I have url, for example:
http://i.myhost.com/myimage.jpg
I want to change this url to
http://i.myhost.com/myimageD.jpg.
(Add D after image name and before point)
i.e I want add some words after image name and before point using regex.
What is the best way do it using regex?
Try using ^(.*)\.([a-zA-Z]{3,5}) and replacing with \1D\2. I'm assuming the extension is 3-5 alphanumeric numbers but you can modify it to suit. E.g. if it's just jpg images then you can put that instead of the [a-zA-Z]{3,5}.
Sounds like a homework question given the solution must use a regex, on that assumption here is an outline to get you going.
If all you have is a URL then #mathematical.coffee's solution will suit. However if you have a chunk of text within which is one or more URLs and you have to locate and change just those then you'll need something a little more involved.
Look at the structure of a URL: {protocol}{address}{item}; where
{protocol} is "http://", "ftp://" etc.;
{address} is a name, e.g. "www.google.com", or a number, e.g. "74.125.237.116" - there will always be at least one dot in the address; and
{item} is "/name" where name is quite flexible - there will be zero or more items, you can think of them as directories and a file but this isn't strictly true. Also the sequence of items can end in a "/" (including when there are zero of them).
To make a regex which matches a URL start by matching each part. In the case of the items you'll want to match the last in the sequence separately - you'll have zero or more "directories" and one "file", the latter must be of the form "name.extension".
Once you have regexes for each part you just concatenate them to produce a regex for the whole. To form the replacement pattern you can surround parts of your regex with parentheses and refer to those parts using \number in the replacement string - see #mathematical.coffee's solution for an example.
The best way to learn regexs is to use an editor which supports them and just experiment. The exact syntax may not be the same as NSRegularExpression but they are mostly pretty similar for the basic stuff and you can translate from one to another easily.