Facebook Login using Jmeter - regex

I want to do a load test my Heroku application using Jmeter.
To access the functionality of the application, I need to login through Facebook first.
I tried with browser recording using proxy server. But the problem is the code parameter (response_type) returned by facebook is hard coded in the callback URI. So its giving exception (Code expired exception) while running the Jmeter script.
I am able to view the code in response header of https://www.facebook.com/dialog/permissions.request URL. So I need to grab this code from this header dynamically and put in the code parameter of callback URL.
For this I am using Regular Expression Extractor in Jmeter under /dialog/permissions.request URL.
My response header looks like below:
Cache-Control private, no-cache, no-store, must-revalidate
Date Wed, 26 Dec 2012 13:37:17 GMT
Expires Sat, 01 Jan 2000 00:00:00 GMT
Location http://myapplication.herokuapp.com/oauth/authenticate/facebook?code=SOME-CODE
P3P CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"
I want to extract this code=some code and put it in the next URL using regular expression extractor.

I don't know the JMeter context, but the regex can be something like:
\?code=(.*)
You might need to double the backslash. The $ can be problematic if the header is checked as a whole, you can replace it with \n perhaps.
[EDIT] I found the tester pointed from the JMeter page and used it against the header content you gave. Apparently the $ was not necessary, the search is stopping on a line bound. Still not sure about doubling the backslash. Experiment.

Problem is not with Regular Expression Extractor as mentioned by Saswat Sahoo. Main problem is Location header not even getting in Response header of Jmeter. We can see Location header in Browser's response header. Few information are missing in Jmeter Response Header compared to Browser's response header.

Related

How to remove response headers location when doing http request via postman and logic app HTTP connector

Is there any way to remove the response header location when making a post via HTTP connector in the logic app or via a postman?
Response Headers
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Location: http://xxxx.xxx/api/integrationstatus?id=xxxxx
Date: Thu, 11 Mar 2021 10:13:53 GMT
If you mean remove the Location field from response header just inside the HTTP connector, I'm afraid the answer is "no". And to remove it inside postman, the answer is also "no".
But if your requirement is to get the data of response header, at that time remove the location field. This can be implemented, here provide two solutions for your reference.
1. We can do it by "Execute Javascript Code" action in your logic app. Before use "Execute Javascript Code" action, you need to create integration account and link it to your logic app. Then use the js code like below screenshot:
2. If you do not want to create integration account to use "Execute Javascript Code" action. You can also do it by "Compose" action. List all of other fields in "Compose" by their expression. For example, the expression for Cache-Control is outputs('HTTP')['headers']?['Cache-Control'].

JMETER This site does not specify a policy in the P3P header ERROR

I am trying to hit this URL https://subdomain.example.com in JMeter and recorded using the Blazemeter Chrome extension has all the necessary config elements but get an error:
HTTP/1.1 429 Too Many Requests
Content-Type: text/html; charset=utf-8
Content-Length: 1031
Connection: keep-alive
Cache-Control: private, no-cache, no-store, must-revalidate
Date: Tue, 20 Aug 2019 01:21:35 GMT
Expires: 0
p3p: CP="This site does not specify a policy in the P3P header"
I have tried coping the Header Cookies from Browser Header Response which works for sometime but then start throwing an error
As per HTTP Status Code 429 Too Many Requests description:
The HTTP 429 Too Many Requests response status code indicates the user has sent too many requests in a given amount of time ("rate limiting").
A Retry-After header might be included to this response indicating how long to wait before making a new request.
So there are following options:
Your server is overloaded, in this case there is nothing you can do here apart from reporting the error as the bottleneck
Your script doesn't have proper correlation implemented, i.e. you're sending recorded hard-coded values instead of getting dynamic parameters
Your server doesn't allow such amount of requests from a single IP address within the given timeframe, you could try implementing IP Spoofing so your server would "think" that the requests are coming from the different machines.
Thanks for your reply. In the end I figured out that no limitation for number of calls implemented.
Now come to answer this is how I managed to work this:
Opened the page in chrome and from the header section copied all the header elements into the header manager hard coded.
First time it fails and returns p3p: CP="This site does not specify a policy in the P3P header" but also return the update variable value needed for next request which I extract and used in the next and subsequent Requests. The way I was able to find out which variable is changing by using the string comparison of 2 Response Headers
This was a difficult one but somehow worked with very minor change I also added the Header Manager to each request for safer side.

JMeter, Regular Expression Extractor

I am having a hard time get the "Regex Expression Extractor" working in Jmeter for the following:
Response Header is something like:
Set-Cookie: Token=dfrtydgsdttetert; Domain=.domain.ca; Path=/;
Expires=Fri, 19 Oct 2018 18:54:18 GMT; Secure
ETag: W/"41c-gdf+/mzdw"
In JMeter Regular Expression Extractor:
Apply to: main sample and sub-samples
Field to check "Response Header"
Name of create Variable: extracted_token
Regular Expression: (?<=Token=)(.*)(?=; Domain) <- the goal is
the get the string "dfrtydgsdttetert"
Template: $1$
Match No: 1
Default Value: ERROR
I tried the above configuration and the extracted_token variable is always "ERROR"
if I change the regex to Token=
then I get:
extracted_id_token=null
extracted_id_token_g=0
extracted_id_token_g0=Token=
Please guide me how to fix my configuration so I can retrieve "dfrtydgsdttetert" in the response header.
To do this extraction the most performing way is to use Boundary Extractor:
If you still want Regular Expression Extractor:
The "response header" you're trying to extract is basically a HTTP Cookie, JMeter automatically handles cookies via HTTP Cookie Manager so you can just add it to your Test Plan and it will be way more convenient than manually extracting the values from the Set-Cookie header and adding them to Cookie header.
If you need the cookie value for other reason you can get it from the HTTP Cookie Manager itself
Add the next line to user.properties file (lives in "bin" folder of your JMeter installation)
CookieManager.save.cookies=true
Restart JMeter to pick the property up (the change will be permanent)
Add HTTP Cookie Manager to your Test Plan
That's it, now you will be able to refer your Token cookie value as ${COOKIE_Token} where required, no need to extract it from the header.
More information: HTTP Cookie Manager Advanced Usage - A Guide

Apache CXF not handling cookies with "Expires" directive?

We use SUN Jersey client to consume some REST services and Apache CXF to serve some REST services, in the same java project. Some of the services we consume return cookies with "Expires" directive set. For eg Set-Cookie: name=value; Expires=Wed, 09 Jun 2021 10:18:14 GMT.
Consider the below code, assuming wr is a Jersey WebResource. ClientResponse is also a Jersey class.
ClientResponse resp = wr.get(ClientResponse.class);
System.out.println(resp.getCookies())
Now, in the case of cookies with expires directive, the actual cookie is not returned. Instead, the expires directive itself is returned as the cookie (cookie's name is Expires, value is the date).
After some digging, we found that this is due to the way the Set-Cookie HTTP header is parsed by CXF. Please refer the fromString method here. Basically, the code considers the last <name>=<value> pair it finds in the Set-Cookie header to be the cookie. In this case, expires=<date> occurs after name=value (latter being the actual cookie needed).
OTOH, Jersey's header parsing code here (the actual impl class is here, and it calls the former) returns the actual cookie, ignoring the expires directive. This behavior is good enough for us. So we'd like to choose Jersey's version. How do we do this? Please note that we also need the project to still use CXF also (to serve services), so the dependency cannot be removed.
The project in question is a Maven project.

How can I set a cookie in a request using Fiddler?

I need to set a cookie before I issue a request to a Web site using Fiddler. How do I do this?
Simple...You need to set a header value, with your request, like so:
Cookie: YourCookieName=YourCookieValue
To do this using the FiddlerScript engine, add the following code into the onBeforeRequest method:
oSession.oRequest["Cookie"] = (oSession.oRequest["Cookie"] + ";YourCookieName=YourCookieValue");
This will preserve any other cookies that have been set.
You need to be more specific about what you're trying to do.
You can edit (or add) an outbound Cookie header to send a cookie to the website. You can do this either manually or via the FiddlerScript engine. But that doesn't "set" the cookie on the client-- it simply sends it to the server. If you want to set a cookie on the client, you either have to use another means, or you can inject a Set-Cookie response header on a previous response from the server, with the value you want to set on the client.
You can also use the Fiddler Composer.
Run Fiddler
Open the Composer Tab on the top.
It's easiest if you can start with another request from your web site. To do this capture a the request you want to modify, then drag it from the UI to the composer tab.
A good explanation is here: http://www.debugtheweb.com/Fiddler/help/composer.asp
Fiddler allows your to resend/rebuild an existing request. There is a Request Builder. While rebuilding in the RAW form, modify your cookies.
This solution is valid for Cookie based authentication:
If you want to test the API/url which have authentication enabled, please try following, i am showing for MVC web API on IIS server. usually there are more than 1 cookie responsible for authorization, so you may need to send more than 1 cookie in header as follows:
User-Agent: Fiddler Host: localhost:51000 content-Type: application/json Cookie : .ASPXAUTH=xxxxx;ASP.NET_SessionId=yyyy;__RequestVerificationToken=zzzz
When running Fiddler as a reverse Proxy you can modify the response headers
via FiddlerScript by adding a line in the OnBeforeResponse method:
static function OnBeforeResponse(oSession: Session) {
// ...
oSession.oResponse["Set-Cookie"] = "sessionToken=abc123; Expires=Wed, 09 Jun 2021 10:18:14 GMT";
}
Also check Fiddler docs about Modifying a Request or Response for more info.