I have this url:
"url": "/application/userId=5678"
This url will contains the logged in userId, i am trying to map this userId with regex to be mapped on all url's in Wiremock Testing.
So far, i've tried this
"urlPattern": "/application/userId=[0-9]+"
But this is not working, any idea how to make this url work for any UserId?
RegEx should be something like:
^\/application\/userId=[0-9]+$
See also this question + answer:
Wiremock not matching regex
Related
In IIS I need to rewrite some URLs of the following format ...
https://intranet.test.ch/default.asp?rq_AppGuid=1797F2EBEDBAA87403CF202FD726B63FBB064C02&rq_TargetPageGuid=3851012A27819643BB79B647961B0D668FB9FD08&rq_RecId=31333535&rq_Lang=de
to
https://intranet.test.ch/doc/1355
From the first URL the ID is URL encoded 31333535 = 1355
So actually I need to extract the ID and used it to redirect to the other URL.
With (?<=&rq_RecId=)\d* I can geht the ID, but without filtering the not needed 3s. Also the ID can be between 1-9999, means 31-39393939.
Can this be done with regex, so I have a resulting group to use in the redirecting URL?
When I use a URL Pattern in the url field of chrome.cookies.get, I am not able to retrieve a cookie. When I type in a full URL, I am able to get the cookie. Is it not possible to use a url pattern in the url field of chrome.cookies.get?
Basically, I am trying to show a certain div when the user first logs into the site, but only the first time. I figured I can achieve this by checking the session, and it looks like the JWT token changes on each new session.
I tried this:
chrome.cookies.get({url: '*://www.mysite.com/*', name: 'JWT'}, function (cookie) {...} but it doesn't seem to work.
Do I need to use a full path? On https://developer.chrome.com/extensions/cookies#method-getAll it says
The URL with which the cookie to retrieve is associated. This
argument may be a full URL, in which case any data following the URL
path (e.g. the query string) is simply ignored. If host permissions
for this URL are not specified in the manifest file, the API call will
fail.
The 'may be a full URL' part makes me believe that you should be able to use a pattern in the URL field.
In my manifest file, I have
"webRequest",
"activeTab",
"storage",
"alarms",
"tabs",
"cookies",
"webNavigation",
"pageCapture",
"desktopCapture",
"tabCapture",
"http://*/*",
"https://*/*"
],
"https://*/*" should be able to match *://www.mysite.com/*.
Again, when I put the full url into the url field, I am able to get the cookie.
I want to do client and server side validation for Textbox which should only accept URL. I am not able find any link which does the same.
Can anyone please provide some ideas?
#Html.TextBoxFor(m => URl })
There is already a UrlAttribute in the System.ComponentModel.DataAnnotations that you can apply to your property to give both client and server side validation.
[Url] // Add optional (ErrorMessage = "...") as required
public string Url { get; set; }
Internally, it uses the following regex (from source code)
^(https?|ftp)://(((([a-z]|\d|-|.||~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'()*+,;=]|:)*#)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|.||~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))).)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))).?)(:\d*)?)(/((([a-z]|\d|-|.||~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'()*+,;=]|:|#)+(/(([a-z]|\d|-|.||~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'()*+,;=]|:|#)))?)?(\?((([a-z]|\d|-|.||~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'()*+,;=]|:|#)|[\uE000-\uF8FF]|/|\?)*)?(#((([a-z]|\d|-|.||~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'()*+,;=]|:|#)|/|\?)*)?$
You can use a RegularExpression validation in your model:
[StringLength(200)]
[RegularExpression(#"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+#)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+#)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%#.\w_]*)#?(?:[\w]*))?)", ErrorMessage = "Not a valid website URL")]
public string MyUrlField { get; set; }
I have found the above regex for matching a url from here. You could also check this website for other regex which would match a url.
Note that you need to include jquery-validation-unobtrusive, for the client side validation.
You can do URL Validation using regex for validation.
^http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$
OR
/^http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$/
You can this regex in both Server-Side and Javascript.
check it on : JSFIDDLE
I'm trying to create a MODSECURITY rule (using PCRE) for whitelisting ASP session id key in the cookie header. Here is what came to my mind so far:
^(?!.*?ASP.NET_SessionId=[a-z0-9]+;.*?$).+
The website cookie header is like this:
Cookie: PortalAlias=Portal; Language_PostPortal=en-US; ASP.NET_SessionId=opn4y4n1qja0mtzm4sx4514k; portalroles=50FA411EBBAC79
So any cookie value with characters except [a-z0-9] in the ASP.NET_SessionId key must be blocked.Is there a best and more optimized regex(PCRE) to do this?
Instead of matching you can go through a replace method so that you are able to remove whole unwanted session id:
ASP\.NET_SessionId=[a-z0-9]*[^a-z0-9;][^;]*;\s*
Live demo
I am using Jmeter 2.11 and My http response after login as follows,
"apiResponseStatus": "SUCCESS",
"authToken": "o5SsJF9yOebRC9LsR5WCnYUNpslddO30Db/zBAdhBW/ISfL62CaOHqmSkrAHZ8RT4XF6yaGxX6kbmpACZu212Q=="
How to write RegEx for this to reuse same token throughout the Test Plan?
Use Regular Expression Extractor with below details:
Apply to --> Main Sample Only
Response Field to check --> Body
Reference Name: auth_token
Regular Expression: .authToken": "(.+?)".
Template: $1$
Match No.: 1
Default Value: Not Found
You can pass Reference Name as ${auth_token} where it is required throughout your test plan.
Hope this will help.