Optional HTTP basic authentication in JMeter - authentication

I have a request, which can be used on an endpoint with and without authentication too, but response is different in these cases. I send request to path like /MyService?wsdl. I tried to use HTTP Authorization Manager added it to HTTP Request element with whole url to this service, but it isn't working. I am sure, that username and password are correct. How is it possible to debug authentication process?

HTTP Authorisation Manager respects JMeter's Scoping Rules so make sure it is located either on the same level as HTTP Request sampler or add it as a child of this sampler (in the latter case it will be applied to this sampler only)
Configure it as follows:
Base URL: protocol followed by IP address or hostname of the application under test
Username: your username
Password: your password
Mechanism: BASIC_DIGEST
Assuming everything goes well you should see Authorization header added to your request
See How to Use HTTP Basic Authentication in JMeter article for more details.
Alternative solution is adding HTTP Header Manager and configuring it to send Authorisation header with the value of ${__base64Encode(username:password,)}
This approach assumes having __Base64Encode function installed, you can obtain it as a part of Custom JMeter Functions bundle using JMeter Plugins Manager

I suggest to use Fiddler which is a Web Debugging Proxy to send requests from JMeter through it. You can configure HTTP Request to use a proxy.
Make sure the Authorization: Basic ... header is sent within the request.
The HTTP Authorization Manager should be placed at the root of the thread group. You can then specify the full request path associated to each authorization.

Related

JMeter: Oauth 2.0 Token Generation- Getting Timed Out

I am trying to do API Testing by JMeter in two steps:
1. Generate Acess Token
Here, the authentication request is getting timed out.
Authentication Type: OAuth2.0
Grant Type- Client Credentials
I am passing the token URL and grant_type, client_id and client_secret in the Parameters section like this:
But I am getting the following error:
2. Hit the API with the fetched token
I am able to hit this with a token generated from POSTMAN.
Also in POSTMAN, I am able to authenticate properly. I tried recording the POSTMAN script but the authentication flow is not getting recorded. Just the GET API is working.
Is there any way to get the token in JMeter? or any other workaround?
Given you send the same requests you should get the same responses so capture the requests originating from JMeter and Postman using an external sniffer tool like Fiddler or Wireshark and compare the them.
The requests must be exactly the same including:
URL
Request Body
HTTP Headers
Inspect the requests and amend JMeter's configuration so the request would be 100% equal to what Postman sends.
Also it's possible to record Postman request or collection execution using JMeter's HTTP(S) Test Script Recorder
And last but not the least check HTTP Proxy settings for Postman, it might be the case you need to use a proxy server for accessing the authorization endpoint and the connection to the application under test is direct, Postman has proxy configured and JMeter doesn't, if this is the case - perform JMeter Proxy configuration again to match 100% Postman settings.

Mule HTTP Connector - session is required to access resource

I have requirement to develop mule flow to access, login, navigate and then submit form (HTTPS Post). I am using HTTP Connector configured as HTTPS with all required configurations like host/port/path/method/TSL etc. Added Query parameters which I tracked from HTTP trace in Firefox. Also set cookies as Header but I am getting A session is required to access this resource. response instead login to application.
Please find below HTTP Connector and configuration
Any suggestion?
You should not need to set cookies explicitly, and also setting them as HTTP headers will not work. First find out the type of authentication required by the service (basic, oauth, other?), then try to configure it in the HTTP connector.

Apache jmeter- How To Use ht password authentication

I have to load test a site ,which is protected by ht-password ,i used the following methods
http://username:password#site/path
Name: Authorization
Value: Basic [Base64-encoded username:password] string
http Authorization Manager -username and password given
But i failed to pass authentication using all these methods
Can anyone help ??
The correct way of bypassing Basic HTTP Authentication is using HTTP Authorization Manager configured like:
See How to Use HTTP Basic Authentication in JMeter article for more details and example configuration.
Note: above options will work for htpasswd-based authentication (or equivalent) only, if your server uses other mechanism - you will need different configuration.

REST GET requests, verbs and apikey

I want to create a flexible API Rest server. I will allow the clients to authenticate using HTTP or an APIKEY.
My question is: what is the correct way to add the apikey to a GET request? My problem is the apikey pollutes the url.
I imagine something like this : /book/1/apikey/s4cr4t !
In my opinion you should only use the Authorization header. That's what it is there for.
Putting it in the URL is a bad idea because:
a) as you said it pollutes the URL
b) if you decide to go SSL for security then the API will still appear in log files
c) caches will end up creating multiple copies of the same representation, one for each api key.
For more information on creating your own Authorization scheme go here.
Credentials may be passed using the Authorization header:
GET http://domain.com:/book/1
Authorization: apikey="s4cr4t"
It all depends on how far you want to go but the mechanics stays the same:
Context
The goal is to identify the client with some level of security. (Note: Security is another detailed discussion). Remember that one if the “features” of REST is to be stateless: That means no session state on the server except for resources. To keep the client stateless, it needs to supply on each request enough information that the request is independent. It must give the server a way to identify the client such as a username/password, API Key or token.
You have various options to do this so here are some:
Add HTTP headers to identify the client
Here one can use the Authorization header and send it with each request. There are various authentication schemes but stick to the standard ones such as Basic Auth. Here you would probably stick to SSL. The authentication process generates a kind of token if you like.
You can also make use of a cookie. The cookie must contain no information except that it is a “pointer or key” to a stateful session resource on your server (note: session it a resource which is “rest-legal”). You can create this resource by doing a PUT (+info) with response 200 OK or POST (+info) with a response of 201 Created and Location: /sessions/123334. The session can then be validated by the server such as timeout, valid client ip address, api key etc.
With the method above, you can also define a customer header such as Api-Key: XXXX. But then you limit yourself to special client. Set-Cookie are “well known” headers so browser will handle them kind of transparently. The authentication process can then be done by following links and filling in forms (PUT + POST) to authenticate (create session resource).
Encode an identifier in the content
Here you are free to do what you want too. Just add a field/token/id to your content and let the server verify it.
A RESTful API does application flow by resolving links. See also HATEOAS and Fielding's words. This also applies when you have a separate process of logging in to the application.
Do not encode any data in the URIs. (Out of band information)

Read Http Cookie from Request Stream In a WCF Service

What settings must be configured to permit Http cookies to retrieved from the Http request object in a WCF service. I am using basic Http binding. I have set aspNetCompatibilityEnabled = true and allowCookies="true". Please advise. I am certain the cookie is there with the proper domain. I have created an .aspx test page that calls my utility directly and the cookie value is returned, but calling the same code wrapped in a service does not return a value.
Are you using :
HttpContext.Current.Request.Cookies["CookieName"]?
If you are using this then there no problem.
And make sure that there is no spelling mistake.
If you are using form authentication then you have to pass token for authentication.