Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TestUploadWithArchiveAndSymlink #1269

Merged
merged 1 commit into from
Nov 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1991,17 +1991,17 @@ func TestSymlinkWildcardPathHandling(t *testing.T) {

func TestUploadWithArchiveAndSymlink(t *testing.T) {
initArtifactoryTest(t)
symlinkTarget := filepath.Join(tests.GetTestResourcesPath(), "a", "a2.in")
// Path to local file with a different name from symlinkTarget
testFile := filepath.Join(tests.GetTestResourcesPath(), "a", "a1.in")
tmpDir, err := fileutils.CreateTempDir()
assert.NoError(t, err)
defer func() { assert.NoError(t, os.RemoveAll(tmpDir)) }()
err = fileutils.CopyFile(tmpDir, testFile)
assert.NoError(t, err)
// Link valid symLink to local file
symlinkTarget := filepath.Join(tmpDir, "a1.in")
err = os.Symlink(symlinkTarget, filepath.Join(tmpDir, "symlink"))
assert.NoError(t, err)
err = fileutils.CopyFile(tmpDir, testFile)
assert.NoError(t, err)
// Upload symlink and local file to artifactory
assert.NoError(t, artifactoryCli.Exec("u", tmpDir+"/*", tests.RtRepo1+"/test-archive.zip", "--archive=zip", "--symlinks=true", "--flat=true"))
assert.NoError(t, os.RemoveAll(tmpDir))
Expand All @@ -2014,6 +2014,30 @@ func TestUploadWithArchiveAndSymlink(t *testing.T) {
cleanArtifactoryTest()
}

func TestUploadWithArchiveAndSymlinkZipSlip(t *testing.T) {
initArtifactoryTest(t)
symlinkTarget := filepath.Join(tests.GetTestResourcesPath(), "a", "a2.in")
tmpDir, err := fileutils.CreateTempDir()
assert.NoError(t, err)
defer func() { assert.NoError(t, os.RemoveAll(tmpDir)) }()
// Link symLink to local file, outside of the extraction directory
err = os.Symlink(symlinkTarget, filepath.Join(tmpDir, "symlink"))
assert.NoError(t, err)

// Upload symlink and local file to artifactory
assert.NoError(t, artifactoryCli.Exec("u", tmpDir+"/*", tests.RtRepo1+"/test-archive.zip", "--archive=zip", "--symlinks=true", "--flat=true"))
assert.NoError(t, os.RemoveAll(tmpDir))
assert.NoError(t, os.Mkdir(tmpDir, 0777))

// Discard output logging to prevent negative logs
previousLogger := tests.RedirectLogOutputToNil()
defer log.SetLogger(previousLogger)

// Make sure download failed
assert.Error(t, artifactoryCli.Exec("download", tests.RtRepo1+"/test-archive.zip", tmpDir+"/", "--explode=true"))
cleanArtifactoryTest()
}

// Upload symlink pointing to directory to Artifactory.
// Download the symlink which was uploaded.
func TestSymlinkToDirHandling(t *testing.T) {
Expand Down Expand Up @@ -2088,6 +2112,11 @@ func TestSymlinkInsideSymlinkDirWithRecursionIssueUpload(t *testing.T) {
}

func validateSymLink(localLinkPath, localFilePath string, t *testing.T) {
// In macOS, localFilePath may lead to /var/folders/dn instead of /private/var/folders/dn.
// EvalSymlinks in localLinkPath should fix it.
localFilePath, err := filepath.EvalSymlinks(localLinkPath)
assert.NoError(t, err)

exists := fileutils.IsPathSymlink(localLinkPath)
assert.True(t, exists, "failed to download symlinks from artifactory")
symlinks, err := filepath.EvalSymlinks(localLinkPath)
Expand Down