github.com/iDigitalFlame/xmt@v0.5.4/c2/z_no_implant_test.go (about) 1 //go:build !implant 2 // +build !implant 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package c2 21 22 import ( 23 "encoding/json" 24 "testing" 25 26 "github.com/iDigitalFlame/xmt/device/local" 27 ) 28 29 func TestMarshal(t *testing.T) { 30 b, err := (&Job{}).MarshalJSON() 31 if err != nil { 32 t.Fatalf(`TestMarshal(): Job.MarshalJSON() returned an error: %s!`, err.Error()) 33 } 34 if len(b) == 0 { 35 t.Fatalf(`TestMarshal(): Job.MarshalJSON() returned an empty byte slice!`) 36 } 37 var v interface{} 38 if err = json.Unmarshal(b, &v); err != nil { 39 t.Fatalf(`TestMarshal(): Unmarshal() Job returned an error: %s!`, err.Error()) 40 } 41 s := NewServer(nil) 42 b, err = s.MarshalJSON() 43 if err != nil { 44 t.Fatalf(`TestMarshal(): Server.MarshalJSON() returned an error: %s!`, err.Error()) 45 } 46 if len(b) == 0 { 47 t.Fatalf(`TestMarshal(): Server.MarshalJSON() returned an empty byte slice!`) 48 } 49 if err = json.Unmarshal(b, &v); err != nil { 50 t.Fatalf(`TestMarshal(): Unmarshal() Server returned an error: %s!`, err.Error()) 51 } 52 l := new(Listener) 53 l.s = s 54 b, err = l.MarshalJSON() 55 if err != nil { 56 t.Fatalf(`TestMarshal(): Listener.MarshalJSON() returned an error: %s!`, err.Error()) 57 } 58 if len(b) == 0 { 59 t.Fatalf(`TestMarshal(): Listener.MarshalJSON() returned an empty byte slice!`) 60 } 61 if err = json.Unmarshal(b, &v); err != nil { 62 t.Fatalf(`TestMarshal(): Unmarshal() Listener returned an error: %s!`, err.Error()) 63 } 64 b, err = (&Session{parent: l, Device: local.Device.Machine}).MarshalJSON() 65 if err != nil { 66 t.Fatalf(`TestMarshal(): Session.MarshalJSON() returned an error: %s!`, err.Error()) 67 } 68 if len(b) == 0 { 69 t.Fatalf(`TestMarshal(): Session.MarshalJSON() returned an empty byte slice!`) 70 } 71 if err = json.Unmarshal(b, &v); err != nil { 72 t.Fatalf(`TestMarshal(): Unmarshal() Session returned an error: %s!`, err.Error()) 73 } 74 }