SoapUI testing: remove quotation marks from session ID - testing

So, I am new to SoapUI, and working with API's in general, but I am trying to set up an automated test for a REST API in SoapUI (the freeware version).
The first call I make returns a session ID in JSON, which is placed between quotation markslike: "session ID goes here". This key is needed, without quotation marks, in the next API call. I use SOAPUI's "Property Transfer Teststep", and this is working well, apart from the quotationmarks which are still around the session ID, resulting in an error responce by the subsequent call.
Any idea how I can remove the quotation marks? Ive been reading up/Googling on Xpath and JSONPath, which are some of the coding languages I can use in the screen, but I cant see how to use this to remove said quotation marks.
Your help would be greatly appreciated!!
Full RAW Response:
HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Tue, 02 May 2017 18:31:48 GMT Content-Length: 38 "48d45ba2-4549-41be-8b31-e85b3c738a03"

you say that the message is returned as "48d45ba2-4549-41be-8b31-e85b3c738a03". Although the message says it is json, that does not mean that SoapUI will interprete it as valid json. Valid JSON like in the question referred to in another answer, starts and ends with curly brackets. Also it should have a key and value pair. Like so:
{
"sessionId":"48d45ba2-4549-41be-8b31-e85b3c738a03"
}
In that case the transfer $.sessionId would yield 48d45ba2-4549-41be-8b31-e85b3c738a03(without quotation marks), and not "48d45ba2-4549-41be-8b31-e85b3c738a03" (with quotation marks).
In attachment there is a project with a mock. It has got one call. If you open the project, you have to launch the mock by clicking play, then you can execute the test case. - https://www.dropbox.com/s/rsgc9q1g45jze5z/StackOverflow_43745255_QuestionQuotationMarks.xml?dl=0. You can save this as XML, then you can open it with SoapUI.
You will see a property transfer step. It has one step that is passed. Then one where you transfer the value without any paramter. It will transfer the message in full. Including the quotation marks.
The sencond transfer is '$'. For a valid json, this would render the same result as for the property transfer without any parameter because '$' represents the root. At least that is how I understand it.
Included you will also find a script:
response = context.testCase.getTestStepAt(0).testRequest.response.getResponseContent()
assert response == '"48d45ba2-4549-41be-8b31-e85b3c738a03"'
stripResponse = response.replace("\"", "")
assert stripResponse == '48d45ba2-4549-41be-8b31-e85b3c738a03'
The stripResponse is the response where the quotation marks are stripped away. You could then proceed to assign this variable to a property of choice, or inject it directly in the headers of a next step.
Sometimes scripting is the way to go.

Related

Remove Request-Context from Response Header

Somehow in my request response header "Request-Context" coming and i tried to remove that using in web.config and Response.Headers.Remove("Request-Context"); in global.asax but that header is not getting removed.
In the value of that header I am getting some Appid and I am not sure from where that is coming.
Here is response header of my request.
Cache-Control:no-cache, no-store
Content-Encoding:gzip
Content-Length:140
Content-Type:application/json; charset=utf-8
Date:Tue, 20 Feb 2018 09:48:28 GMT
Pragma:no-cache
Request-Context:appId=cid-v1:b650ed48-297a-4ea2-af46-0a5a5d26a82b
Vary:Accept-Encoding
Any help appreciated. Thanks in Advance.
Request-Context is used for cross-component correlation when 2 of your applications use different instrumentation keys.
In this case, knowing caller or callee appId (passed in the header) allows to build application map and trace correlated telemetry across instrumentation keys
You may set RequestTrackingTelemetryModule.SetComponentCorrelationHttpHeaders to false to prevent header to be added to the response.
You can do it in applicationInsights xml file, just find RequestTrackingTelemetryModule element and add false under it.
Refer link: https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/739#issuecomment-367774652

Onenote API (REST) - PATCH append - "must include a 'commands'" error when Commands is already supplied (?!)

Note: I'm pretty sure nothing's wrong with the PATCH query, I had it working before with 'Content-type':'application/json' and a constructed json file:
[
{
'target':'|TARGET_ID|',
'action':'append',
'content':'|HTML|'
}
]
For the purposes of this, the header supplied (authentication bearer is correct and will be omitted)
'Content-type':'multipart/form-data; Boundary=sectionboundary'
(note: Boundary=sectionboundary is in the same line)
Attempting to pass the following body as a PATCH to
https://www.onenote.com/api/v1.0/pages/|GUID|/content
returns a
"code":"20124","message":"A multi-part PATCH request must include a 'commands' part containing the PATCH action JSON structure." :
--sectionboundary
Content-Disposition: form-data; name="Commands"
Content-Type: application/json
[
{
'target':'|TARGET_ID|',
'action':'append',
'content':'|HTML|'
}
]
--sectionboundary
Content-Disposition: form-data; name="image-part-name"
Content-Type: image/png
|BINARY_IMAGE_DATA|
--sectionboundary--
As you can see, there's a Commands section already. Using smallcaps 'commands' doesn't help, and the correct syntax should be "Commands" as per the OneNote Dev Center documentation.
PS: |TARGET_ID| |HTML| |GUID| and |BINARY_DATA| are replaced with the correct content at runtime. Due to privacy constraints, the fact that you may use a different schema than I do, and how long |BINARY_IMAGE_DATA| actually is, I will not show the actual input unless required to solve the problem.
Would like to know if I missed anything - thanks in advance.
PPS: Yes, I realize i've omitted the img tag inside |HTML| somewhere. It shouldn't have anything to do with code 20124, and if I got it wrong should return another thing entirely.
Based on investigating the request information you shared, I can confirm that the PATCH request referenced as part of the correlation you provided does not match your posted header information.
The correlated PATCH request shows up as a multi-part request with only a single part that has Media Type "TEXT/HTML" and not "Application/JSON". Can you please check and confirm your request content ?
Let us continue to discuss this on email. If you still face issues calling the API, please write to me at machandw#microsoft.com
Regards,
Manoj

WCF OData patching an entity set

Is it possible in update multiple entites based on a filter query in a batch request?
As an example of what I'm trying to achieve, say I want to update all product categories from foo to bar in one request to an OData endpoint, is there something like this that would work:
--batch_36522ad7-fc75-4b56-8c71-56071383e77b
Content-Type: multipart/mixed; boundary=changeset_fa7b-4aa9-a01f
GET /api/products?$filter=category eq 'foo' HTTP/1.1
Accept:application/json
Content-ID: 1
--changeset_fa7b-4aa9-a01f
Content-Type: application/http
Content-Transfer-Encoding: binary
PATCH $1 HTTP/1.1
Accept: application/json
Content-Type: application/json;odata=verbose
{"category":"bar"}
--changeset_fa7b-4aa9-a01f--
--batch_36522ad7-fc75-4b56-8c71-56071383e77b--
I'm afraid the answer is no. There's no support for that in the protocol. And even if you remove the filtering from the question, trying to update all entities in the entity set so that they will have a same new value, the answer is still no.
You could probably do this yourself. Like,
Get /service.svc/MyEntitySet
and for every entity you get back, send a PATCH to update it individually.
In addition, if this kind of operation is going to be done frequently, the service author could write a specific service operation or action to do this on the server side. For example, write something called "ClearAllNames", and a user could invoke that, and the server would go through every entity and clear its name field.

getting directly only the contents after the first nth character in vb.net

Is there any way we could get directly say the 1000 characters after the first 5000 characters, skipping everything before that after sending in an HTTP request to an HTTPS page using either GET or POST in VB.NET?
The reason why I ask this question is because in one of the webpage I am trying the get through my program, the website is sending response data in chunks with the first chunk containing some javascript garbage that I have no interest in, the only data I care is in the second chunk and
I have no idea how to get the second chunk after receiving the first one since it is within the same HTTP request
It would save some time and Internet traffic if I can skip the first chunk that I do not need.
Is that possible or I am just day dreaming?
Many thanks!
ADDED:
Here is how a typical header of the response I am getting from the webpage I am trying to get:
Date: Mon, 20 Jun 2011 13:21:56 GMT
Set-Cookie: JSESSIONID=1AF1AF9EF936E1CB2FA85B750EDC67C4; Path=****some path******; Secure
Content-Type: text/html; charset=ISO-8859-1
Transfer-Encoding: chunked
Set-Cookie: **********some cookie***************
path=/
Vary: Accept-Encoding, User-Agent
Not sure if that helps, but as you can see, the chunk size is not visible to me, there is no "Trailer" in the header as well.
Fun little problem. Look at RANGE in the following GET request.
GET /file.txt HTTP/1.1
Host: localhost
Range: bytes=5000-6000
Connection: Close
Edit: Found a HTTP example.
Here is an example in PHP. (Sorry I couldn't find any VB.NET examples).

Why am I not getting the soap header?

Why is this so hard in WCF 4.0
I add a custom header in my client
Authorization: 18732818 gfdsgShoyh3sfayql6jWCRc=
so that my header looks like the following
GET http://HOSTNAME/Public/Xml/SyncReply/TestClearUsername?Id=1 HTTP/1.1
Authorization: 18732818 gfdsgShoyh3sfayql6jWCRc=
Host: HOSTNAME
Connection: Keep-Alive
in my wired up service responder I can access the property Id and get the value 1. I would also like to access the value Authorization, but it always shows as null.
What am I doing wrong?
After much googling I finally found the answer to this so I will post it here so it might be of use to someone else. I am assuming this is an undocumented feature, since it is so well hidden, but someone else might know different.
I found this enumeration System.Web.HttpWorkerRequest.HeaderAuthorization (value=24)
and this method System.Web.HttpWorkerRequest.GetKnownRequestHeader(24)
Just to summarize the reason Authorization was hiding from me was that its a reserved header value. if you add a random word and want to retrieve you can use.
.GetUnknownRequestHeader("YOUR_WORD_HERE").
so in full you need
HttpRequestContext hrc = (HttpRequestContext)this.RequestContext;
RequestAttributes ra = (RequestAttributes)hrc.RequestAttributes;
System.Web.HttpWorkerRequest hwr = ra.HttpWorkerRequest;
string Auth = hwr.GetKnownRequestHeader(System.Web.HttpWorkerRequest.HeaderAuthorization);