@@ -6,14 +6,15 @@ package netrc
66
77import (
88 "bytes"
9+ "fmt"
910 "io"
1011 "io/ioutil"
1112 "strings"
1213 "testing"
1314)
1415
1516var expectedMachines = []* Machine {
16- & Machine {
Name :
"mail.google.com" ,
Login :
"[email protected] " ,
Password :
"somethingSecret" ,
Account :
"gmail " },
17+ & Machine {
Name :
"mail.google.com" ,
Login :
"[email protected] " ,
Password :
"somethingSecret" ,
Account :
"justagmail " },
1718 & Machine {Name : "ray" , Login : "demo" , Password : "mypassword" , Account : "" },
1819 & Machine {Name : "weirdlogin" , Login : "uname" , Password : "pass#pass" , Account : "" },
1920 & Machine {
Name :
"" ,
Login :
"anonymous" ,
Password :
"[email protected] " ,
Account :
"" },
@@ -185,6 +186,18 @@ func TestMarshalText(t *testing.T) {
185186 if string (result ) != string (expected ) {
186187 t .Errorf ("expected:\n %q\n got:\n %q" , string (expected ), string (result ))
187188 }
189+
190+ // make sure tokens w/ no value are not serialized
191+ m := n .FindMachine ("mail.google.com" )
192+ m .UpdatePassword ("" )
193+ result , err = n .MarshalText ()
194+ if err != nil {
195+ t .Fatal (err )
196+ }
197+ if strings .Contains (string (result ), "\t password \n " ) {
198+ fmt .Println (string (result ))
199+ t .Errorf ("expected zero-value password token to not be serialzed" )
200+ }
188201}
189202
190203var newMachineTests = []struct {
0 commit comments