mic.git


mic

~ proxy for JA4-TLS fingerprinting evasion
git clone https://github.com/djnnvx/mic.git
log | files | refs | archive | README | LICENSE

client_test.go (1574B)

      1 package cmd
      2 
      3 import (
      4 	"os"
      5 	"path/filepath"
      6 	"strings"
      7 	"testing"
      8 )
      9 
     10 // runClient uses an invalid port so p.Run() fails instead of binding a socket.
     11 func runClient(t *testing.T, args ...string) error {
     12 	t.Helper()
     13 	c := newClientCmd()
     14 	c.SetOut(os.NewFile(0, os.DevNull))
     15 	c.SetErr(os.NewFile(0, os.DevNull))
     16 	c.SetArgs(append([]string{"--listen", "127.0.0.1:99999"}, args...))
     17 	return c.Execute()
     18 }
     19 
     20 func TestGarbageCAFileIsRefused(t *testing.T) {
     21 	path := filepath.Join(t.TempDir(), "ca.pem")
     22 	if err := os.WriteFile(path, []byte("this is not a certificate"), 0o600); err != nil {
     23 		t.Fatal(err)
     24 	}
     25 	err := runClient(t, "--ca", path)
     26 	if err == nil || !strings.Contains(err.Error(), "no certificates found") {
     27 		t.Errorf("garbage CA accepted; got err=%v, want one naming the bad file", err)
     28 	}
     29 }
     30 
     31 func TestHalfSpecifiedInterceptPairIsRefused(t *testing.T) {
     32 	dir := t.TempDir()
     33 	for _, flag := range []string{"--intercept-cert", "--intercept-key"} {
     34 		err := runClient(t, flag, filepath.Join(dir, "x.pem"))
     35 		if err == nil || !strings.Contains(err.Error(), "must be given together") {
     36 			t.Errorf("%s alone accepted; got err=%v", flag, err)
     37 		}
     38 		if _, statErr := os.Stat(filepath.Join(dir, "x.pem")); statErr == nil {
     39 			t.Errorf("%s alone wrote a CA file it should have refused to create", flag)
     40 		}
     41 	}
     42 }
     43 
     44 func TestProxyURL(t *testing.T) {
     45 	for in, want := range map[string]string{
     46 		":8080":          "localhost:8080",
     47 		"127.0.0.1:8080": "127.0.0.1:8080",
     48 	} {
     49 		if got := proxyURL(in); got != want {
     50 			t.Errorf("proxyURL(%q) = %q; want %q", in, got, want)
     51 		}
     52 	}
     53 }