restored Node.Sanitize() for RPC endpoints

multiple other updates from code review
This commit is contained in:
Chris Baker
2021-03-26 17:03:15 +00:00
parent c5731ebecc
commit a52f32dedc
23 changed files with 121 additions and 99 deletions

View File

@@ -24,7 +24,7 @@ import (
"github.com/hashicorp/nomad/helper/noxssrw"
"github.com/hashicorp/nomad/helper/tlsutil"
"github.com/hashicorp/nomad/nomad/json/handlers"
"github.com/hashicorp/nomad/nomad/jsonhandles"
"github.com/hashicorp/nomad/nomad/structs"
)
@@ -496,13 +496,13 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
if obj != nil {
var buf bytes.Buffer
if prettyPrint {
enc := codec.NewEncoder(&buf, handlers.JsonHandlePretty)
enc := codec.NewEncoder(&buf, jsonhandles.JsonHandlePretty)
err = enc.Encode(obj)
if err == nil {
buf.Write([]byte("\n"))
}
} else {
enc := codec.NewEncoder(&buf, handlers.JsonHandleWithExtensions)
enc := codec.NewEncoder(&buf, jsonhandles.JsonHandleWithExtensions)
err = enc.Encode(obj)
}
if err != nil {

View File

@@ -30,8 +30,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/hashicorp/nomad/nomad/json/handlers"
nomadjson "github.com/hashicorp/nomad/nomad/json/handlers"
"github.com/hashicorp/nomad/nomad/jsonhandles"
)
// makeHTTPServer returns a test server whose logs will be written to
@@ -315,11 +314,11 @@ func testPrettyPrint(pretty string, prettyFmt bool, t *testing.T) {
var expected bytes.Buffer
var err error
if prettyFmt {
enc := codec.NewEncoder(&expected, nomadjson.JsonHandlePretty)
enc := codec.NewEncoder(&expected, jsonhandles.JsonHandlePretty)
err = enc.Encode(r)
expected.WriteByte('\n')
} else {
enc := codec.NewEncoder(&expected, nomadjson.JsonHandleWithExtensions)
enc := codec.NewEncoder(&expected, jsonhandles.JsonHandleWithExtensions)
err = enc.Encode(r)
}
if err != nil {
@@ -1249,13 +1248,13 @@ func Test_decodeBody(t *testing.T) {
// BenchmarkHTTPServer_JSONEncodingWithExtensions benchmarks the performance of
// encoding JSON objects using extensions
func BenchmarkHTTPServer_JSONEncodingWithExtensions(b *testing.B) {
benchmarkJsonEncoding(b, handlers.JsonHandleWithExtensions)
benchmarkJsonEncoding(b, jsonhandles.JsonHandleWithExtensions)
}
// BenchmarkHTTPServer_JSONEncodingWithoutExtensions benchmarks the performance of
// encoding JSON objects using extensions
func BenchmarkHTTPServer_JSONEncodingWithoutExtensions(b *testing.B) {
benchmarkJsonEncoding(b, handlers.JsonHandle)
benchmarkJsonEncoding(b, jsonhandles.JsonHandle)
}
func benchmarkJsonEncoding(b *testing.B, handle *codec.JsonHandle) {