HTTPS using jmeter is not working and getting 403 error - jmeter

I am load testing an HTTPS service using jmeter.
It works well by using following curl on a linux box:
curl -k -v -HContent-Type:application/json
-HauthToken:abcdefghijkla995e2f9-6cba-46e7-8b08-a7ffb67ca95d20150416163318
-Hsystem_name:testingsystemname -X POST --data-binary '{"deviceId":"1","cookieId":null,"emailId":"jmetertest#gmail.com"}'
https://localhost:9443/service/push/datacheck
How do I use jmeter to hit the request for load testing.
I was putting the authToken and system_name under 'send parameters with request' but it did not work and i keep on getting a 403 error.
Please help

You need to add HTTP Header Manager to your Test Plan and configure it to send the following headers:
authToken=abcdefghijkla995e2f9-6cba-46e7-8b08-a7ffb67ca95d20150416163318
system_name=testingsystemname
For sending JSON switch HTTP Request sampler to "Body Data" tab and put it there.

Related

Making a POST request with Chef

I need to post a .json file to a server with a rest API with a Chef recipe, following Chef's documentation I came up with this code:
http_request '/tmp/bpp.json' do
url 'http://localhost:8080/api/v1/blueprints/bpp'
headers ({
'AUTHORIZATION' => "Basic #{Base64.encode64(user)}",
'CONTENT-TYPE' => 'aplication/json'
})
action :post
end
For authorization token, user is a variable that contains 'user:password'
When I run this chef recipe I obtain the following response:
Error executing action `post` on resource 'http_request[POST /tmp/bpp.json]'
Net::HTTPServerException
------------------------
400 "Bad Request"
Prior to this I was just executing a curl call and it was working fine, but I need to change to the http_request resource. This was the old (working) curl request:
curl --user user:password -H 'X-Requested-By:My-cookbook' --data #/tmp/bpp.json localhost:8080/api/v1/blueprints/bpp
I am not very used with REST apis and seems like an uncharted territory to me.
You forget about message. Using file name as resource name won't send this file as data. Try adding:
...
message lazy { IO.read('/tmp/bpp.json') }
...
In your case only the resource name - /tmp/bpp.json, will be sent. Not a file content. As stated in linked doc:
The message that is sent by the HTTP request. Default value: the name of the resource block See “Syntax” section above for more information.

create project for sonarqube with the rest-api / web-api

we try to automate the creation of projects (including user/group Management) in sonarqube and I already found the Web-API-documentation in our sonarqube 5.6-Installation. But if I try to create a project with the following settings
JSON-File create-project.json:
{"key": "test1", "name": "Testprojekt1"}
curl-request
curl --noproxy '*' -D -X POST -k -u admin:admin -H 'content-type: application/json' -d create_project.json http://localhost:9000/api/projects/create
I get the Error:
{"err_code":400,"err_msg":"Missing parameter: key"}
It's a bit strange because if I try e.g. the URL:
http://localhost:9000/api/projects/index
I get the list of the projects I created manuelly and if I try a request like
curl -u admin:admin -X POST 'http://localhost:9000/api/projects/create?key=myKey&name=myProject'
it works too, but I would like to use the new api because it looks like it support much more function that the 4.X API of sonarqube.
Maybe someone here can help me with this problem, if would very thanksful for every useful hint.
best regards
Dan
I found this question because I got the same "parameter missing" error message.
So what we both did not understand: The SQ API expects the parameters as plain URL parameters and not as json formatted parameters as most REST APIs do today.
PS: Would be nice if this could be added to the SQ documentation.

Apache Tika server request to get 'main content' instead of 'plain text'

I am experimenting with Apache Tika: app & server, gui and command line.
With Tika app, I can do something like
java -jar tika-app-1.7.jar --gui
and choose 'View' -> 'Main content', or
java -jar tika-app-1.7.jar --text-main http://www.cnn.com/2015/07/09/politics/russian-bombers-u-s-intercept-july-4/index.html
I need main content, but it seems in a server mode I can only get plain text. I am checking this guide.
curl -s "http://amzn.com/B005IWM8PU" | curl -X PUT -T - http://<server_ip>:9998/meta
curl -s "http://amzn.com/B005IWM8PU" | curl -X PUT -T - http://<server_ip>:9998/tika
Maybe, something that comes after http://:9998/ will do the trick?
Is there any way do get main content in a server mode?
At the end, the request has to be made in Ruby, tika-server-1.3.jar. So far looks like this:
require "net/http"
tika_prefix = URI('http://<server_ip>:9998/tika')
url = 'http://www.cnn.com/2015/07/09/politics/russian-bombers-u-s-intercept-july-4/index.html'
request = Net::HTTP::Put.new(tika_prefix.to_s)
request.body = url
request.content_type = 'text/html'
http = Net::HTTP.start(tika_prefix.hostname, tika_prefix.port)
http.request(request).body
This is possible as of today. Tika 1.15 now implements TIKA-2343 feature request, which adds --text-main equivalent in server mode.
vaites/php-apache-tika is a PHP binding for Tika that I use, and I've opened an issue regarding this, so we should be able to see it being implemented soon.
EDIT: The PHP Binding library now supports this feature.

How to login using mediawiki's api, curl, and bash?

My understanding of the process:
From mediawikis login manual https://www.mediawiki.org/wiki/API:Login
When using MediaWiki's web service API, you will probably need your application or client to log in. This involves submitting a login query, constructing a cookie, and confirming the login by resubmitting the login request with the confirmation token returned.
1) Attempt to login with username and password, this will fail with 'result="NeedToken"' as part of response html. Response will also contain the token to be passed in for the next login attempt.
2) Attempt to login again, this time passing in token in addition to un/pw. This should return with 'result="Success"'
My code:
###Attempt first login setup cookie jar
loginRes1=$(curl --cookie-jar cjar -X POST "$domain/wiki/api.php?action=login&lgname=$lgname&lgpassword=$lgpassword")
###Grab the token from login attempt
lgtoken=$(echo $loginRes1 |sed -rn "s/.*token="([0-9a-zA-Z]+)".*/\1/p" )
###Attempt second login, this time passing token as well
loginRes2=$(curl --cookie-jar cjar -X POST "$domain/wiki/api.php?action=login&lgname=$lgname&lgpassword=$lgpassword&lgtoken=$lgtoken")
Result:
echo $loginRes1
###Only relevant html from echo shown below, cleaned up into xml syntax
<?xml version="1.0"?> <api> <login result="NeedToken" token="944af711913a037cfb8b90d477d51f6c" cookieprefix="ronk" sessionid="isqvhm955lj35g1q2e2klme091" /> </api>
echo $loginRes2
###Only relevant html from echo shown below, cleaned up into xml syntax
<?xml version="1.0"?> <api> <login result="NeedToken" token="ffdd1aa6dc3699df26b9de6dd1c6d5a5" cookieprefix="ronk" sessionid="fdahoh4gh7junrqm1tk2p1qd25" /> </api>
I'm still getting the NeedToken result the second time, instead of Success as I would expect.
Logging in via browser
I can login normally with a browser with a form submission, the post request contains 4 parameters: wpName, wpPassword, wpLoginAttempt, wpLoginToken
wpName=myName&wpPassword=myPassword&wpLoginAttempt=Log+in&wpLoginToken=d3fe3a1de6fbc934acd3039149f3c56d
Other Notes
1) I confirmed that the un/pw works when logging in normally through a browser.
2) It's unclear to me if I'm using the curl cookie-jar syntax appropriately
3) I don't know the version of mediawiki I'm connecting to, it was installed recently and is likely the highest stable version.
4) You'll notice in the successful browser attempt, the parameters have the wp prefix instead of lg, if I change the curl attempt to match (i.e. wpName, wpPassword) then the returned result is:
<?xml version="1.0"?> <api> <warnings> <main xml:space="preserve">Unrecognized parameters: 'wpName', 'wpPassword'</main> </warnings> <login result="NoName" /> </api>
The --cookie-jar option to curl only tells curl to save cookies to the jar. It doesn't tell curl to load cookies from the jar.
To get curl to load cookies from the jar you need to use the -b option to specify the cookie jar to use.

CodeIgniter Curl Library Capturing Error

I am trying to retrieve an error when my CI curl request fails. However, I cant seem to get $this->curl->error_code or $this->curl->error_string to output any data. I am trying to make a request to an API and I am breaking the URL to force an error.
$api_url = "http://breamkebreakmedfd.com";
$this->curl->create($api_url);
$this->curl->execute();
echo($this->curl->error_string);
I get no error when I echo the error.

Resources