How to send XML file request using Capybara, and check response for correct parameters - ruby

I am writing acceptance tests using capybara/rspec. And I want in one of my tests send request using XML file and check that it got correct parameters in response. Do you know how I can write it please?
For now I send my request using curl.
curl -X POST -H 'Content-Type: application/xml' -H 'Authorization: Basic example' http://example/example --data-binary #request.xml
But I want to automate it using Capybara/rspec

You don't do this with Capybara. Capybara is used for tests that replicate what a user would do via a browser. As such it interacts with elements in the browser and the page generates the requests a user would trigger. For what you want to test you should be looking at request specs (they don't use Capybara) which are aimed at testing APIs, etc. and allow for posts of random data to endpoints - https://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec

Related

How to send authentication parameters in PUT request - Jmeter

Trying to perform a load testing using Jmeter tool however can not pass authentication.
The following curl works well
curl -u <USERNAME>:<PASSWORD> -X PUT "http://server-url/artifactory/my-repository/my/new/artifact/directory/file.txt" -T Desktop/myNewFile.txt
I need to upload file via PUT method based on the curl sample above and can not do it because do not understand where username and password values should be placed in the HTTP Request sampler, in the parameters part, Post Body or somewhere else.
Thanks you
You need to add a HTTP Authorisation Manager to your Test Plan and configure it as follows:
Base URL: http://server-url
Username: USERNAME
Password: PASSWORD
JMeter will generate relevant Authorization header and add it to the request. See How to Use HTTP Basic Authentication in JMeter article for more details.
Guessing, but you probably add the HTTP header
Authentication: basic [base64 of username:password]
Google "HTTP Basic Authentication"

Downloading files with Microsoft Graph using bash (curl)

I try to download several files from OneDrive through Microsoft Graph.
I am very close to achieve my goal. For the moment I have managed the token system (notably through Jay Lee detailed answer), and achieved to resolve the confusion that I made among the different endpoints that exist in Microsoft Graph (thank you Marc LaFleur - MSFT).
Now I really work on the call of the API that would permit to download the files I want. This is how I proceeded:
1- As I've seen in the Microsoft Graph Documentation, the normal syntax would be the following:
curl -w %{time_total} https://graph.microsoft.com/v1.0/me/drive/items/01M...WU/content -H "Authorization: Bearer $access_token"
2- However, this gives me a 302 request, which I can't handle in bash. So I looked for another solution and I found this Microsoft article explaining that:
"To download files from OneDrive in a JavaScript app you cannot use the /content API, since this responds with a 302 redirect. A 302 redirect is explicitly prohibited when a CORS preflight is required, such as when providing the Authorization header.
Instead, your app needs to select the #microsoft.graph.downloadUrl property, which returns the same URL that /content would have redirected to. This URL can then be requested directly using XMLHttpRequest. Because these URLs are pre-authenticated they can be retrieved without a CORS preflight request."
It talks about Javascript but I think it can be applied to my case.
3- So I tried this method and I wrote:
curl "https://graph.microsoft.com/v1.0/me/drive/items/01MB...WU?select=id,#microsoft.graph.downloadUrl" -H "Authorization: Bearer $access_token"
It gave me the URL that normally would permit me to finally download the file, but when I execute it, I get the following response:
Code:
curl "https://graph.microsoft.com/v1.0/$metadata#users('e967dd4d-680e-4a06-9bf7-468875e1a04c')/drive/items/$entity" -H "Authorization: Bearer $access_token" (it is exactly what I got with the previous request)
Response:
Any help? Why is it a bad request since I've put exactly what I got from the graph.microsoft.com request?
https://graph.microsoft.com/v1.0/$metadata#users('e967dd4d-680e-4a06-9bf7-468875e1a04c')/drive/items/$entity is the #odata.context annotation, which is not what you're after. You need to pull the URL out of the #microsoft.graph.downloadUrl annotation and use that to grab the file contents. The URL you're after should mention download.aspx in it.

http authentication using apiary / api blueprint

Just dipping my toes into Apiary and API Blueprint, and having some problems with passing in some basic http authentication.
On an initial call, the API creates a token for any given user that needs to be used with any subsequent call. My problem is how to mark-up that authentication so it works with the Apiary production request.
The command-line curl (that works) is (in obfuscated code) this...
curl --user name#somewhere.com:tokenGoesHere http://test.server.uri/API/getUserInfo
So, how do I convert that curl command into the equivalent API Blueprint format?
Unfortunately there's no way, at the moment, to specify authentication/authorisation in APIBlueprint.
It's in the roadmap, but unfortunately we can't give you any precise ETA on that.
You might want to read our help page on the argument as well.

How to send auth_token in Http header

I am trying to create rest based webservices, which I want to secure them using spring security Oauth2.
What I found is then, in oauth2 we have to send auth_token in query string.
But my need is to send in header.
I have searched a lot, but I didn't get the answer which I need.
Is there anybody who can help?
Reference link [ http://www.beingjavaguys.com/2014/10/spring-security-oauth2-integration.html
]
You can test sending the access token for example using Curl:
curl -H "Authorization: Bearer <ACCESS_TOKEN>" http://www.example.com
With this you should be able to see, if server is working as expected. How to do it in client application depends on the programming language you are using.

How to provide basic authorization like in curl command in web browser or in RestClient

I am new to Spring and very new to Spring Oauth2 Security. I have searched a lot about how to request the following link in web browser(In Firefox Rest Client plugin).The following request is curl and working perfectly fine in terminal through this command.
I am getting the problem while giving basic authorization. So How we can interact with basic authorization given below as -vu myapp:123456.
curl -X POST -vu myapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=sunit&username=sunit&grant_type=password&scope=read%20write&client_secret=123456&client_id=myapp"
I used wireshark for capture the request and ended the same request to fb just to connect because I don't have a local server running... you can see that is a post request with the body in encoded URL...

Resources