basicfs_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. // Copyright (C) 2017 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package fs
  7. import (
  8. "bytes"
  9. "errors"
  10. "fmt"
  11. "os"
  12. "path/filepath"
  13. "sort"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "testing"
  18. "time"
  19. "github.com/syncthing/syncthing/lib/build"
  20. "github.com/syncthing/syncthing/lib/protocol"
  21. "github.com/syncthing/syncthing/lib/rand"
  22. )
  23. func setup(t *testing.T) (*BasicFilesystem, string) {
  24. t.Helper()
  25. dir := t.TempDir()
  26. return newBasicFilesystem(dir), dir
  27. }
  28. func TestChmodFile(t *testing.T) {
  29. fs, dir := setup(t)
  30. path := filepath.Join(dir, "file")
  31. defer os.Chmod(path, 0666)
  32. fd, err := os.Create(path)
  33. if err != nil {
  34. t.Error(err)
  35. }
  36. fd.Close()
  37. if err := os.Chmod(path, 0666); err != nil {
  38. t.Error(err)
  39. }
  40. if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != 0666 {
  41. t.Errorf("wrong perm: %t %#o", err == nil, stat.Mode()&os.ModePerm)
  42. }
  43. if err := fs.Chmod("file", 0444); err != nil {
  44. t.Error(err)
  45. }
  46. if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != 0444 {
  47. t.Errorf("wrong perm: %t %#o", err == nil, stat.Mode()&os.ModePerm)
  48. }
  49. }
  50. func TestChownFile(t *testing.T) {
  51. if build.IsWindows {
  52. t.Skip("Not supported on Windows")
  53. return
  54. }
  55. if os.Getuid() != 0 {
  56. // We are not root. No expectation of being able to chown. Our tests
  57. // typically don't run with CAP_FOWNER.
  58. t.Skip("Test not possible")
  59. return
  60. }
  61. fs, dir := setup(t)
  62. path := filepath.Join(dir, "file")
  63. defer os.Chmod(path, 0666)
  64. fd, err := os.Create(path)
  65. if err != nil {
  66. t.Error("Unexpected error:", err)
  67. }
  68. fd.Close()
  69. _, err = fs.Lstat("file")
  70. if err != nil {
  71. t.Error("Unexpected error:", err)
  72. }
  73. newUID := 1000 + rand.Intn(30000)
  74. newGID := 1000 + rand.Intn(30000)
  75. if err := fs.Lchown("file", strconv.Itoa(newUID), strconv.Itoa(newGID)); err != nil {
  76. t.Error("Unexpected error:", err)
  77. }
  78. info, err := fs.Lstat("file")
  79. if err != nil {
  80. t.Error("Unexpected error:", err)
  81. }
  82. if info.Owner() != newUID {
  83. t.Errorf("Incorrect owner, expected %d but got %d", newUID, info.Owner())
  84. }
  85. if info.Group() != newGID {
  86. t.Errorf("Incorrect group, expected %d but got %d", newGID, info.Group())
  87. }
  88. }
  89. func TestChmodDir(t *testing.T) {
  90. fs, dir := setup(t)
  91. path := filepath.Join(dir, "dir")
  92. mode := os.FileMode(0755)
  93. if build.IsWindows {
  94. mode = os.FileMode(0777)
  95. }
  96. defer os.Chmod(path, mode)
  97. if err := os.Mkdir(path, mode); err != nil {
  98. t.Error(err)
  99. }
  100. // On UNIX, Mkdir will subtract the umask, so force desired mode explicitly
  101. if err := os.Chmod(path, mode); err != nil {
  102. t.Error(err)
  103. }
  104. if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != mode {
  105. t.Errorf("wrong perm: %t %#o", err == nil, stat.Mode()&os.ModePerm)
  106. }
  107. if err := fs.Chmod("dir", 0555); err != nil {
  108. t.Error(err)
  109. }
  110. if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != 0555 {
  111. t.Errorf("wrong perm: %t %#o", err == nil, stat.Mode()&os.ModePerm)
  112. }
  113. }
  114. func TestChtimes(t *testing.T) {
  115. fs, dir := setup(t)
  116. path := filepath.Join(dir, "file")
  117. fd, err := os.Create(path)
  118. if err != nil {
  119. t.Error(err)
  120. }
  121. fd.Close()
  122. mtime := time.Now().Add(-time.Hour)
  123. fs.Chtimes("file", mtime, mtime)
  124. stat, err := os.Stat(path)
  125. if err != nil {
  126. t.Error(err)
  127. }
  128. diff := stat.ModTime().Sub(mtime)
  129. if diff > 3*time.Second || diff < -3*time.Second {
  130. t.Errorf("%s != %s", stat.Mode(), mtime)
  131. }
  132. }
  133. func TestCreate(t *testing.T) {
  134. fs, dir := setup(t)
  135. path := filepath.Join(dir, "file")
  136. if _, err := os.Stat(path); err == nil {
  137. t.Errorf("exists?")
  138. }
  139. fd, err := fs.Create("file")
  140. if err != nil {
  141. t.Error(err)
  142. }
  143. fd.Close()
  144. if _, err := os.Stat(path); err != nil {
  145. t.Error(err)
  146. }
  147. }
  148. func TestCreateSymlink(t *testing.T) {
  149. if build.IsWindows {
  150. t.Skip("windows not supported")
  151. }
  152. fs, dir := setup(t)
  153. path := filepath.Join(dir, "file")
  154. if err := fs.CreateSymlink("blah", "file"); err != nil {
  155. t.Error(err)
  156. }
  157. if target, err := os.Readlink(path); err != nil || target != "blah" {
  158. t.Error("target", target, "err", err)
  159. }
  160. if err := os.Remove(path); err != nil {
  161. t.Error(err)
  162. }
  163. if err := fs.CreateSymlink(filepath.Join("..", "blah"), "file"); err != nil {
  164. t.Error(err)
  165. }
  166. if target, err := os.Readlink(path); err != nil || target != filepath.Join("..", "blah") {
  167. t.Error("target", target, "err", err)
  168. }
  169. }
  170. func TestDirNames(t *testing.T) {
  171. fs, dir := setup(t)
  172. // Case differences
  173. testCases := []string{
  174. "a",
  175. "bC",
  176. }
  177. sort.Strings(testCases)
  178. for _, sub := range testCases {
  179. if err := os.Mkdir(filepath.Join(dir, sub), 0777); err != nil {
  180. t.Error(err)
  181. }
  182. }
  183. if dirs, err := fs.DirNames("."); err != nil || len(dirs) != len(testCases) {
  184. t.Errorf("%s %s %s", err, dirs, testCases)
  185. } else {
  186. sort.Strings(dirs)
  187. for i := range dirs {
  188. if dirs[i] != testCases[i] {
  189. t.Errorf("%s != %s", dirs[i], testCases[i])
  190. }
  191. }
  192. }
  193. }
  194. func TestNames(t *testing.T) {
  195. // Tests that all names are without the root directory.
  196. fs, _ := setup(t)
  197. expected := "file"
  198. fd, err := fs.Create(expected)
  199. if err != nil {
  200. t.Error(err)
  201. }
  202. defer fd.Close()
  203. if fd.Name() != expected {
  204. t.Errorf("incorrect %s != %s", fd.Name(), expected)
  205. }
  206. if stat, err := fd.Stat(); err != nil || stat.Name() != expected {
  207. t.Errorf("incorrect %s != %s (%v)", stat.Name(), expected, err)
  208. }
  209. if err := fs.Mkdir("dir", 0777); err != nil {
  210. t.Error(err)
  211. }
  212. expected = filepath.Join("dir", "file")
  213. fd, err = fs.Create(expected)
  214. if err != nil {
  215. t.Error(err)
  216. }
  217. defer fd.Close()
  218. if fd.Name() != expected {
  219. t.Errorf("incorrect %s != %s", fd.Name(), expected)
  220. }
  221. // os.fd.Stat() returns just base, so do we.
  222. if stat, err := fd.Stat(); err != nil || stat.Name() != filepath.Base(expected) {
  223. t.Errorf("incorrect %s != %s (%v)", stat.Name(), filepath.Base(expected), err)
  224. }
  225. }
  226. func TestGlob(t *testing.T) {
  227. // Tests that all names are without the root directory.
  228. fs, _ := setup(t)
  229. for _, dirToCreate := range []string{
  230. filepath.Join("a", "test", "b"),
  231. filepath.Join("a", "best", "b"),
  232. filepath.Join("a", "best", "c"),
  233. } {
  234. if err := fs.MkdirAll(dirToCreate, 0777); err != nil {
  235. t.Error(err)
  236. }
  237. }
  238. testCases := []struct {
  239. pattern string
  240. matches []string
  241. }{
  242. {
  243. filepath.Join("a", "?est", "?"),
  244. []string{
  245. filepath.Join("a", "test", "b"),
  246. filepath.Join("a", "best", "b"),
  247. filepath.Join("a", "best", "c"),
  248. },
  249. },
  250. {
  251. filepath.Join("a", "?est", "b"),
  252. []string{
  253. filepath.Join("a", "test", "b"),
  254. filepath.Join("a", "best", "b"),
  255. },
  256. },
  257. {
  258. filepath.Join("a", "best", "?"),
  259. []string{
  260. filepath.Join("a", "best", "b"),
  261. filepath.Join("a", "best", "c"),
  262. },
  263. },
  264. }
  265. for _, testCase := range testCases {
  266. results, err := fs.Glob(testCase.pattern)
  267. sort.Strings(results)
  268. sort.Strings(testCase.matches)
  269. if err != nil {
  270. t.Error(err)
  271. }
  272. if len(results) != len(testCase.matches) {
  273. t.Errorf("result count mismatch")
  274. }
  275. for i := range testCase.matches {
  276. if results[i] != testCase.matches[i] {
  277. t.Errorf("%s != %s", results[i], testCase.matches[i])
  278. }
  279. }
  280. }
  281. }
  282. func TestUsage(t *testing.T) {
  283. fs, _ := setup(t)
  284. usage, err := fs.Usage(".")
  285. if err != nil {
  286. if build.IsNetBSD || build.IsOpenBSD || build.IsSolaris || build.IsIllumos {
  287. t.Skip()
  288. }
  289. t.Errorf("Unexpected error: %s", err)
  290. }
  291. if usage.Free < 1 {
  292. t.Error("Disk is full?", usage.Free)
  293. }
  294. }
  295. func TestRooted(t *testing.T) {
  296. type testcase struct {
  297. root string
  298. rel string
  299. joined string
  300. ok bool
  301. }
  302. cases := []testcase{
  303. // Valid cases
  304. {"foo", "bar", "foo/bar", true},
  305. {"foo", "/bar", "foo/bar", true},
  306. {"foo/", "bar", "foo/bar", true},
  307. {"foo/", "/bar", "foo/bar", true},
  308. {"baz/foo", "bar", "baz/foo/bar", true},
  309. {"baz/foo", "/bar", "baz/foo/bar", true},
  310. {"baz/foo/", "bar", "baz/foo/bar", true},
  311. {"baz/foo/", "/bar", "baz/foo/bar", true},
  312. {"foo", "bar/baz", "foo/bar/baz", true},
  313. {"foo", "/bar/baz", "foo/bar/baz", true},
  314. {"foo/", "bar/baz", "foo/bar/baz", true},
  315. {"foo/", "/bar/baz", "foo/bar/baz", true},
  316. {"baz/foo", "bar/baz", "baz/foo/bar/baz", true},
  317. {"baz/foo", "/bar/baz", "baz/foo/bar/baz", true},
  318. {"baz/foo/", "bar/baz", "baz/foo/bar/baz", true},
  319. {"baz/foo/", "/bar/baz", "baz/foo/bar/baz", true},
  320. // Not escape attempts, but oddly formatted relative paths.
  321. {"foo", "", "foo", true},
  322. {"foo", "/", "foo", true},
  323. {"foo", "/..", "foo", true},
  324. {"foo", "./bar", "foo/bar", true},
  325. {"foo/", "", "foo", true},
  326. {"foo/", "/", "foo", true},
  327. {"foo/", "/..", "foo", true},
  328. {"foo/", "./bar", "foo/bar", true},
  329. {"baz/foo", "./bar", "baz/foo/bar", true},
  330. {"foo", "./bar/baz", "foo/bar/baz", true},
  331. {"baz/foo", "./bar/baz", "baz/foo/bar/baz", true},
  332. {"baz/foo", "bar/../baz", "baz/foo/baz", true},
  333. {"baz/foo", "/bar/../baz", "baz/foo/baz", true},
  334. {"baz/foo", "./bar/../baz", "baz/foo/baz", true},
  335. // Results in an allowed path, but does it by probing. Disallowed.
  336. {"foo", "../foo", "", false},
  337. {"foo", "../foo/bar", "", false},
  338. {"baz/foo", "../foo/bar", "", false},
  339. {"baz/foo", "../../baz/foo/bar", "", false},
  340. {"baz/foo", "bar/../../foo/bar", "", false},
  341. {"baz/foo", "bar/../../../baz/foo/bar", "", false},
  342. // Escape attempts.
  343. {"foo", "..", "", false},
  344. {"foo", "../", "", false},
  345. {"foo", "../bar", "", false},
  346. {"foo", "../foobar", "", false},
  347. {"foo/", "../bar", "", false},
  348. {"foo/", "../foobar", "", false},
  349. {"baz/foo", "../bar", "", false},
  350. {"baz/foo", "../foobar", "", false},
  351. {"baz/foo/", "../bar", "", false},
  352. {"baz/foo/", "../foobar", "", false},
  353. {"baz/foo/", "bar/../../quux/baz", "", false},
  354. // Empty root is a misconfiguration.
  355. {"", "/foo", "", false},
  356. {"", "foo", "", false},
  357. {"", ".", "", false},
  358. {"", "..", "", false},
  359. {"", "/", "", false},
  360. {"", "", "", false},
  361. // Root=/ is valid, and things should be verified as usual.
  362. {"/", "foo", "/foo", true},
  363. {"/", "/foo", "/foo", true},
  364. {"/", "../foo", "", false},
  365. {"/", "..", "", false},
  366. {"/", "/", "/", true},
  367. {"/", "", "/", true},
  368. // special case for filesystems to be able to MkdirAll('.') for example
  369. {"/", ".", "/", true},
  370. }
  371. if build.IsWindows {
  372. extraCases := []testcase{
  373. {`c:\`, `foo`, `c:\foo`, true},
  374. {`\\?\c:\`, `foo`, `\\?\c:\foo`, true},
  375. {`c:\`, `\foo`, `c:\foo`, true},
  376. {`\\?\c:\`, `\foo`, `\\?\c:\foo`, true},
  377. {`c:\`, `\\foo`, ``, false},
  378. {`c:\`, ``, `c:\`, true},
  379. {`c:\`, `\`, `c:\`, true},
  380. {`\\?\c:\`, `\\foo`, ``, false},
  381. {`\\?\c:\`, ``, `\\?\c:\`, true},
  382. {`\\?\c:\`, `\`, `\\?\c:\`, true},
  383. {`\\?\c:\test`, `.`, `\\?\c:\test`, true},
  384. {`c:\test`, `.`, `c:\test`, true},
  385. {`\\?\c:\test`, `/`, `\\?\c:\test`, true},
  386. {`c:\test`, ``, `c:\test`, true},
  387. // makes no sense, but will be treated simply as a bad filename
  388. {`c:\foo`, `d:\bar`, `c:\foo\d:\bar`, true},
  389. // special case for filesystems to be able to MkdirAll('.') for example
  390. {`c:\`, `.`, `c:\`, true},
  391. {`\\?\c:\`, `.`, `\\?\c:\`, true},
  392. }
  393. for _, tc := range cases {
  394. extraCases = append(extraCases,
  395. // Add case where root is backslashed, rel is forward slashed
  396. testcase{
  397. root: filepath.FromSlash(tc.root),
  398. rel: tc.rel,
  399. joined: tc.joined,
  400. ok: tc.ok,
  401. },
  402. // and the opposite
  403. testcase{
  404. root: tc.root,
  405. rel: filepath.FromSlash(tc.rel),
  406. joined: tc.joined,
  407. ok: tc.ok,
  408. },
  409. // and both backslashed
  410. testcase{
  411. root: filepath.FromSlash(tc.root),
  412. rel: filepath.FromSlash(tc.rel),
  413. joined: tc.joined,
  414. ok: tc.ok,
  415. },
  416. )
  417. }
  418. cases = append(cases, extraCases...)
  419. }
  420. for _, tc := range cases {
  421. fs := BasicFilesystem{root: tc.root}
  422. res, err := fs.rooted(tc.rel)
  423. if tc.ok {
  424. if err != nil {
  425. t.Errorf("Unexpected error for rooted(%q, %q): %v", tc.root, tc.rel, err)
  426. continue
  427. }
  428. exp := filepath.FromSlash(tc.joined)
  429. if res != exp {
  430. t.Errorf("Unexpected result for rooted(%q, %q): %q != expected %q", tc.root, tc.rel, res, exp)
  431. }
  432. } else if err == nil {
  433. t.Errorf("Unexpected pass for rooted(%q, %q) => %q", tc.root, tc.rel, res)
  434. continue
  435. }
  436. }
  437. }
  438. func TestNewBasicFilesystem(t *testing.T) {
  439. if build.IsWindows {
  440. t.Skip("non-windows root paths")
  441. }
  442. currentDir, err := filepath.Abs(".")
  443. if err != nil {
  444. t.Fatal(err)
  445. }
  446. testCases := []struct {
  447. input string
  448. expectedRoot string
  449. expectedURI string
  450. }{
  451. {"/foo/bar/baz", "/foo/bar/baz", "/foo/bar/baz"},
  452. {"/foo/bar/baz/", "/foo/bar/baz", "/foo/bar/baz"},
  453. {"", currentDir, currentDir},
  454. {".", currentDir, currentDir},
  455. {"/", "/", "/"},
  456. }
  457. for _, testCase := range testCases {
  458. fs := newBasicFilesystem(testCase.input)
  459. if fs.root != testCase.expectedRoot {
  460. t.Errorf("root %q != %q", fs.root, testCase.expectedRoot)
  461. }
  462. if fs.URI() != testCase.expectedURI {
  463. t.Errorf("uri %q != %q", fs.URI(), testCase.expectedURI)
  464. }
  465. }
  466. fs := newBasicFilesystem("relative/path")
  467. if fs.root == "relative/path" || !strings.HasPrefix(fs.root, string(PathSeparator)) {
  468. t.Errorf(`newBasicFilesystem("relative/path").root == %q, expected absolutification`, fs.root)
  469. }
  470. }
  471. func TestRel(t *testing.T) {
  472. testCases := []struct {
  473. root string
  474. abs string
  475. expectedRel string
  476. }{
  477. {"/", "/", ""},
  478. {"/", "/test", "test"},
  479. {"/", "/Test", "Test"},
  480. {"/Test", "/Test/test", "test"},
  481. }
  482. if build.IsWindows {
  483. for i := range testCases {
  484. testCases[i].root = filepath.FromSlash(testCases[i].root)
  485. testCases[i].abs = filepath.FromSlash(testCases[i].abs)
  486. testCases[i].expectedRel = filepath.FromSlash(testCases[i].expectedRel)
  487. }
  488. }
  489. for _, tc := range testCases {
  490. if res := rel(tc.abs, tc.root); res != tc.expectedRel {
  491. t.Errorf(`rel("%v", "%v") == "%v", expected "%v"`, tc.abs, tc.root, res, tc.expectedRel)
  492. }
  493. }
  494. }
  495. func TestXattr(t *testing.T) {
  496. tfs, _ := setup(t)
  497. if err := tfs.Mkdir("/test", 0755); err != nil {
  498. t.Fatal(err)
  499. }
  500. xattrSize := func() int { return 20 + rand.Intn(20) }
  501. // Create a set of random attributes that we will set and read back
  502. var attrs []protocol.Xattr
  503. for i := 0; i < 10; i++ {
  504. key := fmt.Sprintf("user.test-%d", i)
  505. value := make([]byte, xattrSize())
  506. rand.Read(value)
  507. attrs = append(attrs, protocol.Xattr{
  508. Name: key,
  509. Value: value,
  510. })
  511. }
  512. // Set the xattrs, read them back and compare
  513. if err := tfs.SetXattr("/test", attrs, testXattrFilter{}); errors.Is(err, ErrXattrsNotSupported) || errors.Is(err, syscall.EOPNOTSUPP) {
  514. t.Skip("xattrs not supported")
  515. } else if err != nil {
  516. t.Fatal(err)
  517. }
  518. res, err := tfs.GetXattr("/test", testXattrFilter{})
  519. if err != nil {
  520. t.Fatal(err)
  521. }
  522. if len(res) != len(attrs) {
  523. t.Fatalf("length of returned xattrs does not match (%d != %d)", len(res), len(attrs))
  524. }
  525. for i, xa := range res {
  526. if xa.Name != attrs[i].Name {
  527. t.Errorf("xattr name %q != %q", xa.Name, attrs[i].Name)
  528. }
  529. if !bytes.Equal(xa.Value, attrs[i].Value) {
  530. t.Errorf("xattr value %q != %q", xa.Value, attrs[i].Value)
  531. }
  532. }
  533. // Remove a couple, change a couple, and add another couple of
  534. // attributes. Replacing the xattrs again should work.
  535. attrs = attrs[2:]
  536. attrs[1].Value = make([]byte, xattrSize())
  537. rand.Read(attrs[1].Value)
  538. attrs[3].Value = make([]byte, xattrSize())
  539. rand.Read(attrs[3].Value)
  540. for i := 10; i < 12; i++ {
  541. key := fmt.Sprintf("user.test-%d", i)
  542. value := make([]byte, xattrSize())
  543. rand.Read(value)
  544. attrs = append(attrs, protocol.Xattr{
  545. Name: key,
  546. Value: value,
  547. })
  548. }
  549. sort.Slice(attrs, func(i, j int) bool { return attrs[i].Name < attrs[j].Name })
  550. // Set the xattrs, read them back and compare
  551. if err := tfs.SetXattr("/test", attrs, testXattrFilter{}); err != nil {
  552. t.Fatal(err)
  553. }
  554. res, err = tfs.GetXattr("/test", testXattrFilter{})
  555. if err != nil {
  556. t.Fatal(err)
  557. }
  558. if len(res) != len(attrs) {
  559. t.Fatalf("length of returned xattrs does not match (%d != %d)", len(res), len(attrs))
  560. }
  561. for i, xa := range res {
  562. if xa.Name != attrs[i].Name {
  563. t.Errorf("xattr name %q != %q", xa.Name, attrs[i].Name)
  564. }
  565. if !bytes.Equal(xa.Value, attrs[i].Value) {
  566. t.Errorf("xattr value %q != %q", xa.Value, attrs[i].Value)
  567. }
  568. }
  569. }
  570. func TestBasicWalkSkipSymlink(t *testing.T) {
  571. _, dir := setup(t)
  572. testWalkSkipSymlink(t, FilesystemTypeBasic, dir)
  573. }
  574. func TestWalkTraverseDirJunct(t *testing.T) {
  575. _, dir := setup(t)
  576. testWalkTraverseDirJunct(t, FilesystemTypeBasic, dir)
  577. }
  578. func TestWalkInfiniteRecursion(t *testing.T) {
  579. _, dir := setup(t)
  580. testWalkInfiniteRecursion(t, FilesystemTypeBasic, dir)
  581. }
  582. type testXattrFilter struct{}
  583. // Permit only xattrs generated by our test, avoiding issues with SELinux etc.
  584. func (testXattrFilter) Permit(name string) bool { return strings.HasPrefix(name, "user.test-") }
  585. func (testXattrFilter) GetMaxSingleEntrySize() int { return 0 }
  586. func (testXattrFilter) GetMaxTotalSize() int { return 0 }