Skip to content

Commit

Permalink
Tests for Restricting user to use yarn v4
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxBot committed Feb 13, 2025
1 parent 34354c4 commit 01d2fa6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,45 @@ func TestYarn(t *testing.T) {
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.YarnBuildName, artHttpDetails)
}

func TestYarnUpgradeToV4(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)

// Temporarily change the cache folder to a temporary folder - to make sure the cache is clean and dependencies will be downloaded from Artifactory
tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()

testDataSource := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "yarn")
testDataTarget := filepath.Join(tempDirPath, tests.Out, "yarn")
assert.NoError(t, biutils.CopyDir(testDataSource, testDataTarget, true, nil))

yarnProjectPath := filepath.Join(testDataTarget, "yarnproject")
assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, project.Yarn, false))

wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, yarnProjectPath)
defer chdirCallback()
cleanUpYarnGlobalFolder := clientTestUtils.SetEnvWithCallbackAndAssert(t, "YARN_GLOBAL_FOLDER", tempDirPath)
defer cleanUpYarnGlobalFolder()

// Add "localhost" to http whitelist
yarnExecPath, err := exec.LookPath("yarn")
assert.NoError(t, err)
// Get original http white list config
origWhitelist, err := yarn.ConfigGet("unsafeHttpWhitelist", yarnExecPath, true)
assert.NoError(t, err)
assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", "[\"localhost\"]", yarnExecPath, true))
defer func() {
// Restore original whitelist config
assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", origWhitelist, yarnExecPath, true))
}()

jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
err = jfrogCli.Exec("yarn", "set", "version", "4.0.1")
assert.Error(t, err)
}

// Checks if the expected dependencies match the actual dependencies. Only the dependencies' IDs and scopes (not more than one scope) are compared.
func equalDependenciesSlices(t *testing.T, expectedDependencies []expectedDependency, actualDependencies []buildinfo.Dependency) {
assert.Equal(t, len(expectedDependencies), len(actualDependencies))
Expand Down

0 comments on commit 01d2fa6

Please sign in to comment.