github.com/iDigitalFlame/xmt@v0.5.1/c2/cfg/connect_test.go (about) 1 // Copyright (C) 2020 - 2023 iDigitalFlame 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 // 16 17 package cfg 18 19 import ( 20 "testing" 21 ) 22 23 func TestConnect(t *testing.T) { 24 c := Pack( 25 ConnectIP(1), 26 ConnectTLSEx(10), 27 ConnectTLSExCA(12, []byte("derp1234")), 28 ConnectTLSCerts(13, []byte("testing123"), []byte("456testing")), 29 ConnectMuTLS(14, []byte("derp1234"), []byte("testing123"), []byte("456testing")), 30 ConnectWC2("http://localhost", "host", "", map[string]string{"Test": "", "Content-Type": "text/html"}), 31 ) 32 33 if _, err := c.Build(); err == nil { 34 t.Fatalf("TestConnect(): Invalid build should have failed!") 35 } 36 37 if n := c.Len(); n != 135 { 38 t.Fatalf(`TestConnect(): Len returned invalid size "%d" should ne "135"!`, n) 39 } 40 if c[0] != byte(valIP) || c[1] != 1 { 41 t.Fatalf(`TestConnect(): Invalid byte at position "0:1"!`) 42 } 43 if c[2] != byte(valTLSx) || c[3] != 10 { 44 t.Fatalf(`TestConnect(): Invalid byte at position "2:3"!`) 45 } 46 if c[4] != byte(valTLSxCA) || c[5] != 12 { 47 t.Fatalf(`TestConnect(): Invalid byte at position "4:5"!`) 48 } 49 if c[16] != byte(valTLSCert) { 50 t.Fatalf(`TestConnect(): Invalid byte at position "16"!`) 51 } 52 if c[42] != byte(valMuTLS) { 53 t.Fatalf(`TestConnect(): Invalid byte at position "42"!`) 54 } 55 if c[78] != byte(valWC2) { 56 t.Fatalf(`TestConnect(): Invalid byte at position "78"!`) 57 } 58 }