feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package isolation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFTPFreezeOnlyChangesMatchingManagedAccount(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
directory := filepath.Join(root, "etc")
|
||||
if err := os.Mkdir(directory, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
file := filepath.Join(directory, "pureftpd.passwd")
|
||||
if err := os.WriteFile(file, []byte("other-user:private-hash:1001\nsv0123456789:private-hash:1002\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var calls []string
|
||||
a := Agent{PurePWBinary: filepath.Join(root, "bin", "pure-pw"), runCommand: func(_ context.Context, name string, args ...string) error {
|
||||
calls = append(calls, strings.Join(args, " "))
|
||||
return nil
|
||||
}}
|
||||
if err := a.freezeFTPLogin(context.Background(), "sv0123456789"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(calls) != 1 || calls[0] != "usermod sv0123456789 -r 0.0.0.0 -m" {
|
||||
t.Fatalf("unexpected FTP changes: %v", calls)
|
||||
}
|
||||
if err := a.freezeFTPLogin(context.Background(), "sv1111111111"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(calls) != 1 {
|
||||
t.Fatal("missing account changed unrelated FTP resources")
|
||||
}
|
||||
if err := os.Remove(file); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(filepath.Join(root, "outside"), file); err != nil {
|
||||
t.Skip("symlink unavailable")
|
||||
}
|
||||
if err := a.freezeFTPLogin(context.Background(), "sv0123456789"); err == nil {
|
||||
t.Fatal("symlink account database accepted")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user