diff --git a/cryptkeeper_test.go b/cryptkeeper_test.go index cd476cc..85980ef 100644 --- a/cryptkeeper_test.go +++ b/cryptkeeper_test.go @@ -129,6 +129,13 @@ func TestCryptString(t *testing.T) { if err != nil || cs.String != "another secret text" { t.Fatalf("UnmarshalJSON failed to provide original value") } + + badJsonBytes := append(jsonBytes, '}') + + err = cs.UnmarshalJSON(badJsonBytes) + if err == nil { + t.Fatalf("UnmarshalJSON with bad json bytes should be failed") + } }) t.Run("Scan", func(t *testing.T) { scannable := "2tHq4GL8r7tTvfk6l2TS8d5nVDXY6ztqz6WTmbmq8ZOJ" @@ -150,6 +157,12 @@ func TestCryptString(t *testing.T) { t.Fatalf("Scan of []byte should have matched 'how are you doing', got: '%s'", csByte.String) } + badScannable := "@tHq4GL8r7tTvfk6l2TS8d5nVDXY6ztqz6WTmbmq8ZOJ" + err = csString.Scan(interface{}(badScannable)) + if err == nil { + t.Fatalf("Scan of bad string should have errored") + } + var csGoofyType CryptString err = csGoofyType.Scan(interface{}(12345)) if err == nil { @@ -306,6 +319,13 @@ func TestCryptBytes(t *testing.T) { if !bytes.Equal(originalBytes, cb.Bytes) { t.Fatalf("UnmarshalJSON should have matched '%s', got: '%s'", originalBytes, cb.Bytes) } + + badJsonBytes := append(jsonBytes, '}') + + err = cb.UnmarshalJSON(badJsonBytes) + if err == nil { + t.Fatalf("UnmarshalJSON with bad json bytes should be failed") + } }) t.Run("Scan", func(t *testing.T) { scannable := "2tHq4GL8r7tTvfk6l2TS8d5nVDXY6ztqz6WTmbmq8ZOJ"