fleet icon indicating copy to clipboard operation
fleet copied to clipboard

Add automation for verifying /hosts and /os_versions API endpoints

Open thisisjoegrant opened this issue 4 months ago • 0 comments

API error handling test cases: OS versions & vulnerabilities (#35075)

Test coverage for the three endpoints touched by #35075: GET /hosts/{id}, GET /os_versions, and GET /os_versions/{id}. NOTE: That ticket tested these endpoints specifically for Android version updates, but they should work with any device type.

Partial Blocker: No Android VM set up for QA Wolf to verify Android-specific functionality.

Replace <API Token>, <fleet url>, <valid host ID>, and <valid os_version_id> with real values before running.

Pass/fail criteria: A clean 200 or 4xx response (see each case's Expected response for details) with a JSON error body is a pass. A 500, an unhandled stack trace, or an empty 200 on any negative test case is a bug.

NOTE: -w "\nStatus: %{http_code}\n" in the following commands appends the status code to the end of the response for easy checking.


1. GET /api/v1/fleet/hosts/{id}

Positive

Case Expected
Valid, existing host ID 200 + full host object
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" <fleet url>/api/v1/fleet/hosts/<valid host ID>

Negative

Case Expected
Non-existent host ID 404
Non-numeric host ID 400 or 404
Negative host ID 400 or 404
Zero as host ID 400 or 404
No auth header 401
Malformed/garbage auth token 401
# Non-existent host ID
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" <fleet url>/api/v1/fleet/hosts/999999999

# Non-numeric host ID
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" <fleet url>/api/v1/fleet/hosts/abc

# Negative host ID
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" <fleet url>/api/v1/fleet/hosts/-1

# Zero as host ID
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" <fleet url>/api/v1/fleet/hosts/0

# No auth header
curl -s -w "\nStatus: %{http_code}\n" <fleet url>/api/v1/fleet/hosts/<valid host ID>

# Malformed/garbage auth token
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer not-a-real-token" <fleet url>/api/v1/fleet/hosts/<valid host ID>

2. GET /api/v1/fleet/os_versions

Positive

Case Expected
Valid platform filter (android) 200 + list including Android entries
Valid os_name + os_version together 200 + matching entry
Valid max_vulnerabilities 200, vulnerabilities array capped at given count
No params at all 200 + full unfiltered list
# Valid platform filter
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" "<fleet url>/api/v1/fleet/os_versions?platform=android"

# Valid os_name + os_version together
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" "<fleet url>/api/v1/fleet/os_versions?os_name=Android&os_version=16"

# Valid max_vulnerabilities
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" "<fleet url>/api/v1/fleet/os_versions?platform=android&max_vulnerabilities=5"

# No params at all
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" "<fleet url>/api/v1/fleet/os_versions"

Negative

Case Expected
Invalid platform enum value 400
os_version without required os_name 400
Non-integer max_vulnerabilities 400
Negative max_vulnerabilities 400
Non-existent fleet_id/team_id 400 or empty result set, not a 500
No auth header 401
Malformed/garbage auth token 401
# Invalid platform enum value
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" "<fleet url>/api/v1/fleet/os_versions?platform=notarealplatform"

# os_version without required os_name
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" "<fleet url>/api/v1/fleet/os_versions?os_version=16"

# Non-integer max_vulnerabilities
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" "<fleet url>/api/v1/fleet/os_versions?max_vulnerabilities=abc"

# Negative max_vulnerabilities
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" "<fleet url>/api/v1/fleet/os_versions?max_vulnerabilities=-5"

# Non-existent team_id/fleet_id
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" "<fleet url>/api/v1/fleet/os_versions?fleet_id=999999"

# No auth header
curl -s -w "\nStatus: %{http_code}\n" "<fleet url>/api/v1/fleet/os_versions?platform=android"

# Malformed/garbage auth token
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer not-a-real-token" "/api/v1/fleet/os_versions?platform=android"

3. GET /api/v1/fleet/os_versions/{id}

Positive

Case Expected
Valid, existing OS version ID 200 + full OS version object (including vulnerabilities array)
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" <fleet url>/api/v1/fleet/os_versions/<valid os_version_id>

Negative

Case Expected
Non-existent OS version ID 404
Non-numeric OS version ID 400 or 404
Negative OS version ID 400 or 404
No auth header 401
Malformed/garbage auth token 401
# Non-existent OS version ID
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" <fleet url>/api/v1/fleet/os_versions/999999999

# Non-numeric OS version ID
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" <fleet url>/api/v1/fleet/os_versions/abc

# Negative OS version ID
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer <API Token>" <fleet url>/api/v1/fleet/os_versions/-1

# No auth header
curl -s -w "\nStatus: %{http_code}\n" <fleet url>/api/v1/fleet/os_versions/<valid os_version_id>

# Malformed/garbage auth token
curl -s -w "\nStatus: %{http_code}\n" -H "Authorization: Bearer not-a-real-token" <fleet url>/api/v1/fleet/os_versions/<valid os_version_id>

thisisjoegrant avatar Jul 20 '26 16:07 thisisjoegrant