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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7277](https://github.com/apache/trafficcontrol/pull/7277) *Traffic Control Cache Config (t3c)* remapdotconfig: remove skip check at mids for nocache/live
- [#7282](https://github.com/apache/trafficcontrol/pull/7282) *Traffic Ops* Fixed issue with user getting correctly logged when using an access or bearer token authentication.
- [#7346](https://github.com/apache/trafficcontrol/pull/7346) *Traffic Control Cache Config (t3c)* Fixed issue with stale lock file when using git to track changes.
- [#7352](https://github.com/apache/trafficcontrol/pull/7352) *Traffic Control Cache Config (t3c)* Fixed issue with application locking which would allow multiple instances of *t3c apply* to run concurrently.
- [#7352](https://github.com/apache/trafficcontrol/pull/7352) *Traffic Control Cache Config (t3c)* Fixed issue with application locking which would allow multiple instances of `t3c apply` to run concurrently.
- [#6775](https://github.com/apache/trafficcontrol/issues/6775) *Traffic Ops* Invalid "orgServerFqdn" in Delivery Service creation/update causes Internal Server Error

## [7.0.0] - 2022-07-19
### Added
Expand Down
2 changes: 2 additions & 0 deletions traffic_ops/testing/api/v3/tc-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
"initialDispersion": 1,
"logsEnabled": true,
"longDesc": "long desc",
"orgServerFqdn": "http://example.test",
"regionalGeoBlocking": true,
"routingName": "goodroute",
"tenant": "tenant1",
Expand All @@ -334,6 +335,7 @@
"initialDispersion": 1,
"logsEnabled": true,
"longDesc": "long desc",
"orgServerFqdn": "http://example2.test",
"regionalGeoBlocking": true,
"routingName": "goodroute",
"tenant": "tenant1",
Expand Down
42 changes: 24 additions & 18 deletions traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,9 @@ func requiredIfMatchesTypeName(patterns []string, typeName string) func(interfac
return nil
case *string:
if v != nil {
return nil
if *v != "" {
return nil
}
}
case *float64:
if v != nil {
Expand Down Expand Up @@ -1690,15 +1692,19 @@ func validateOrgServerFQDN(orgServerFQDN string) bool {
return true
}

func validateTypeFields(tx *sql.Tx, ds *tc.DeliveryServiceV5) error {
// Validate the TypeName related fields below
err := error(nil)
DNSRegexType := "^DNS.*$"
HTTPRegexType := "^HTTP.*$"
SteeringRegexType := "^STEERING.*$"
latitudeErr := "Must be a floating point number within the range +-90"
longitudeErr := "Must be a floating point number within the range +-180"
const (
dnsTypeRegexp = "^DNS.*$"
httpTypeRegexp = "^HTTP.*$"
steeringTypeRegexp = "^STEERING.*$"
)

const (
latitudeErr = "Must be a floating point number within the range +-90"
longitudeErr = "Must be a floating point number within the range +-180"
)

// validateTypeFields validates the TypeName-related field.
func validateTypeFields(tx *sql.Tx, ds *tc.DeliveryServiceV5) error {
typeName, err := tc.ValidateTypeID(tx, &ds.TypeID, "deliveryservice")
if err != nil {
return err
Expand All @@ -1714,22 +1720,22 @@ func validateTypeFields(tx *sql.Tx, ds *tc.DeliveryServiceV5) error {
return fmt.Errorf("consistentHashQueryParams not allowed for '%s' deliveryservice type", typeName)
})),
"initialDispersion": validation.Validate(ds.InitialDispersion,
validation.By(requiredIfMatchesTypeName([]string{HTTPRegexType}, typeName)),
validation.By(requiredIfMatchesTypeName([]string{httpTypeRegexp}, typeName)),
validation.By(tovalidate.IsGreaterThanZero)),
"ipv6RoutingEnabled": validation.Validate(ds.IPV6RoutingEnabled,
validation.By(requiredIfMatchesTypeName([]string{SteeringRegexType, DNSRegexType, HTTPRegexType}, typeName))),
validation.By(requiredIfMatchesTypeName([]string{steeringTypeRegexp, dnsTypeRegexp, httpTypeRegexp}, typeName))),
"missLat": validation.Validate(ds.MissLat,
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName)),
validation.By(requiredIfMatchesTypeName([]string{dnsTypeRegexp, httpTypeRegexp}, typeName)),
validation.Min(-90.0).Error(latitudeErr),
validation.Max(90.0).Error(latitudeErr)),
"missLong": validation.Validate(ds.MissLong,
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName)),
validation.By(requiredIfMatchesTypeName([]string{dnsTypeRegexp, httpTypeRegexp}, typeName)),
validation.Min(-180.0).Error(longitudeErr),
validation.Max(180.0).Error(longitudeErr)),
"multiSiteOrigin": validation.Validate(ds.MultiSiteOrigin,
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName))),
validation.By(requiredIfMatchesTypeName([]string{dnsTypeRegexp, httpTypeRegexp}, typeName))),
"orgServerFqdn": validation.Validate(ds.OrgServerFQDN,
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName)),
validation.By(requiredIfMatchesTypeName([]string{dnsTypeRegexp, httpTypeRegexp}, typeName)),
validation.NewStringRule(validateOrgServerFQDN, "must start with http:// or https:// and be followed by a valid hostname with an optional port (no trailing slash)")),
"rangeSliceBlockSize": validation.Validate(ds,
validation.By(func(dsi interface{}) error {
Expand All @@ -1749,11 +1755,11 @@ func validateTypeFields(tx *sql.Tx, ds *tc.DeliveryServiceV5) error {
return nil
})),
"protocol": validation.Validate(ds.Protocol,
validation.By(requiredIfMatchesTypeName([]string{SteeringRegexType, DNSRegexType, HTTPRegexType}, typeName))),
validation.By(requiredIfMatchesTypeName([]string{steeringTypeRegexp, dnsTypeRegexp, httpTypeRegexp}, typeName))),
"qstringIgnore": validation.Validate(ds.QStringIgnore,
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName))),
validation.By(requiredIfMatchesTypeName([]string{dnsTypeRegexp, httpTypeRegexp}, typeName))),
"rangeRequestHandling": validation.Validate(ds.RangeRequestHandling,
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName))),
validation.By(requiredIfMatchesTypeName([]string{dnsTypeRegexp, httpTypeRegexp}, typeName))),
"tlsVersions": validation.Validate(
&ds.TLSVersions,
validation.By(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,25 @@ func TestReadGetDeliveryServices(t *testing.T) {
t.Errorf("Unexpected system error reading Delivery Services: %v", sysErr)
}
}

func TestRequiredIfTypeMatchesName(t *testing.T) {
ds := &tc.DeliveryServiceV50{
OrgServerFQDN: new(string),
Protocol: new(int),
InitialDispersion: new(int),
MissLat: new(float64),
MissLong: new(float64),
RangeRequestHandling: new(int),
QStringIgnore: new(int),
MaxRequestHeaderBytes: new(int),
IPV6RoutingEnabled: new(bool),
}
*ds.InitialDispersion = 1
fn := requiredIfMatchesTypeName([]string{httpTypeRegexp, dnsTypeRegexp}, "HTTP")
err := fn(ds.OrgServerFQDN)
if err == nil {
t.Error("Failed to raise an error when the orgserver fqdn is empty")
} else {
t.Logf("Got expected error: %v", err)
}
}