e0e362d700
SDK Tests / changes (push) Waiting to run
SDK Tests / Python SDK Tests (sandbox) (push) Blocked by required conditions
SDK Tests / CLI Quality (push) Blocked by required conditions
SDK Tests / CLI Tests (push) Blocked by required conditions
SDK Tests / Python SDK Quality (code-interpreter) (push) Blocked by required conditions
SDK Tests / Python SDK Quality (sandbox) (push) Blocked by required conditions
SDK Tests / Python SDK Tests (code-interpreter) (push) Blocked by required conditions
SDK Tests / JavaScript SDK Quality And Tests (code-interpreter) (push) Blocked by required conditions
SDK Tests / JavaScript SDK Quality And Tests (sandbox) (push) Blocked by required conditions
Deploy Docs Pages / build (push) Waiting to run
Deploy Docs Pages / deploy (push) Blocked by required conditions
Real E2E Tests / changes (push) Waiting to run
Real E2E Tests / Python E2E (docker bridge) (push) Blocked by required conditions
Real E2E Tests / Java E2E (docker bridge) (push) Blocked by required conditions
Real E2E Tests / JavaScript E2E (docker bridge) (push) Blocked by required conditions
Real E2E Tests / C# E2E (docker bridge) (push) Blocked by required conditions
Real E2E Tests / Go E2E (docker bridge) (push) Blocked by required conditions
Real E2E Tests / Real E2E CI (push) Blocked by required conditions
SDK Tests / Kotlin SDK Quality And Tests (sandbox) (push) Blocked by required conditions
SDK Tests / Kotlin SDK Quality And Tests (code-interpreter) (push) Blocked by required conditions
SDK Tests / C# SDK Quality And Tests (code-interpreter) (push) Blocked by required conditions
SDK Tests / C# SDK Quality And Tests (sandbox) (push) Blocked by required conditions
SDK Tests / Go SDK Quality And Tests (push) Blocked by required conditions
SDK Tests / SDK CI (push) Blocked by required conditions
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCleanupScriptRemovesNativeDNSRedirectFallbackTables(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
binDir := filepath.Join(tmpDir, "bin")
|
|
require.NoError(t, os.Mkdir(binDir, 0o755))
|
|
logPath := filepath.Join(tmpDir, "nft.log")
|
|
orderPath := filepath.Join(tmpDir, "order.log")
|
|
|
|
writeExecutable(t, filepath.Join(binDir, "nft"), `#!/bin/sh
|
|
printf '%s\n' "$*" >> "`+logPath+`"
|
|
cat >> "`+logPath+`"
|
|
printf 'nft\n' >> "`+orderPath+`"
|
|
exit 0
|
|
`)
|
|
writeExecutable(t, filepath.Join(binDir, "iptables"), `#!/bin/sh
|
|
printf 'iptables\n' >> "`+orderPath+`"
|
|
exit 0
|
|
`)
|
|
writeExecutable(t, filepath.Join(binDir, "ip6tables"), `#!/bin/sh
|
|
printf 'ip6tables\n' >> "`+orderPath+`"
|
|
exit 0
|
|
`)
|
|
writeExecutable(t, filepath.Join(binDir, "pkill"), `#!/bin/sh
|
|
exit 0
|
|
`)
|
|
|
|
cmd := exec.Command("sh", "scripts/cleanup.sh")
|
|
cmd.Env = append(os.Environ(), "PATH="+binDir+string(os.PathListSeparator)+os.Getenv("PATH"))
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
require.NoError(t, err, string(out))
|
|
logBytes, err := os.ReadFile(logPath)
|
|
require.NoError(t, err)
|
|
logText := string(logBytes)
|
|
require.Contains(t, logText, "delete table inet opensandbox_dns_redirect")
|
|
require.Contains(t, logText, "delete table ip opensandbox_dns_redirect")
|
|
require.Contains(t, logText, "delete table ip6 opensandbox_dns_redirect")
|
|
orderBytes, err := os.ReadFile(orderPath)
|
|
require.NoError(t, err)
|
|
order := strings.Split(strings.TrimSpace(string(orderBytes)), "\n")
|
|
require.NotEmpty(t, order)
|
|
require.Equal(t, "nft", order[0])
|
|
}
|
|
|
|
func writeExecutable(t *testing.T, path string, content string) {
|
|
t.Helper()
|
|
require.NoError(t, os.WriteFile(path, []byte(strings.TrimLeft(content, "\n")), 0o755))
|
|
}
|