Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

[18.09 backport] API: properly handle invalid JSON to return a 400 status #110

Merged

Commits on Nov 8, 2018

  1. Windows: Start of enabling tests under integration/

    - Add windows CI entrypoint script.
    
    Signed-off-by: John Howard <jhoward@microsoft.com>
    Signed-off-by: Vincent Demeester <vincent@sbr.pm>
    Signed-off-by: Daniel Nephin <dnephin@docker.com>
    Signed-off-by: Vincent Demeester <vincent@sbr.pm>
    (cherry picked from commit d3cc071)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    vdemeester authored and thaJeztah committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    59be980 View commit details
    Browse the repository at this point in the history
  2. Enabling Windows integration tests

    Signed-off-by: Salahuddin Khan <salah@docker.com>
    (cherry picked from commit 4c8b1fd)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    salah-khan authored and thaJeztah committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    37cb9e7 View commit details
    Browse the repository at this point in the history
  3. Renamed windowsRS1.ps1 to windows.ps1

    Signed-off-by: Deep Debroy <ddebroy@docker.com>
    (cherry picked from commit 7d1c1a4)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    ddebroy authored and thaJeztah committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    9fc9c30 View commit details
    Browse the repository at this point in the history
  4. Some improvements to TestVolumesInspect

    Some improvements in this test;
    
    - use the volume-information that's returned by VolumeCreate as "expected"
    - don't use an explict name for the volume, as it was only used to reference
      the volume for inspection
    - improve the test-output on failure, so that "expected" and "actual" values
      are printed
    
    Without this patch applied;
    
        === RUN   TestVolumesInspect
        --- FAIL: TestVolumesInspect (0.02s)
         	volume_test.go:108: assertion failed: false (bool) != true (true bool): Time Volume is CreatedAt not equal to current time
        FAIL
    
    With this patch applied;
    
        === RUN   TestVolumesInspect
        --- FAIL: TestVolumesInspect (0.02s)
            volume_test.go:95: assertion failed: expression is false: createdAt.Truncate(time.Minute).Equal(now.Truncate(time.Minute)): CreatedAt (2018-11-01 16:15:20 +0000 UTC) not equal to creation time (2018-11-01 16:15:20.2421166 +0000 UTC m=+13.733512701)
        FAIL
    
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    (cherry picked from commit 8e8cac8)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    65bf95f View commit details
    Browse the repository at this point in the history
  5. Integration test: use filepath.Join() to make path cross-platform

    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    (cherry picked from commit 05e1842)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    673f04f View commit details
    Browse the repository at this point in the history
  6. Enable volume tests on Windows

    These tests don't seem to have anything Linux-specific,
    so enable them on Windows
    
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    (cherry picked from commit b334198)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    e8eb3ca View commit details
    Browse the repository at this point in the history
  7. API: properly handle invalid JSON to return a 400 status

    The API did not treat invalid JSON payloads as a 400 error, as a result
    returning a 500 error;
    
    Before this change, an invalid JSON body would return a 500 error;
    
    ```bash
    curl -v \
      --unix-socket /var/run/docker.sock \
      -X POST \
      "http://localhost/v1.30/networks/create" \
      -H "Content-Type: application/json" \
      -d '{invalid json'
    ```
    
    ```
    > POST /v1.30/networks/create HTTP/1.1
    > Host: localhost
    > User-Agent: curl/7.52.1
    > Accept: */*
    > Content-Type: application/json
    > Content-Length: 13
    >
    * upload completely sent off: 13 out of 13 bytes
    < HTTP/1.1 500 Internal Server Error
    < Api-Version: 1.40
    < Content-Type: application/json
    < Docker-Experimental: false
    < Ostype: linux
    < Server: Docker/dev (linux)
    < Date: Mon, 05 Nov 2018 11:55:20 GMT
    < Content-Length: 79
    <
    {"message":"invalid character 'i' looking for beginning of object key string"}
    ```
    
    Empty request:
    
    ```bash
    curl -v \
      --unix-socket /var/run/docker.sock \
      -X POST \
      "http://localhost/v1.30/networks/create" \
      -H "Content-Type: application/json"
    ```
    
    ```
    > POST /v1.30/networks/create HTTP/1.1
    > Host: localhost
    > User-Agent: curl/7.54.0
    > Accept: */*
    > Content-Type: application/json
    >
    < HTTP/1.1 500 Internal Server Error
    < Api-Version: 1.38
    < Content-Length: 18
    < Content-Type: application/json
    < Date: Mon, 05 Nov 2018 12:00:18 GMT
    < Docker-Experimental: true
    < Ostype: linux
    < Server: Docker/18.06.1-ce (linux)
    <
    {"message":"EOF"}
    ```
    
    After this change, a 400 is returned;
    
    ```bash
    curl -v \
      --unix-socket /var/run/docker.sock \
      -X POST \
      "http://localhost/v1.30/networks/create" \
      -H "Content-Type: application/json" \
      -d '{invalid json'
    ```
    
    ```
    > POST /v1.30/networks/create HTTP/1.1
    > Host: localhost
    > User-Agent: curl/7.52.1
    > Accept: */*
    > Content-Type: application/json
    > Content-Length: 13
    >
    * upload completely sent off: 13 out of 13 bytes
    < HTTP/1.1 400 Bad Request
    < Api-Version: 1.40
    < Content-Type: application/json
    < Docker-Experimental: false
    < Ostype: linux
    < Server: Docker/dev (linux)
    < Date: Mon, 05 Nov 2018 11:57:15 GMT
    < Content-Length: 79
    <
    {"message":"invalid character 'i' looking for beginning of object key string"}
    ```
    
    Empty request:
    
    ```bash
    curl -v \
      --unix-socket /var/run/docker.sock \
      -X POST \
      "http://localhost/v1.30/networks/create" \
      -H "Content-Type: application/json"
    ```
    
    ```
    > POST /v1.30/networks/create HTTP/1.1
    > Host: localhost
    > User-Agent: curl/7.52.1
    > Accept: */*
    > Content-Type: application/json
    >
    < HTTP/1.1 400 Bad Request
    < Api-Version: 1.40
    < Content-Type: application/json
    < Docker-Experimental: false
    < Ostype: linux
    < Server: Docker/dev (linux)
    < Date: Mon, 05 Nov 2018 11:59:22 GMT
    < Content-Length: 49
    <
    {"message":"got EOF while reading request body"}
    ```
    
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    (cherry picked from commit c7b488f)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    9e06a42 View commit details
    Browse the repository at this point in the history