Skip to content

Commit

Permalink
identify feeds from nuget.config by 'key' attribute; write failing te…
Browse files Browse the repository at this point in the history
…st for ignoring
  • Loading branch information
theimowski committed Oct 3, 2015
1 parent d39cda8 commit eab7884
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
22 changes: 14 additions & 8 deletions src/Paket.Core/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,12 +66,12 @@ let private getKeyValueList (node : XmlNode) =
| _ -> None)

type NugetConfig =
{ PackageSources : list<string * Auth option>
{ PackageSources : Map<string, string * Auth option>
PackageRestoreEnabled : bool
PackageRestoreAutomatic : bool }

static member empty =
{ PackageSources = []
{ PackageSources = Map.empty
PackageRestoreEnabled = false
PackageRestoreAutomatic = false }

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<disabledPackageSources>
<add key="MyGetDuality" value="true" />
</disabledPackageSources>
<activePackageSource>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</activePackageSource>
</configuration>
38 changes: 29 additions & 9 deletions tests/Paket.Tests/NuGetConfig/NuGetConfigSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ 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 }

[<Test>]
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 }

Expand All @@ -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 }

[<Test>]
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 }
PackageRestoreAutomatic = true }
5 changes: 4 additions & 1 deletion tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,13 @@
<Content Include="NuGetConfig\PasswordConfig.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Compile Include="NuGetConfig\NuGetConfigSpecs.fs" />
<Content Include="NuGetConfig\ConfigWithDisabledFeed.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Include="NuGetConfig\NuGetConfigSpecs.fs" />
<Content Include="NuGetConfig\ConfigWithDisabledFeedFromUpstream.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="JSON-LD\Rx-PlatformServices.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit eab7884

Please sign in to comment.