github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/obfuscate_test.go (about) 1 package internal 2 3 import ( 4 "testing" 5 ) 6 7 func TestDeobfuscate(t *testing.T) { 8 var out []byte 9 var err error 10 11 for _, in := range []string{"", "foo"} { 12 out, err = deobfuscate(in, []byte("")) 13 if err == nil { 14 t.Error("error is nil for an empty key") 15 } 16 if out != nil { 17 t.Errorf("out is not nil; got: %s", out) 18 } 19 } 20 21 for _, in := range []string{"invalid_base64", "=moreinvalidbase64", "xx"} { 22 out, err = deobfuscate(in, []byte("")) 23 if err == nil { 24 t.Error("error is nil for invalid base64") 25 } 26 if out != nil { 27 t.Errorf("out is not nil; got: %s", out) 28 } 29 } 30 31 for _, test := range []struct { 32 input string 33 key string 34 expected string 35 }{ 36 {"", "BLAHHHH", ""}, 37 {"NikyPBs8OisiJg==", "BLAHHHH", "testString"}, 38 } { 39 out, err = deobfuscate(test.input, []byte(test.key)) 40 if err != nil { 41 t.Errorf("error expected to be nil; got: %v", err) 42 } 43 if string(out) != test.expected { 44 t.Errorf("output mismatch; expected: %s; got: %s", test.expected, out) 45 } 46 } 47 } 48 49 func TestObfuscate(t *testing.T) { 50 var out string 51 var err error 52 53 for _, in := range []string{"", "foo"} { 54 out, err = obfuscate([]byte(in), []byte("")) 55 if err == nil { 56 t.Error("error is nil for an empty key") 57 } 58 if out != "" { 59 t.Errorf("out is not an empty string; got: %s", out) 60 } 61 } 62 63 for _, test := range []struct { 64 input string 65 key string 66 expected string 67 }{ 68 {"", "BLAHHHH", ""}, 69 {"testString", "BLAHHHH", "NikyPBs8OisiJg=="}, 70 } { 71 out, err = obfuscate([]byte(test.input), []byte(test.key)) 72 if err != nil { 73 t.Errorf("error expected to be nil; got: %v", err) 74 } 75 if out != test.expected { 76 t.Errorf("output mismatch; expected: %s; got: %s", test.expected, out) 77 } 78 } 79 }