Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Switched Delivery Service active state to a three-value system, adding a state that will be used to prevent cache servers from deploying DS configuration.

### Fixed
- [#4428](https://github.com/apache/trafficcontrol/issues/4428) *Traffic Ops* Fixed Internal Server Error with POST to `profileparameters` when POST body is empty
- [#7179](https://github.com/apache/trafficcontrol/issues/7179) *Traffic Portal* Fixed search filter for Delivery Service Table
- [#7174](https://github.com/apache/trafficcontrol/issues/7174) *Traffic Portal* Fixed topologies sort (table and Delivery Service's form)
- [#5970](https://github.com/apache/trafficcontrol/issues/5970) *Traffic Portal* Fixed numeric sort in Delivery Service's form for DSCP
Expand Down
12 changes: 12 additions & 0 deletions traffic_ops/testing/api/v3/profile_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const queryParamFormat = "?profileId=%s&parameterId=%s"
func TestProfileParameters(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles, ProfileParameters}, func() {

// This is a one off test to check POST with an empty JSON body
TestPostWithEmptyBody(t)
currentTime := time.Now().UTC().Add(-15 * time.Second)
tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)

Expand Down Expand Up @@ -163,6 +165,16 @@ func TestProfileParameters(t *testing.T) {
})
}

func TestPostWithEmptyBody(t *testing.T) {
resp, err := TOSession.Client.Post(TOSession.URL+"/api/3.0/profileparameters", "application/json", nil)
if err != nil {
t.Fatalf("error sending post to create profile parameter with an empty body: %v", err)
}
if resp.StatusCode != http.StatusBadRequest {
t.Errorf("expected to get a 400 error code, but received %d instead", resp.StatusCode)
}
}

func CreateTestProfileParameters(t *testing.T) {
for _, profile := range testData.Profiles {
profileID := GetProfileID(t, profile.Name)()
Expand Down
12 changes: 12 additions & 0 deletions traffic_ops/testing/api/v4/profile_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
func TestProfileParameters(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles, ProfileParameters}, func() {

// This is a one off test to check POST with an empty JSON body
TestPostWithEmptyBody(t)
currentTime := time.Now().UTC().Add(-15 * time.Second)
tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)

Expand Down Expand Up @@ -172,6 +174,16 @@ func TestProfileParameters(t *testing.T) {
})
}

func TestPostWithEmptyBody(t *testing.T) {
resp, err := TOSession.Client.Post(TOSession.URL+"/api/4.0/profileparameters", "application/json", nil)
if err != nil {
t.Fatalf("error sending post to create profile parameter with an empty body: %v", err)
}
if resp.StatusCode != http.StatusBadRequest {
t.Errorf("expected to get a 400 error code, but received %d instead", resp.StatusCode)
}
}

func TestProfileParameter(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles}, func() {

Expand Down
12 changes: 12 additions & 0 deletions traffic_ops/testing/api/v5/profile_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
func TestProfileParameters(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles, ProfileParameters}, func() {

// This is a one off test to check POST with an empty JSON body
TestPostWithEmptyBody(t)
currentTime := time.Now().UTC().Add(-15 * time.Second)
tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)

Expand Down Expand Up @@ -172,6 +174,16 @@ func TestProfileParameters(t *testing.T) {
})
}

func TestPostWithEmptyBody(t *testing.T) {
resp, err := TOSession.Client.Post(TOSession.URL+"/api/5.0/profileparameters", "application/json", nil)
if err != nil {
t.Fatalf("error sending post to create profile parameter with an empty body: %v", err)
}
if resp.StatusCode != http.StatusBadRequest {
t.Errorf("expected to get a 400 error code, but received %d instead", resp.StatusCode)
}
}

func TestProfileParameter(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles}, func() {

Expand Down
5 changes: 5 additions & 0 deletions traffic_ops/traffic_ops_golang/api/shared_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@ func CreateHandler(creator Creator) http.HandlerFunc {
return
}

if len(data) == 0 {
HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("no request body supplied"), nil)
return
}

objSlice, err := parseMultipleCreates(data, objectType, inf)
if err != nil {
HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err)
Expand Down