github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/util/ui/sanitize_json_test.go (about)

     1  package ui_test
     2  
     3  import (
     4  	. "github.com/liamawhite/cli-with-i18n/util/ui"
     5  
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var _ = Describe("SanitizeJSON", func() {
    11  	It("sanitizes json", func() {
    12  		raw := []byte(`{
    13  			"mytoken": "foo",
    14  			"next_level": {
    15  				"next_pAssword_all": "bar",
    16  				"again": {
    17  					"real password ": "Don't tell nobody, it's banana",
    18  					"token_endpoint": "some url",
    19  					"testtokentest": "banana pants"
    20  				}
    21  			}
    22  		}`)
    23  
    24  		expected := map[string]interface{}{
    25  			"mytoken": RedactedValue,
    26  			"next_level": map[string]interface{}{
    27  				"next_pAssword_all": RedactedValue,
    28  				"again": map[string]interface{}{
    29  					"real password ": RedactedValue,
    30  					"token_endpoint": "some url",
    31  					"testtokentest":  RedactedValue,
    32  				},
    33  			},
    34  		}
    35  
    36  		redacted, err := SanitizeJSON(raw)
    37  		Expect(err).ToNot(HaveOccurred())
    38  		Expect(redacted).To(Equal(expected))
    39  	})
    40  })