Debian Codegraph @

integration/ipacl/ipacl_test.go

raw symbols SCIP
1 package ipacl_testscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/"
5 "netscip-go gomod github.com/golang/go/src go1.25.0 net/"
6 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
7 "os/execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/"
8 "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/"
9 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
10 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
11
12 "github.com/gokrazy/rsync/internal/rsyncdconfigscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncdconfig`/"
13 "github.com/gokrazy/rsync/internal/rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/"
14 "github.com/gokrazy/rsync/internal/testloggerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/testlogger`/"
15 )
16
17 type connWithRemoteAddrListenerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener# struct {
18 netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener#Listener.
19
20 remoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener#remoteAddr. netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#
21 }
22
23 func (l *connWithRemoteAddrListenerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener#) Acceptscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener#Accept().() (netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#, error) {
24 conn, err := l.Listenerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener#Listener..Acceptscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#Accept().()
25 if err != nil {
26 return nil, err
27 }
28 return &connWithRemoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddr#{
29 Connscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddr#Conn.: conn,
30 remoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddr#remoteAddr.: l.remoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener#remoteAddr.,
31 }, nil
32 }
33
34 type connWithRemoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddr# struct {
35 netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddr#Conn.
36
37 remoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddr#remoteAddr. netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#
38 }
39
40 func (c *connWithRemoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddr#) RemoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddr#RemoteAddr().() netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr# {
41 return c.remoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddr#remoteAddr.
42 }
43
44 func TestIPACLscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/TestIPACL().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
45 rsyncBin := rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.TridgeOrGTFOscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/TridgeOrGTFO().(t, "TODO: reason")
46
47 tmp := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().()
48 source := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmp, "source")
49 dest := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmp, "dest")
50 // create files in source to be copied
51 if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.25.0 os/MkdirAll().(source, 0755); err != nil {
52 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
53 }
54
55 cfg, err := rsyncdconfigscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncdconfig`/.FromStringscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncdconfig`/FromString().(`
56 [[module]]
57 name = "interop"
58 path = '` + source + `'
59 acl = [
60 "allow 192.168.1.0/24",
61 "allow 2001:db8::1/32",
62 "deny all"
63 ]
64
65 `)
66 if err != nil {
67 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
68 }
69
70 for _, tt := range []struct {
71 remoteAddr string
72 wantError bool
73 }{
74 {
75 remoteAddr: "192.168.1.1",
76 wantError: false,
77 },
78 {
79 remoteAddr: "2001:db8::1234",
80 wantError: false,
81 },
82 {
83 remoteAddr: "10.0.0.1",
84 wantError: true,
85 },
86 } {
87 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tt.remoteAddr, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
88 t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().()
89
90 ln, err := netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenscip-go gomod github.com/golang/go/src go1.25.0 net/Listen().("tcp", "localhost:0")
91 if err != nil {
92 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
93 }
94 ln = &connWithRemoteAddrListenerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener#{
95 Listenerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener#Listener.: ln,
96 remoteAddrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/ipacl_test`/connWithRemoteAddrListener#remoteAddr.: &netscip-go gomod github.com/golang/go/src go1.25.0 net/.TCPAddrscip-go gomod github.com/golang/go/src go1.25.0 net/TCPAddr#{
97 IPscip-go gomod github.com/golang/go/src go1.25.0 net/TCPAddr#IP.: netscip-go gomod github.com/golang/go/src go1.25.0 net/.ParseIPscip-go gomod github.com/golang/go/src go1.25.0 net/ParseIP().(tt.remoteAddr),
98 Portscip-go gomod github.com/golang/go/src go1.25.0 net/TCPAddr#Port.: 1234,
99 },
100 }
101 srv := rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.Newscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/New().(t, cfg.Modulesscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncdconfig`/Config#Modules., rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.Listenerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/Listener().(ln))
102
103 // request module list: this should work regardless of the source IP
104 var buf bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#
105 rsync := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().(rsyncBin,
106 // "--debug=all4",
107 "--archive",
108 "-v", "-v", "-v", "-v",
109 "--port="+srv.Portscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/TestServer#Port.,
110 "rsync://localhost")
111 rsync.Stdoutscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stdout. = &buf
112 rsync.Stderrscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stderr. = testloggerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/testlogger`/.Newscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/testlogger`/New().(t)
113 if err := rsync.Runscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Run().(); err != nil {
114 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%v: %v", rsync.Argsscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Args., err)
115 }
116
117 output := buf.Stringscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#String().()
118 if want := "interop\tinterop"; !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(output, want) {
119 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("rsync output unexpectedly did not contain %q:\n%s", want, output)
120 }
121
122 buf.Resetscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#Reset().()
123 // actually transfer the interop module (in dry-run mode) to trigger
124 // the ACL check dry run (slight differences in protocol)
125 rsync = execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().(rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.AnyRsyncscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/AnyRsync().(t),
126 // "--debug=all4",
127 "--archive",
128 "-v", "-v", "-v", "-v",
129 "--port="+srv.Portscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/TestServer#Port.,
130 "--dry-run",
131 "rsync://localhost/interop/", // copy contents of interop
132 //source+"/", // sync from local directory
133 filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Base().(dest)) // directly into dest
134 rsync.Dirscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Dir. = filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Dir().(dest)
135 rsync.Stdoutscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stdout. = testloggerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/testlogger`/.Newscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/testlogger`/New().(t)
136 rsync.Stderrscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stderr. = &buf
137 if err := rsync.Runscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Run().(); err != nil {
138 if !tt.wantError {
139 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%v: %v", rsync.Argsscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Args., err)
140 }
141 }
142
143 if tt.wantError {
144 if !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(buf.Stringscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#String().(), "@ERROR: access denied") {
145 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected access denied error, got: %q", buf.Stringscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#String().())
146 }
147 }
148 })
149 }
150 }