Is this the correct syntax to validate authorization of API? given().get("url").when().auth("username","pwd").then().assertthat().statuscode(200) - bdd

I am testing for preemptive authorization using BDD for API automation using Rest assured. Is this the correct syntax?
given().get("url").when().auth("username","pwd").then().assertthat().statuscode(200)
Can I write get() after given() or should it be in when()?

Try this, it works for me when i use this with Testng.
httpreq.auth().preemptive().basic("ToolsQA", "TestPassword");
reponse = httpreq.request(Method.GET,"/authentication/CheckForAuthentication");
Thanks for Asking,

Related

How to change OData API paths to lowercase format?

I added OData to my .NET Web API. I only use it for querying data (HttpMethod GET).
When I run my application, and I look at Swagger I see the following:
As you can see, the OData endpoints use uppercase name for the resource set which I something I really dislike. It's important to note that the endpoints work fine even in lowercase.
How can I make it so that the OData endpoints use lowercase by default to create consistency in my swagger documentation?
Thanks in advance
Use:
services.AddRouting(options => options.LowercaseUrls = true);
In your startup.cs

Can I achieve AND instead of OR in Swagger API generated by JHipster?

I set up a basic JHipster project and generated an entity that supports filtering with JDL.
The generator made a Swagger API which I use for querying the database.
The Swagger API doc shows me a list of parameters which can be used to build query.
The template query looks like this:
GET /api/client?name.equals=john&surname.equals=doe&country.in=uk&country.in=de
The request works fine but the parameters are chained like name==john OR surname==doe OR country==uk OR country==de so I get all johns, does, and everoyne from uk and de.
This is ok, but for some queries i need name==john AND surname==doe so not all Johns and Does but specifically John Doe. I searched here and on the swagger forum but couldn't find the answer.
My question is: how do I achieve changing the OR to AND in the query?
Does this swagger query support AND or do I have to make changes in the backend?
Your question is not about swagger, this is why you could not find anything in swagger forum.
It's about JHipster JPA entity filtering and the answer is no: you can't generate code that would use a OR.
You must code it yourself, look at the *QueryService classes and assemble your criteria with the logic you need.

Run a flow from another flow in Twilio

How can I run a flow from another flow in Twilio Studio Flow?
Help with defining the To and From HTTP parameters:
I am a beginner in programming so I am failing to understand the brief notes given in support docs, namely specifying HTTP additional parameters for "To" and "From".
Additional details from comment:
I am trying to run REST API triggered Flow B from primary Flow A by using an http request widget in Flow A in the format below: (as suggested in a similar problem posted on this portal) Widget: HTTP Request [ACCOUNT_SID:AUTH_TOKEN#studio.twilio.com/v1/Flows/THE_OTHER_STUDIO_FLOW_SID/Executions][2] Content Type: Form URL Encoded KEY:VALUES To:+1234567890 From:+2773123456 I am getting error 401. I tried to swap the To number with the From number without success
There are 2 ways you can trigger one twilio studio flow from another
Method 1:
Use the TwiML Redirect Widget. Place the widget where you need it and specify the target studio flow URL there. Studio URLs have the following format
https://webhooks.twilio.com/v1/Accounts/{AccountSid}/Flows/{FlowSid}
Method 2:
Do the same as above programmatically. You can send twilio a twiML response such as the one below
let twiml = new Twilio.twiml.VoiceResponse();
if (something) {
twiml.redirect({
method: 'POST'
}, 'https://webhooks.twilio.com/v1/Accounts/{AccountSid}/Flows/{FlowSid1}');
} else {
twiml.redirect({
method: 'POST'
}, 'https://webhooks.twilio.com/v1/Accounts/{AccountSid}/Flows/{FlowSid2}');
}
For more info, check out https://www.twilio.com/docs/voice/twiml/redirect
Assuming you are not trying to bridge the call between the two flows, this should be possible. To simplify:
You have a call come in on Flow A ("Incoming Call" trigger on Flow A).
Flow A executes its logic.
That logic triggers Flow B by calling its REST API endpoint so that it makes a new outbound call ("REST API" trigger on Flow B).
This last thing is the hard part. Make sure you are looking at the docs for the REST API Execution resource. To trigger a new flow, you need to make a POST request which supplies the To and From parameters.
If you are a beginner at programming, it might be helpful for you to start with a separate HTTP client like Postman to start to get familiar with the structure of an HTTP request, and learn the full extent of what is required to successfully make this API request before you start trying to cram it into Studio and automate it.
That said, this request should be possible to do within the Studio Make HTTP Request widget. If you make your content type Application/JSON, you can pass the To/From parameters directly in a JSON-formatted request body, like this:
{
"To": "+19995551234",
"From": "+12345556789"
}
To be perfectly honest, I don't know what the widget means by "Http Parameters". This could be HTTP Headers, URI parameters, or something else. I think the JSON form is clearer.
I came across the same situation. The solution for authentication is to change the url to include AccountSid and AuthToken
https://[AccountSid]:[AuthToken]#studio.twilio.com/v2/Flows/[SID]/Executions
Instead of Application / Json, use Form Parameters. Then add individual parameters below, for To, From, and Parameters​ (JSON string) for other variables.

Orbeon Form HTTP Service

Does anyone know how to pass parameters to a RESTFUL webservice using the Orbeon HTTP Service?
I have a RESTFUL API at http://localhost/RESTFUL/GETADDRESS/$parameter$.
Sample of the URL is http://localhost/RESTFUL/GETADDRESS/1234
Orbeon HTTP service is unable to pass the parameter to the web service.
The Request Body is configured as <parameter/> and serialization is set to XML.
Could not use HTML Form as it adds a ? to the URL which is not correct.
Anyone has any ideas to get this working?
There is no perfect solution. But try writing the service URL as:
http://localhost/RESTFUL/GETADDRESS/{...expression here...}
where "...expression here..." should be replaced by an XPath expression pointing to the value you would like to pass. For example, if pointing to a control called foo in a section called bar, try:
http://localhost/RESTFUL/GETADDRESS/{/*/bar/foo}
I also added this RFE.

Automated testing of rails app with real XML and JSON request/response, to serve as API documentation?

I should be kind to my web service consumers and serve them some nice examples, even though it's no fun maintaining a big xml request test. Are there better ways to be a good WS provider?
I have no html. The app accepts both XML and JSON, so to ensure the validity of the API examples(both xml and json), I'd like to prove their OK in an integration suite.
In your answer, I'd like to see some examples, not "try cucumber/webrat/capybara" only. It's hard to find howto without html. Thanks for helping out!
Since you don't need the fancy features of webrat/capybara for executing javascript or dealing with arbitrary html, it makes sense to just use the basic integration test support from rails.
I'd store the API examples in some form that can be easily transformed to either XML or JSON, then use this file in the integration test so that you get both format types tested while only maintaining one representation of the test requests. You can also write a task to generate API examples for the documentation from this.
The full response body from any API call in your tests will be stored in #response.body, and you can parse/verify that however you please.
I had this standalone script, enabling me to send xml request, but requiring a server:
require 'rubygems'
require 'net/http'
require 'json'
url = URI.parse('http://localhost:3030/myresource.xml')
request = Net::HTTP::Post.new(url.path)
request.content_type="text/xml"
request.basic_auth('user', 'secret')
request.body = "<?xml version='1.0' encoding='UTF-8'?><somedata><name>Test Name 1</name><description>Some data for testing</description></somedata>"
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
puts response
finally I was able to do this without starting up a server, using rspec 2. Putting this in a spec file under spec/requests enables me to do it in my app without webrat or capybara.
for XML
post("/myresource.xml",
some_xml_string,
{"CONTENT_TYPE" => "text/xml",
"HTTP_AUTHORIZATION" => ActionController::HttpAuthentication::Basic.encode_credentials("user", "secret")})
and JSON
post("/myresource.json",
some_json_string,
{"CONTENT_TYPE" => "application/json",
"HTTP_AUTHORIZATION" => ActionController::HttpAuthentication::Basic.encode_credentials("user", "secret")})
Now I guess I can build the some_xml_string from a remote resource like my documentation xml or json file (some http:// resource), for instance. Yes, it's more to maintain and the test will be fragile. I'll have to think more about this... Changing APIs used by external people isn't something to be taken upon lightly, always a lot of trade-offs. Better suggests are welcome!

Resources