English 中文(简体)
Status code of 426 is returned instead of 200 when getting a simple endpoint from an Express app (in localhost) using Karate
原标题:

I have written a simple Express app. I am trying out Karate for API Testing, when I try to get a certain endpoint (literally GET) im expecting a response of status code 200 and the json test data for that endpoint. However, I am getting a 426 instead.

Here is the karate feature file

Feature: Test 

  Background:
    * url  http://localhost:3000 

  Scenario: Read users
    Given path  users 
    And header Upgrade =  HTTP/1.0 
    And header Connection =  Upgrade 
    And header Accept =  application/json 
    And header Accept-Encoding =  gzip, deflate 
    And header Connection =  keep-alive 
    When method get
    Then status 200


    * print response
    * print response.headers

I only have one dependency in pom.xml:

<dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-junit5</artifactId>
            <version>1.4.1.RC2</version>
            <scope>test</scope>
        </dependency>

The express app:

const port = 3000

    var testData = [
            {
              "name": "John Mayer",
              "info": {
               "title": "Mr.",
               "age": "35",
               "phone": "23423423-23423",
                "email": "jmayer@test.com"
            },
            "id":"old001"
        }
    ]
    
    app.listen(port, () => {
        console.log(`Server listening on port ${port}`)
    })
    
    
    app.get( /users , (req, res) => {
        console.log(req.protocol)
        res.status(200).send(testData)
    })

When I try this with Postman I get a 200 and the expected json test data.

I tried adding the Upgrade and Connection headers in the Karate feature too but I m still getting a 426 status code.

问题回答

暂无回答




相关问题
intercept a log from winstonjs and inject arguments

Is it possible to inject an argument into a log such as error, debug or info using the winston configuration (createLogger)? I d like to be able to intercept the log and inject an object into each log

Why can t I pass my token without hardcoding?

If I hardcode the token from console.log(token); it works but doesn t work like this const jwt = require( jsonwebtoken ); module.exports = async (req, res, next) => { const authorization = req....

Writing to files in Node.js

I ve been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?