Can I use Karate to test URLs with multiple subsequent slashes? [duplicate] - karate

This question already has an answer here:
Karate : How to send query param without url encoding
(1 answer)
Closed 1 year ago.
I'm trying to use Karate to check the behavior of our server when paths contain multiple slashes, so I have a test like
Scenario: Multiple slashes
* url 'http://localhost'
Given path '///some//path///'
When method get
Then status 404
When running this, the Karate output/log contains all the slashes:
12:04:52.307 [pool-1-thread-1] DEBUG com.intuit.karate - request:
1 > GET http://localhost///some//path///
1 > Host: localhost
But according to the server log (simply using Apache for this demo), the actual request just has single slashes:
127.0.0.1 - - [23/Aug/2021:12:04:52 +0200] "GET /some/path/ HTTP/1.1" 404 488 "-" "Apache-HttpClient/4.5.13 (Java/11.0.4)"
So I have several questions:
Is that slash normalization the expected (and documented?) behavior?
Can I switch it off somewhere?
If the slashes are collapsed, shouldn't the log contain the actual (normalized) request, so that I see what's really sent to the server?

You can see if this thread answers your question, combined with the path keyword (scroll to the end): https://github.com/intuit/karate/issues/1561
If not, you can assume this is not directly supported. Personally I don't think such use-cases are worth automating with Karate.
Work-arounds are to make your own HTTP call by integrating any Java lib (via Karate interop) or using cURL (hack): https://stackoverflow.com/a/64352676/143475
You are welcome to contribute code to Karate.

Related

Karate WebSocket connection failed due to extension negotiation error [duplicate]

This question already has an answer here:
How can I integrate socket.io on Karate
(1 answer)
Closed 1 year ago.
Got the following exception when connecting to a WebSocket server with karate.webSocket():
org.graalvm.polyglot.PolyglotException: karate.io.netty.handler.codec.CodecException: invalid WebSocket Extension handshake for "permessage-deflate; server_no_context_takeover; client_no_context_takeover"
- com.intuit.karate.http.WebSocketClient.<init>(WebSocketClient.java:144)
- com.intuit.karate.core.ScenarioEngine.webSocket(ScenarioEngine.java:731)
- com.intuit.karate.core.ScenarioBridge.webSocket(ScenarioBridge.java:861)
The server response has the header
Sec-WebSocket-Extensions: permessage-deflate; server_no_context_takeover; client_no_context_takeover
According to the spec https://www.rfc-editor.org/rfc/rfc7692#section-7.1.1.1, a server may include this in the response header.
Tried to specify the same header in the options but still failed.
Is there a way to work around this?
It certainly can be a case we don't support yet. It would be great if you can follow this process and hopefully you can find a public end-point to simulate or try to create a local way - ideally via java / netty or you can use some JS lib etc if that's more convenient.
Instructions: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
Of course if you can also provide pointers or a PR, nothing like it. Here is an example of a similar conversation in the past: Is there a way to use custom headers when opening WebSocket connection?

Jmeter Illegal character found in host: '/' ISSUE

I tried to install Jmeter on my colleague computer when I executed http request.He has been showing this error, but I found that there is no such error in my computer. I wonder if anyone has encountered a similar problem?
My
My1
My2
Colleague
colleague1
colleague2
--
error message
java.net.MalformedURLException: Illegal character found in host: '/'
at java.base/java.net.URL.<init>(URL.java:480)
at java.base/java.net.URL.<init>(URL.java:360)
at java.base/java.net.URL.<init>(URL.java:383)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.getUrl(HTTPSamplerBase.java:1053)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1231)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1220)
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
at java.base/java.lang.Thread.run(Thread.java:830)
This problem occurs when using the http request sampler, putting '/' at the end of the Server Name or Ip textbox. It will work if you delete the '/' character at the end of the host information and add it to path.
This www.amazon.com/ref=nav_logo is not a valid hostname
Valid characters for hostnames are ASCII(7) letters
from a to z, the digits from 0 to 9, and the hyphen (-). A hostname
may not start with a hyphen.
In any case your URL query string is not correct, it should look like:
https://www.amazon.com/?ref=nav_logo
^mind this character
So correct HTTP Request sampler configuration would be:
Resulting into the following request observable via View Results Tree listener
Going forward be aware that you can build a JMeter Test Plan using HTTP(S) Test Script Recorder or JMeter Chrome Extension
Even though I cannot tell you why the test behaves differently on your machine vs that of your colleaugue (I would guess that you probably chose different client implementations in the advanced section of the HTTP Request Sampler), you should definitely consider what part of your URL is:
Protocol
Server Name or IP
Path
Parameter
and use the corresponding fields in JMeter accordingly.
Hint: "/ref=nav_logo" is most definitely NOT part of the Server Name.
I faced this issue and it was for simple reason. in the server name/ip address instead giving only the severname/ip address i.e server1 i had accidentally included the https://server1 and spend two hours to resolve it

How does apache 2 server process http GET request?

I was trying an IOT project where in I want to update the database remotely using ESP8266-01 module. I have the php file to update the database, but to execute that I am trying with GET method. Unfortunately, it wan't working. The server received the request in the access.log, but wan't updating the database. Wanted to debug, so I had this question.
The entry in the access.log is as follows:
192.168.43.150 - - [18/Mar/2017:20:23:40 +0000] "GET collectdata.php?status=1 HTTP/1.1\r\nHost: 192.168.43.92\r\n\r\n" 400 0 "-" "-"
This looks wrong: GET collectdata.php...
That needs to be a full path, eg. GET /collectdata.php or GET /scripts/collectdata.php, or similar.
The 400 response code you're seeing in the log means "Bad request", and the lack of a leading slash (and the rest of the path, if needed) is what Apache is complaining about.

How to debug a 404 error on apache server ( lamp )?

I came across 404 error a few times and i have difficulties in debugging this kind of problem.
What is the strategy and tools available to analyse such problems (firebug, logs...).
How to differentiate and fix the cause ?
page not existing ,wrong path , redirection and rewriting ,server problem ...
404 error code means that a file is not found for whatever reason.
Just check that the file exists and that the path you use is right.
You can analyse sent requests and received responses headers and body in your browser's developper console if you want more details about why some request failed.

Express.js: how to get assets gzipped

I use compress() middleware, put it the first in configure().
app.configure('all', function(){
app.use(express.compress());
...
app.use(express.static('public'), { maxAge: oneMonth });
})
How do I check that my content is gzipped? I've got a fricking strange situation:
1) On my dev machine: I reqeust localhost:4000/mystyle.css - DON'T see Content-encoding: gzip
2) When I deploy it on production if I request the file it self mydomain.com/mystyle.css - I SEE there see Content-encoding: gzip
3) I request mydomain.com and see in Network in chrome dev tools, find there mystyle.css and there I DON'T see Content-encoding: gzip
4) I use different services to check if my content is gzipped some says that it IS, some that it IS NOT.
WTF? Can some one explain?
Your issue is your use of app.configure. This is largely deprecated, but you're specifically using it such that you're looking for an all environment.
The documentation explains: "This method remains for legacy reason, and is effectively an if statement as illustrated in the following snippets."
Instead, just use the app.use without wrapping them in a configure statement.