diff --git a/src/Paket.Core/NugetConvert.fs b/src/Paket.Core/NugetConvert.fs index 1d9ee5f0f3..de888f19d1 100644 --- a/src/Paket.Core/NugetConvert.fs +++ b/src/Paket.Core/NugetConvert.fs @@ -8,7 +8,6 @@ open System.Xml open Paket.Domain open Paket.Logging open Paket.Xml -open Paket.NuGetV2 open Paket.PackageSources open Paket.Requirements open Chessie.ErrorHandling @@ -67,12 +66,12 @@ let private getKeyValueList (node : XmlNode) = | _ -> None) type NugetConfig = - { PackageSources : list + { PackageSources : Map PackageRestoreEnabled : bool PackageRestoreAutomatic : bool } static member empty = - { PackageSources = [] + { PackageSources = Map.empty PackageRestoreEnabled = false PackageRestoreAutomatic = false } @@ -120,12 +119,15 @@ type NugetConfig = |> Option.toList |> List.collect getKeyValueList |> List.filter (fun (key,_) -> Set.contains key disabledSources |> not) - |> List.map (fun (key,value) -> String.quoted value, getAuth key) - + |> List.map (fun (key,value) -> key, (String.quoted value, getAuth key)) + |> Map.ofList + { PackageSources = if clearSources then sources else - nugetConfig.PackageSources @ sources - |> List.distinct + Map.fold + (fun acc k v -> Map.add k v acc) + nugetConfig.PackageSources + sources PackageRestoreEnabled = match configNode |> getNode "packageRestore" |> Option.bind (tryGetValue "enabled") with | Some value -> bool.Parse(value) @@ -271,7 +273,11 @@ let createDependenciesFileR (rootDirectory : DirectoryInfo) nugetEnv mode = let create() = let sources = - if nugetEnv.NugetConfig.PackageSources = [] then [Constants.DefaultNugetStream,None] else nugetEnv.NugetConfig.PackageSources + if nugetEnv.NugetConfig.PackageSources = Map.empty then [ Constants.DefaultNugetStream, None ] + else + (nugetEnv.NugetConfig.PackageSources + |> Map.toList + |> List.map snd) |> List.map (fun (n, auth) -> n, auth |> Option.map (CredsMigrationMode.toAuthentication mode n)) |> List.map (fun source -> try source |> PackageSource.Parse |> ok diff --git a/src/Paket.Core/PublicAPI.fs b/src/Paket.Core/PublicAPI.fs index fcdd07872f..6555c6b68e 100644 --- a/src/Paket.Core/PublicAPI.fs +++ b/src/Paket.Core/PublicAPI.fs @@ -277,7 +277,7 @@ type Dependencies(dependenciesFileName: string) = member this.GetDefinedNuGetFeeds() : string list = let configured = match NuGetConvert.NugetEnv.readNugetConfig(this.RootDirectory) with - | Result.Ok(config,_) -> config.PackageSources |> List.map fst + | Result.Ok(config,_) -> config.PackageSources |> Map.toList |> List.map (snd >> fst) | _ -> [] Constants.DefaultNugetStream :: configured |> Set.ofSeq diff --git a/tests/Paket.Tests/NuGetConfig/ConfigWithDisabledFeedFromUpstream.xml b/tests/Paket.Tests/NuGetConfig/ConfigWithDisabledFeedFromUpstream.xml new file mode 100644 index 0000000000..643a8b8e53 --- /dev/null +++ b/tests/Paket.Tests/NuGetConfig/ConfigWithDisabledFeedFromUpstream.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Paket.Tests/NuGetConfig/NuGetConfigSpecs.fs b/tests/Paket.Tests/NuGetConfig/NuGetConfigSpecs.fs index 57768eecd2..c4693fd0e5 100644 --- a/tests/Paket.Tests/NuGetConfig/NuGetConfigSpecs.fs +++ b/tests/Paket.Tests/NuGetConfig/NuGetConfigSpecs.fs @@ -32,9 +32,10 @@ let ``can detect encrypted passwords in nuget.config``() = parse "NuGetConfig/PasswordConfig.xml" |> shouldEqual { PackageSources = - [ "https://www.nuget.org/api/v2/",None - "https://tc/httpAuth/app/nuget/v1/FeedService.svc/", - Some { Username = "notty"; Password = "secret" } ] + [ "https://www.nuget.org/api/v2/", ("https://www.nuget.org/api/v2/",None) + "tc", ("https://tc/httpAuth/app/nuget/v1/FeedService.svc/", + Some { Username = "notty"; Password = "secret" } ) ] + |> Map.ofList PackageRestoreEnabled = false PackageRestoreAutomatic = false } @@ -42,10 +43,11 @@ let ``can detect encrypted passwords in nuget.config``() = let ``can detect cleartextpasswords in nuget.config``() = parse "NuGetConfig/ClearTextPasswordConfig.xml" |> shouldEqual - { PackageSources = - [ "https://www.nuget.org/api/v2/",None - "https://nuget/somewhere/", - Some { Username = "myUser"; Password = "myPassword" } ] + { PackageSources = + [ "https://www.nuget.org/api/v2/", ("https://www.nuget.org/api/v2/",None) + "somewhere", ("https://nuget/somewhere/", + Some { Username = "myUser"; Password = "myPassword" } ) ] + |> Map.ofList PackageRestoreEnabled = false PackageRestoreAutomatic = false } @@ -54,6 +56,24 @@ let ``ignores disabled nuget feed`` () = parse "NuGetConfig/ConfigWithDisabledFeed.xml" |> shouldEqual { PackageSources = - [ "https://www.nuget.org/api/v2/",None] + [ "nuget.org", ("https://www.nuget.org/api/v2/",None) ] + |> Map.ofList + PackageRestoreEnabled = true + PackageRestoreAutomatic = true } + +[] +let ``ignores disabled nuget feed from upstream`` () = + let upstream = + { NugetConfig.empty with + PackageSources = + [ "MyGetDuality", ("https://www.myget.org/F/6416d9912a7c4d46bc983870fb440d25/", None) ] + |> Map.ofList } + let next = NugetConfig.getConfigNode (FileInfo "NugetConfig/ConfigWithDisabledFeedFromUpstream.xml") |> Trial.returnOrFail + let overridden = NugetConfig.overrideConfig upstream next + overridden + |> shouldEqual + { PackageSources = + [ "nuget.org", ("https://www.nuget.org/api/v2/",None) ] + |> Map.ofList PackageRestoreEnabled = true - PackageRestoreAutomatic = true } \ No newline at end of file + PackageRestoreAutomatic = true } diff --git a/tests/Paket.Tests/Paket.Tests.fsproj b/tests/Paket.Tests/Paket.Tests.fsproj index 837a294a51..3a71635cc6 100644 --- a/tests/Paket.Tests/Paket.Tests.fsproj +++ b/tests/Paket.Tests/Paket.Tests.fsproj @@ -188,10 +188,13 @@ Always + PreserveNewest - + + PreserveNewest + Always