diff --git a/src/Paket.Core/Versioning/PackageSources.fs b/src/Paket.Core/Versioning/PackageSources.fs index c32f11de41..328fcf0747 100644 --- a/src/Paket.Core/Versioning/PackageSources.fs +++ b/src/Paket.Core/Versioning/PackageSources.fs @@ -126,16 +126,21 @@ type PackageSource = static member Parse(line : string) = let sourceRegex = Regex("source[ ]*[\"]([^\"]*)[\"]", RegexOptions.IgnoreCase) let parts = line.Split ' ' + let source = if sourceRegex.IsMatch line then sourceRegex.Match(line).Groups.[1].Value.TrimEnd([| '/' |]) else parts.[1].Replace("\"","").TrimEnd([| '/' |]) - let feed = normalizeFeedUrl source - PackageSource.Parse(feed, parseAuth(line, feed)) + match EnvironmentVariable.Create(source) with + | None -> + let feed = normalizeFeedUrl source + PackageSource.Parse(feed, parseAuth(line, feed)) + | Some var -> + PackageSource.Parse ("source " + var.Value) - static member Parse(source,auth) = + static member Parse(source, auth) = match tryParseWindowsStyleNetworkPath source with | Some path -> PackageSource.Parse(path) | _ -> diff --git a/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs b/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs index 1a5914bc7b..966083bce9 100644 --- a/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs +++ b/tests/Paket.Tests/DependenciesFile/ParserSpecs.fs @@ -750,7 +750,7 @@ nuget Rx-Main let ``should read config with password in env variable``() = Environment.SetEnvironmentVariable("FEED_USERNAME", "user XYZ", EnvironmentVariableTarget.Process) Environment.SetEnvironmentVariable("FEED_PASSWORD", "pw Love", EnvironmentVariableTarget.Process) - let cfg = DependenciesFile.FromSource( configWithPasswordInEnvVariable) + let cfg = DependenciesFile.FromSource(configWithPasswordInEnvVariable) cfg.Groups.[Constants.MainDependencyGroup].Sources |> shouldEqual [ @@ -769,7 +769,7 @@ nuget Rx-Main let ``should read config with password in env variable and auth type specified``() = Environment.SetEnvironmentVariable("FEED_USERNAME", "user XYZ", EnvironmentVariableTarget.Process) Environment.SetEnvironmentVariable("FEED_PASSWORD", "pw Love", EnvironmentVariableTarget.Process) - let cfg = DependenciesFile.FromSource( configWithPasswordInEnvVariableAndAuthType) + let cfg = DependenciesFile.FromSource(configWithPasswordInEnvVariableAndAuthType) cfg.Groups.[Constants.MainDependencyGroup].Sources |> shouldEqual [ @@ -779,6 +779,43 @@ let ``should read config with password in env variable and auth type specified`` cfg.Groups.[Constants.MainDependencyGroup].Sources.Head.Auth.Retrieve true |> shouldEqual (Some (Credentials{ Username = "user XYZ"; Password = "pw Love"; Type = NetUtils.AuthType.NTLM})) +let configWithSourceInEnvVariable = """ +source %FEED_URL% +nuget Rx-Main +""" + +[] +let ``should read config with source in env variable``() = + Environment.SetEnvironmentVariable("FEED_URL", "http://www.nuget.org/api/v2", EnvironmentVariableTarget.Process) + let cfg = DependenciesFile.FromSource(configWithSourceInEnvVariable) + + cfg.Groups.[Constants.MainDependencyGroup].Sources + |> shouldEqual [ + PackageSource.NuGetV2 { + Url = "http://www.nuget.org/api/v2" + Authentication = AuthProvider.empty} ] + + +let configWithSourceAndCredentialsInEnvVariable = """ +source %FEED_URL% +nuget Rx-Main +""" + +[] +let ``should read config with source and credentials in env variable``() = + Environment.SetEnvironmentVariable("FEED_USERNAME", "user XYZ", EnvironmentVariableTarget.Process) + Environment.SetEnvironmentVariable("FEED_PASSWORD", "pw Love", EnvironmentVariableTarget.Process) + Environment.SetEnvironmentVariable("FEED_URL", "http://www.nuget.org/api/v2 username: \"%FEED_USERNAME%\" password: \"%FEED_PASSWORD%\" authtype: \"nTlM\"", EnvironmentVariableTarget.Process) + let cfg = DependenciesFile.FromSource(configWithSourceAndCredentialsInEnvVariable) + + cfg.Groups.[Constants.MainDependencyGroup].Sources + |> shouldEqual [ + PackageSource.NuGetV2 { + Url = "http://www.nuget.org/api/v2" + Authentication = AuthProvider.empty} ] + cfg.Groups.[Constants.MainDependencyGroup].Sources.Head.Auth.Retrieve true + |> shouldEqual (Some (Credentials{ Username = "user XYZ"; Password = "pw Love"; Type = NetUtils.AuthType.NTLM})) + let configWithExplicitVersions = """ source "http://www.nuget.org/api/v2"