Files
kopia/fs/ignorefs/resolve_test.go
Julio López a394a5029f fix(general): prevent infinite loop while resolving ignore file symlinks (#4413)
* test symlink infinite loop
* remove spurious error wrap
* cleanup error messages
* remove unneeded intermediate vars
* check error in loop in fs.GetAllEntries
  While cur is expected to be `nil` when there's an error, this
  makes the check explicit.

Ref:
- #2037
- #4190
2025-02-14 23:38:32 -08:00

32 lines
613 B
Go

package ignorefs
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/kopia/kopia/fs"
"github.com/kopia/kopia/internal/mockfs"
"github.com/kopia/kopia/internal/testlogging"
)
func TestNoInfiniteResolveLink(t *testing.T) {
root := mockfs.NewDirectory()
root.AddSymlink("a", "./b", 0)
root.AddSymlink("b", "./c", 0)
root.AddSymlink("c", "./a", 0)
ctx := testlogging.Context(t)
e, err := root.Child(ctx, "b")
require.NoError(t, err)
s, ok := e.(fs.Symlink)
require.True(t, ok)
f, err := resolveSymlink(ctx, s)
require.ErrorIs(t, err, errTooManySymlinks)
require.Nil(t, f)
}