|
|
|
@ -119,7 +119,7 @@ func TestExtractFiles(t *testing.T) { |
|
|
|
|
skipWindows(t) |
|
|
|
|
|
|
|
|
|
pluginID := "plugin-with-absolute-symlink" |
|
|
|
|
path, err := i.extractFiles(context.Background(), zipFile(t, "testdata/plugin-with-absolute-symlink.zip"), pluginID, SimpleDirNameGeneratorFunc) |
|
|
|
|
path, err := i.extractFiles(context.Background(), zipFile(t, filepath.Join("testdata", "plugin-with-absolute-symlink.zip")), pluginID, SimpleDirNameGeneratorFunc) |
|
|
|
|
require.Equal(t, filepath.Join(pluginsDir, pluginID), path) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
@ -131,7 +131,7 @@ func TestExtractFiles(t *testing.T) { |
|
|
|
|
skipWindows(t) |
|
|
|
|
|
|
|
|
|
pluginID := "plugin-with-absolute-symlink-dir" |
|
|
|
|
path, err := i.extractFiles(context.Background(), zipFile(t, "testdata/plugin-with-absolute-symlink-dir.zip"), pluginID, SimpleDirNameGeneratorFunc) |
|
|
|
|
path, err := i.extractFiles(context.Background(), zipFile(t, filepath.Join("testdata", "plugin-with-absolute-symlink-dir.zip")), pluginID, SimpleDirNameGeneratorFunc) |
|
|
|
|
require.Equal(t, filepath.Join(pluginsDir, pluginID), path) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
@ -140,7 +140,7 @@ func TestExtractFiles(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
t.Run("Should detect if archive members point outside of the destination directory", func(t *testing.T) { |
|
|
|
|
path, err := i.extractFiles(context.Background(), zipFile(t, "testdata/plugin-with-parent-member.zip"), "plugin-with-parent-member", SimpleDirNameGeneratorFunc) |
|
|
|
|
path, err := i.extractFiles(context.Background(), zipFile(t, filepath.Join("testdata", "plugin-with-parent-member.zip")), "plugin-with-parent-member", SimpleDirNameGeneratorFunc) |
|
|
|
|
require.Empty(t, path) |
|
|
|
|
require.EqualError(t, err, fmt.Sprintf( |
|
|
|
|
`archive member "../member.txt" tries to write outside of plugin directory: %q, this can be a security risk`, |
|
|
|
@ -149,7 +149,7 @@ func TestExtractFiles(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
t.Run("Should detect if archive members are absolute", func(t *testing.T) { |
|
|
|
|
path, err := i.extractFiles(context.Background(), zipFile(t, "testdata/plugin-with-absolute-member.zip"), "plugin-with-absolute-member", SimpleDirNameGeneratorFunc) |
|
|
|
|
path, err := i.extractFiles(context.Background(), zipFile(t, filepath.Join("testdata", "plugin-with-absolute-member.zip")), "plugin-with-absolute-member", SimpleDirNameGeneratorFunc) |
|
|
|
|
require.Empty(t, path) |
|
|
|
|
require.EqualError(t, err, fmt.Sprintf( |
|
|
|
|
`archive member "/member.txt" tries to write outside of plugin directory: %q, this can be a security risk`, |
|
|
|
|