|
1 | 1 | // Copyright 2023 The Gitea Authors. All rights reserved. |
| 2 | +// Copyright 2025 The Forgejo Authors. All rights reserved. |
2 | 3 | // SPDX-License-Identifier: MIT |
3 | 4 |
|
4 | 5 | package assetfs |
@@ -108,3 +109,30 @@ func TestLayered(t *testing.T) { |
108 | 109 | assert.Equal(t, "l1", assets.GetFileLayerName("f1")) |
109 | 110 | assert.Equal(t, "l2", assets.GetFileLayerName("f2")) |
110 | 111 | } |
| 112 | + |
| 113 | +// Allow layers to read symlink outside the layer root. |
| 114 | +func TestLayeredSymlink(t *testing.T) { |
| 115 | + dir := t.TempDir() |
| 116 | + dirl1 := filepath.Join(dir, "l1") |
| 117 | + require.NoError(t, os.MkdirAll(dirl1, 0o755)) |
| 118 | + |
| 119 | + // Open layer in dir/l1 |
| 120 | + layer := Local("l1", dirl1) |
| 121 | + |
| 122 | + // Create a file in dir/outside |
| 123 | + fileContents := []byte("I am outside the layer") |
| 124 | + require.NoError(t, os.WriteFile(filepath.Join(dir, "outside"), fileContents, 0o600)) |
| 125 | + // Symlink dir/l1/outside to dir/outside |
| 126 | + require.NoError(t, os.Symlink(filepath.Join(dir, "outside"), filepath.Join(dirl1, "outside"))) |
| 127 | + |
| 128 | + // Open dir/l1/outside. |
| 129 | + f, err := layer.Open("outside") |
| 130 | + require.NoError(t, err) |
| 131 | + defer f.Close() |
| 132 | + |
| 133 | + // Confirm it contains the output of dir/outside |
| 134 | + contents, err := io.ReadAll(f) |
| 135 | + require.NoError(t, err) |
| 136 | + |
| 137 | + assert.Equal(t, fileContents, contents) |
| 138 | +} |
0 commit comments