apache / trafficcontrol

Apache Traffic Control is an Open Source implementation of a Content Delivery Network
https://trafficcontrol.apache.org/
Apache License 2.0
1.03k stars 339 forks source link

Servers PUT handler returns API v2 servers when requested at v1 #5289

Closed ocket8888 closed 3 years ago

ocket8888 commented 3 years ago

I'm submitting a ...

Traffic Control components affected ...

Current behavior:

When modifying a server by requesting API version 1, the server will respond (on success) with an APIv2 server structure.

Expected behavior:

The API should respond to APIv1 requests with APIv1 structures only.

Minimal reproduction of the problem with instructions:

Modify a server using APIv1, notice the response includes fields only added in APIv2.

Anything else:

HTTP Stack ```http PUT /api/1.4/servers/6 HTTP/1.1 User-Agent: python-requests/2.24.0 Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive Cookie: mojolicious=... Content-Length: 937 { "cachegroup": "CDN_in_a_Box_Edge", "ipNetmask": "2.2.2.2", "ipGateway": "3.3.3.3", "cachegroupId": 1, "cdnId": 1, "cdnName": "CDN-in-a-Box", "domainName": "infra.ciab.test", "guid": null, "hostName": "test", "httpsPort": 443, "iloIpAddress": "", "iloIpGateway": "", "iloIpNetmask": "", "iloPassword": "", "iloUsername": "", "mgmtIpAddress": "", "mgmtIpGateway": "", "mgmtIpNetmask": "", "offlineReason": "", "physLocation": "Apachecon North America 2018", "physLocationId": 2, "profile": "ATS_EDGE_TIER_CACHE", "profileDesc": "Edge Cache - Apache Traffic Server", "profileId": 8, "rack": "a new rack", "revalPending": false, "routerHostName": "", "routerPortName": "", "status": "REPORTED", "statusId": 3, "tcpPort": 80, "type": "EDGE", "typeId": 11, "updPending": false, "xmppId": "edge", "xmppPasswd": "", "ipAddress": "1.1.1.1", "interfaceMtu": 1281, "ip6Address": "::1", "interfaceName": "eth0" } HTTP/1.1 200 OK Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE Access-Control-Allow-Origin: * Content-Encoding: gzip Content-Type: application/json Set-Cookie: mojolicious=...; Path=/; Expires=Tue, 17 Nov 2020 02:44:52 GMT; Max-Age=3600; HttpOnly Vary: Accept-Encoding X-Server-Name: traffic_ops_golang/ Date: Tue, 17 Nov 2020 01:44:52 GMT Content-Length: 495 { "alerts": [ { "text": "Server updated", "level": "success" } ], "response": { "interfaceMtu": 1281, "interfaceName": "eth0", "ip6Address": "::1", "ip6Gateway": null, "ipAddress": "1.1.1.1", "ipGateway": "3.3.3.3", "ipNetmask": "2.2.2.2", "cachegroup": "test", "cachegroupId": 1, "cdnId": 1, "cdnName": "ALL", "domainName": "infra.ciab.test", "guid": null, "hostName": "test", "httpsPort": 443, "id": 6, "iloIpAddress": "", "iloIpGateway": "", "iloIpNetmask": "", "iloPassword": "", "iloUsername": "", "lastUpdated": "2020-11-17 01:44:52+00", "mgmtIpAddress": "", "mgmtIpGateway": "", "mgmtIpNetmask": "", "offlineReason": "", "physLocation": "test", "physLocationId": 2, "profile": "RIAK_ALL", "profileDesc": "Riak profile for all CDNs", "profileId": 8, "rack": "a new rack", "revalPending": false, "routerHostName": "", "routerPortName": "", "status": "REPORTED", "statusId": 3, "tcpPort": 80, "type": "EDGE", "typeId": 11, "updPending": false, "xmppId": "edge", "xmppPasswd": "", "ipIsService": true, "ip6IsService": true } } ```
ocket8888 commented 3 years ago

This bug manifests because the PUT handler is checking the API minor version instead of its major version. As a result, it does not occur when requesting at API version 1.1