You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/01/06 20:30:39 UTC

[GitHub] [trafficcontrol] zrhoffman opened a new pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

zrhoffman opened a new pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406


   <!--
   ************ STOP!! ************
   If this Pull Request is intended to fix a security vulnerability, DO NOT submit it! Instead, contact
   the Apache Software Foundation Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://www.apache.org/security/ regarding vulnerability disclosure.
   -->
   ## What does this PR (Pull Request) do?
   <!-- Explain the changes you made here. If this fixes an Issue, identify it by
   replacing the text in the checkbox item with the Issue number e.g.
   
   - [x] This PR fixes #9001 OR is not related to any Issue
   
   ^ This will automatically close Issue number 9001 when the Pull Request is
   merged (The '#' is important).
   
   Be sure you check the box properly, see the "The following criteria are ALL
   met by this PR" section for details.
   -->
   
   - [x] This PR fixes #3514 by adding validation to ensure a parent.config weight parameter is a float<!-- You can check for an issue here: https://github.com/apache/trafficcontrol/issues -->
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this
   Pull Request. Also, feel free to add the name of a tool or script that is
   affected but not on the list.
   
   Additionally, if this Pull Request does NOT affect documentation, please
   explain why documentation is not required. -->
   
   - Documentation
   - Traffic Ops
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your Pull Request. If
   it includes tests (and most should), outline here the steps needed to run the
   tests. If not, lay out the manual testing procedure and please explain why
   tests are unnecessary for this Pull Request. -->
   * Add a parameter
       - named `weight`
       - with config file `parent.config`
       - with a valid float value
   
   * Make sure you cannot create or update a parameter to be
     - named `weight`
     - with config file `parent.config`
     - have a value that does not parse to a valid float
   
   ## The following criteria are ALL met by this PR
   <!-- Check the boxes to signify that the associated statement is true. To
   "check a box", replace the space inside of the square brackets with an 'x'.
   e.g.
   
   - [ x] <- Wrong
   - [x ] <- Wrong
   - [] <- Wrong
   - [*] <- Wrong
   - [x] <- Correct!
   
   -->
   
   - [x] This PR includes tests
   - [x] This PR includes documentation
   - [x] This PR includes an update to CHANGELOG.md OR such an update is not necessary
   - [x] This PR includes any and all required license headers
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://www.apache.org/security/) for details)
   
   
   ## Additional Information
   <!-- If you would like to include any additional information on the PR for
   potential reviewers please put it here.
   
   Some examples of this would be:
   
   - Before and after screenshots/gifs of the Traffic Portal if it is affected
   - Links to other dependent Pull Requests
   - References to relevant context (e.g. new/updates to dependent libraries,
   mailing list records, blueprints)
   
   Feel free to leave this section blank (or, preferably, delete it entirely).
   -->
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
   -->
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r554250192



##########
File path: traffic_ops/testing/api/v3/withobjs_test.go
##########
@@ -32,9 +32,15 @@ func WithObjs(t *testing.T, objs []TCObj, f func()) {
 			withFuncs[obj].Delete(t)
 		}
 	}()
-	for _, obj := range objs {
+	var obj TCObj
+	for _, obj = range objs {
 		withFuncs[obj].Create(t)
 	}
+
+	if _, exists := withNegativeFuncs[obj]; exists {

Review comment:
       I can see how generalizing *negative tests* introduces tech debt if I don't move the negative test data to `tc-negative-fixtures.json` at the same time. Since doing that would be outside the scope of this PR:
   
   * Moved the *invalid parameters* data to `CreateNegativeTestParameters()` in c364546143
   * Removed the generalized *negative tests* stuff in 04b2fb10ae
   
   It can be added back in a future PR that also moves existing negative test data to the JSON file that the PR would add.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r554240214



##########
File path: traffic_ops/traffic_ops_golang/parameter/parameters.go
##########
@@ -21,6 +21,7 @@ package parameter
 
 import (
 	"errors"
+	"github.com/apache/trafficcontrol/lib/go-atscfg"

Review comment:
       Separated that import from the standard library in 63eb27d310




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#issuecomment-760510541


   Rebased to resolve merge conflicts


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r554240086



##########
File path: traffic_ops/testing/api/v3/traffic_control_test.go
##########
@@ -59,3 +59,11 @@ type TrafficControl struct {
 	Users                                             []tc.User                               `json:"users"`
 	InvalidationJobs                                  []tc.InvalidationJobInput               `json:"invalidationJobs"`
 }
+
+// NegativeFixtures - maps to the tc-negative-fixtures.json file

Review comment:
       Made this into a sentence in 5bd6414471.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
rawlinp commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r553484337



##########
File path: traffic_ops/testing/api/v3/withobjs_test.go
##########
@@ -32,9 +32,15 @@ func WithObjs(t *testing.T, objs []TCObj, f func()) {
 			withFuncs[obj].Delete(t)
 		}
 	}()
-	for _, obj := range objs {
+	var obj TCObj
+	for _, obj = range objs {
 		withFuncs[obj].Create(t)
 	}
+
+	if _, exists := withNegativeFuncs[obj]; exists {

Review comment:
       Do we really need a new negative fixtures json file and all this extra `WithObjs` stuff that goes with it? It seems like unnecessary complexity when negative test data has always been defined in the tests themselves.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r553470997



##########
File path: lib/go-tc/tovalidate/rules.go
##########
@@ -15,9 +15,12 @@ package tovalidate
 import (
 	"errors"
 	"fmt"
+	validation "github.com/go-ozzo/ozzo-validation"

Review comment:
       This should come after the standard library imports




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r553570546



##########
File path: traffic_ops/traffic_ops_golang/parameter/parameters.go
##########
@@ -21,6 +21,7 @@ package parameter
 
 import (
 	"errors"
+	"github.com/apache/trafficcontrol/lib/go-atscfg"

Review comment:
       These imports ought to be separate from the standard library

##########
File path: traffic_ops/testing/api/v3/traffic_control_test.go
##########
@@ -59,3 +59,11 @@ type TrafficControl struct {
 	Users                                             []tc.User                               `json:"users"`
 	InvalidationJobs                                  []tc.InvalidationJobInput               `json:"invalidationJobs"`
 }
+
+// NegativeFixtures - maps to the tc-negative-fixtures.json file

Review comment:
       GoDoc should be a complete sentence starting with the documented entity and ending with punctuation.

##########
File path: traffic_ops/testing/api/v3/negative_fixtures_test.go
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v3
+
+import (
+	"encoding/json"
+	"io/ioutil"
+	"os"
+
+	"github.com/apache/trafficcontrol/lib/go-log"
+)
+
+// LoadFixtures ...

Review comment:
       GoDoc should be a complete sentence starting with the documented entity and ending with punctuation.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r553476328



##########
File path: lib/go-tc/tovalidate/rules.go
##########
@@ -15,9 +15,12 @@ package tovalidate
 import (
 	"errors"
 	"fmt"
+	validation "github.com/go-ozzo/ozzo-validation"

Review comment:
       Reordered imports in bbd66b5111.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r554240086



##########
File path: traffic_ops/testing/api/v3/traffic_control_test.go
##########
@@ -59,3 +59,11 @@ type TrafficControl struct {
 	Users                                             []tc.User                               `json:"users"`
 	InvalidationJobs                                  []tc.InvalidationJobInput               `json:"invalidationJobs"`
 }
+
+// NegativeFixtures - maps to the tc-negative-fixtures.json file

Review comment:
       Made this into a sentence in 5bd6414471.

##########
File path: traffic_ops/testing/api/v3/negative_fixtures_test.go
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v3
+
+import (
+	"encoding/json"
+	"io/ioutil"
+	"os"
+
+	"github.com/apache/trafficcontrol/lib/go-log"
+)
+
+// LoadFixtures ...

Review comment:
       Added a sentence in 5bd6414471.

##########
File path: traffic_ops/traffic_ops_golang/parameter/parameters.go
##########
@@ -21,6 +21,7 @@ package parameter
 
 import (
 	"errors"
+	"github.com/apache/trafficcontrol/lib/go-atscfg"

Review comment:
       Separated that import from the standard library in 63eb27d310

##########
File path: traffic_ops/testing/api/v3/withobjs_test.go
##########
@@ -32,9 +32,15 @@ func WithObjs(t *testing.T, objs []TCObj, f func()) {
 			withFuncs[obj].Delete(t)
 		}
 	}()
-	for _, obj := range objs {
+	var obj TCObj
+	for _, obj = range objs {
 		withFuncs[obj].Create(t)
 	}
+
+	if _, exists := withNegativeFuncs[obj]; exists {

Review comment:
       I can see how generalizing *negative tests* introduces tech debt if I don't move the negative test data to `tc-negative-fixtures.json` at the same time. Since doing that would be outside the scope of this PR:
   
   * Moved the *invalid parameters* data to `CreateNegativeTestParameters()` in c364546143
   * Removed the generalized *negative tests* stuff in 04b2fb10ae
   
   It can be added back in a future PR that also moves existing negative test data to the JSON file that the PR would add.

##########
File path: traffic_ops/testing/api/v3/withobjs_test.go
##########
@@ -32,9 +32,15 @@ func WithObjs(t *testing.T, objs []TCObj, f func()) {
 			withFuncs[obj].Delete(t)
 		}
 	}()
-	for _, obj := range objs {
+	var obj TCObj
+	for _, obj = range objs {
 		withFuncs[obj].Create(t)
 	}
+
+	if _, exists := withNegativeFuncs[obj]; exists {

Review comment:
       I can see how generalizing *negative tests* introduces tech debt if we don't move the negative test data to `tc-negative-fixtures.json` at the same time. Since doing that would be outside the scope of this PR:
   
   * Moved the *invalid parameters* data to `CreateNegativeTestParameters()` in c364546143
   * Removed the generalized *negative tests* stuff in 04b2fb10ae
   
   It can be added back in a future PR that also moves existing negative test data to the JSON file that the PR would add.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r554240137



##########
File path: traffic_ops/testing/api/v3/negative_fixtures_test.go
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v3
+
+import (
+	"encoding/json"
+	"io/ioutil"
+	"os"
+
+	"github.com/apache/trafficcontrol/lib/go-log"
+)
+
+// LoadFixtures ...

Review comment:
       Added a sentence in 5bd6414471.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406#discussion_r554250192



##########
File path: traffic_ops/testing/api/v3/withobjs_test.go
##########
@@ -32,9 +32,15 @@ func WithObjs(t *testing.T, objs []TCObj, f func()) {
 			withFuncs[obj].Delete(t)
 		}
 	}()
-	for _, obj := range objs {
+	var obj TCObj
+	for _, obj = range objs {
 		withFuncs[obj].Create(t)
 	}
+
+	if _, exists := withNegativeFuncs[obj]; exists {

Review comment:
       I can see how generalizing *negative tests* introduces tech debt if we don't move the negative test data to `tc-negative-fixtures.json` at the same time. Since doing that would be outside the scope of this PR:
   
   * Moved the *invalid parameters* data to `CreateNegativeTestParameters()` in c364546143
   * Removed the generalized *negative tests* stuff in 04b2fb10ae
   
   It can be added back in a future PR that also moves existing negative test data to the JSON file that the PR would add.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 merged pull request #5406: Add TO validation to ensure a parent.config weight parameter is a float

Posted by GitBox <gi...@apache.org>.
ocket8888 merged pull request #5406:
URL: https://github.com/apache/trafficcontrol/pull/5406


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org