@@ -669,7 +669,7 @@ func TestYarn(t *testing.T) {
669669 testDataTarget := filepath .Join (tempDirPath , tests .Out , "yarn" )
670670 assert .NoError (t , biutils .CopyDir (testDataSource , testDataTarget , true , nil ))
671671
672- yarnProjectPath := filepath .Join (testDataTarget , "yarnproject " )
672+ yarnProjectPath := filepath .Join (testDataTarget , "yarnprojectV2 " )
673673 assert .NoError (t , createConfigFileForTest ([]string {yarnProjectPath }, tests .NpmRemoteRepo , "" , t , project .Yarn , false ))
674674
675675 wd , err := os .Getwd ()
@@ -714,6 +714,47 @@ func TestYarn(t *testing.T) {
714714 inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , tests .YarnBuildName , artHttpDetails )
715715}
716716
717+ func TestYarnSetVersion (t * testing.T ) {
718+ initNpmTest (t )
719+ defer cleanNpmTest (t )
720+
721+ // Temporarily change the cache folder to a temporary folder - to make sure the cache is clean and dependencies will be downloaded from Artifactory
722+ tempDirPath , createTempDirCallback := coretests .CreateTempDirWithCallbackAndAssert (t )
723+ defer createTempDirCallback ()
724+
725+ testDataSource := filepath .Join (filepath .FromSlash (tests .GetTestResourcesPath ()), "yarn" )
726+ testDataTarget := filepath .Join (tempDirPath , tests .Out , "yarn" )
727+ assert .NoError (t , biutils .CopyDir (testDataSource , testDataTarget , true , nil ))
728+
729+ yarnProjectPath := filepath .Join (testDataTarget , "yarnprojectV2" )
730+ assert .NoError (t , createConfigFileForTest ([]string {yarnProjectPath }, tests .NpmRemoteRepo , "" , t , project .Yarn , false ))
731+
732+ wd , err := os .Getwd ()
733+ assert .NoError (t , err , "Failed to get current dir" )
734+ chdirCallback := clientTestUtils .ChangeDirWithCallback (t , wd , yarnProjectPath )
735+ defer chdirCallback ()
736+ cleanUpYarnGlobalFolder := clientTestUtils .SetEnvWithCallbackAndAssert (t , "YARN_GLOBAL_FOLDER" , tempDirPath )
737+ defer cleanUpYarnGlobalFolder ()
738+
739+ // Add "localhost" to http whitelist
740+ yarnExecPath , err := exec .LookPath ("yarn" )
741+ assert .NoError (t , err )
742+ // Get original http white list config
743+ origWhitelist , err := yarn .ConfigGet ("unsafeHttpWhitelist" , yarnExecPath , true )
744+ assert .NoError (t , err )
745+ assert .NoError (t , yarn .ConfigSet ("unsafeHttpWhitelist" , "[\" localhost\" ]" , yarnExecPath , true ))
746+ defer func () {
747+ // Restore original whitelist config
748+ assert .NoError (t , yarn .ConfigSet ("unsafeHttpWhitelist" , origWhitelist , yarnExecPath , true ))
749+ }()
750+
751+ jfrogCli := coretests .NewJfrogCli (execMain , "jfrog" , "" )
752+ err = jfrogCli .Exec ("yarn" , "set" , "version" , "3.2.1" )
753+ yarnProjectPath = filepath .Join (testDataTarget , "yarnprojectV3" )
754+ assert .NoError (t , createConfigFileForTest ([]string {yarnProjectPath }, tests .NpmRemoteRepo , "" , t , project .Yarn , false ))
755+ assert .NoError (t , err )
756+ }
757+
717758func TestYarnUpgradeToV4 (t * testing.T ) {
718759 initNpmTest (t )
719760 defer cleanNpmTest (t )
@@ -726,7 +767,7 @@ func TestYarnUpgradeToV4(t *testing.T) {
726767 testDataTarget := filepath .Join (tempDirPath , tests .Out , "yarn" )
727768 assert .NoError (t , biutils .CopyDir (testDataSource , testDataTarget , true , nil ))
728769
729- yarnProjectPath := filepath .Join (testDataTarget , "yarnproject " )
770+ yarnProjectPath := filepath .Join (testDataTarget , "yarnprojectV2 " )
730771 assert .NoError (t , createConfigFileForTest ([]string {yarnProjectPath }, tests .NpmRemoteRepo , "" , t , project .Yarn , false ))
731772
732773 wd , err := os .Getwd ()
@@ -753,6 +794,86 @@ func TestYarnUpgradeToV4(t *testing.T) {
753794 assert .Error (t , err )
754795}
755796
797+ func TestYarnInV4 (t * testing.T ) {
798+ initNpmTest (t )
799+ defer cleanNpmTest (t )
800+
801+ // Temporarily change the cache folder to a temporary folder - to make sure the cache is clean and dependencies will be downloaded from Artifactory
802+ tempDirPath , createTempDirCallback := coretests .CreateTempDirWithCallbackAndAssert (t )
803+ defer createTempDirCallback ()
804+
805+ testDataSource := filepath .Join (filepath .FromSlash (tests .GetTestResourcesPath ()), "yarn" )
806+ testDataTarget := filepath .Join (tempDirPath , tests .Out , "yarn" )
807+ assert .NoError (t , biutils .CopyDir (testDataSource , testDataTarget , true , nil ))
808+
809+ yarnProjectPath := filepath .Join (testDataTarget , "yarnprojectV4" )
810+ assert .NoError (t , createConfigFileForTest ([]string {yarnProjectPath }, tests .NpmRemoteRepo , "" , t , project .Yarn , false ))
811+
812+ wd , err := os .Getwd ()
813+ assert .NoError (t , err , "Failed to get current dir" )
814+ chdirCallback := clientTestUtils .ChangeDirWithCallback (t , wd , yarnProjectPath )
815+ defer chdirCallback ()
816+ cleanUpYarnGlobalFolder := clientTestUtils .SetEnvWithCallbackAndAssert (t , "YARN_GLOBAL_FOLDER" , tempDirPath )
817+ defer cleanUpYarnGlobalFolder ()
818+
819+ // Add "localhost" to http whitelist
820+ yarnExecPath , err := exec .LookPath ("yarn" )
821+ assert .NoError (t , err )
822+ // Get original http white list config
823+ origWhitelist , err := yarn .ConfigGet ("unsafeHttpWhitelist" , yarnExecPath , true )
824+ assert .NoError (t , err )
825+ assert .NoError (t , yarn .ConfigSet ("unsafeHttpWhitelist" , "[\" localhost\" ]" , yarnExecPath , true ))
826+ defer func () {
827+ // Restore original whitelist config
828+ assert .NoError (t , yarn .ConfigSet ("unsafeHttpWhitelist" , origWhitelist , yarnExecPath , true ))
829+ }()
830+
831+ jfrogCli := coretests .NewJfrogCli (execMain , "jfrog" , "" )
832+ err = jfrogCli .Exec ("yarn" , "install" )
833+ assert .Error (t , err )
834+ }
835+
836+ func TestYarnChangeVersionInV4 (t * testing.T ) {
837+ initNpmTest (t )
838+ defer cleanNpmTest (t )
839+
840+ // Temporarily change the cache folder to a temporary folder - to make sure the cache is clean and dependencies will be downloaded from Artifactory
841+ tempDirPath , createTempDirCallback := coretests .CreateTempDirWithCallbackAndAssert (t )
842+ defer createTempDirCallback ()
843+
844+ testDataSource := filepath .Join (filepath .FromSlash (tests .GetTestResourcesPath ()), "yarn" )
845+ testDataTarget := filepath .Join (tempDirPath , tests .Out , "yarn" )
846+ assert .NoError (t , biutils .CopyDir (testDataSource , testDataTarget , true , nil ))
847+
848+ yarnProjectPath := filepath .Join (testDataTarget , "yarnprojectV4" )
849+ assert .NoError (t , createConfigFileForTest ([]string {yarnProjectPath }, tests .NpmRemoteRepo , "" , t , project .Yarn , false ))
850+
851+ wd , err := os .Getwd ()
852+ assert .NoError (t , err , "Failed to get current dir" )
853+ chdirCallback := clientTestUtils .ChangeDirWithCallback (t , wd , yarnProjectPath )
854+ defer chdirCallback ()
855+ cleanUpYarnGlobalFolder := clientTestUtils .SetEnvWithCallbackAndAssert (t , "YARN_GLOBAL_FOLDER" , tempDirPath )
856+ defer cleanUpYarnGlobalFolder ()
857+
858+ // Add "localhost" to http whitelist
859+ yarnExecPath , err := exec .LookPath ("yarn" )
860+ assert .NoError (t , err )
861+ // Get original http white list config
862+ origWhitelist , err := yarn .ConfigGet ("unsafeHttpWhitelist" , yarnExecPath , true )
863+ assert .NoError (t , err )
864+ assert .NoError (t , yarn .ConfigSet ("unsafeHttpWhitelist" , "[\" localhost\" ]" , yarnExecPath , true ))
865+ defer func () {
866+ // Restore original whitelist config
867+ assert .NoError (t , yarn .ConfigSet ("unsafeHttpWhitelist" , origWhitelist , yarnExecPath , true ))
868+ }()
869+
870+ jfrogCli := coretests .NewJfrogCli (execMain , "jfrog" , "" )
871+ err = jfrogCli .Exec ("yarn" , "set" , "version" , "3.2.1" )
872+ yarnProjectPath = filepath .Join (testDataTarget , "yarnprojectV3" )
873+ assert .NoError (t , createConfigFileForTest ([]string {yarnProjectPath }, tests .NpmRemoteRepo , "" , t , project .Yarn , false ))
874+ assert .NoError (t , err )
875+ }
876+
756877// Checks if the expected dependencies match the actual dependencies. Only the dependencies' IDs and scopes (not more than one scope) are compared.
757878func equalDependenciesSlices (t * testing.T , expectedDependencies []expectedDependency , actualDependencies []buildinfo.Dependency ) {
758879 assert .Equal (t , len (expectedDependencies ), len (actualDependencies ))
0 commit comments