Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

packages updated #110

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions WebApiThrottle.StrongName/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -33,4 +32,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
13 changes: 7 additions & 6 deletions WebApiThrottle.StrongName/WebApiThrottle.StrongName.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@
<AssemblyOriginatorKeyFile>WebApiThrottle.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
<Reference Include="Microsoft.Owin, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.3.1.0\lib\net45\Microsoft.Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -75,6 +74,8 @@
<Compile Include="../WebApiThrottle/**/*.cs" Exclude="../WebApiThrottle/obj/**/*.*;../WebApiThrottle/**/AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="WebApiThrottle.snk" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
12 changes: 12 additions & 0 deletions WebApiThrottle.StrongName/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
5 changes: 3 additions & 2 deletions WebApiThrottle.StrongName/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="Microsoft.Owin" version="3.1.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
</packages>
43 changes: 19 additions & 24 deletions WebApiThrottle.Tests/IpAddressUtilTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebApiThrottle.Net;
using WebApiThrottle.Net;
using Xunit;

namespace WebApiThrottle.Tests
Expand All @@ -13,57 +8,57 @@ public class IpAddressUtilTests
[Fact]
public void IsPrivateIpAddress_PrivateAddress_ReturnsTrue()
{
bool result = IpAddressUtil.IsPrivateIpAddress("10.0.0.1");
var result = IpAddressUtil.IsPrivateIpAddress("10.0.0.1");

Assert.Equal(true, result);
}

[Fact]
public void IsPrivateIpAddress_PublicAddress_ReturnsFalse()
public void IsPrivateIpAddress_PrivateAddressIpv6_ReturnsFalse()
{
bool result = IpAddressUtil.IsPrivateIpAddress("8.8.8.8");
var result = IpAddressUtil.IsPrivateIpAddress("fd74:20cf:81a2::");

Assert.Equal(false, result);
Assert.Equal(true, result);
}

[Fact]
public void IsPrivateIpAddress_PublicAddressIpv6_ReturnsFalse()
public void IsPrivateIpAddress_PrivateAddressIpv6WithPort_ReturnsTrue()
{
bool result = IpAddressUtil.IsPrivateIpAddress("2001:4860:4860::8888");
var result = IpAddressUtil.IsPrivateIpAddress("[fd74:20cf:81a2::]:5555");

Assert.Equal(false, result);
Assert.Equal(true, result);
}

[Fact]
public void IsPrivateIpAddress_PrivateAddressIpv6_ReturnsFalse()
public void IsPrivateIpAddress_PrivateAddressWithPort_ReturnsTrue()
{
bool result = IpAddressUtil.IsPrivateIpAddress("fd74:20cf:81a2::");
var result = IpAddressUtil.IsPrivateIpAddress("10.0.0.1:5555");

Assert.Equal(true, result);
}

[Fact]
public void IsPrivateIpAddress_PrivateAddressWithPort_ReturnsTrue()
public void IsPrivateIpAddress_PublicAddress_ReturnsFalse()
{
bool result = IpAddressUtil.IsPrivateIpAddress("10.0.0.1:5555");
var result = IpAddressUtil.IsPrivateIpAddress("8.8.8.8");

Assert.Equal(true, result);
Assert.Equal(false, result);
}

[Fact]
public void IsPrivateIpAddress_PrivateAddressIpv6WithPort_ReturnsTrue()
public void IsPrivateIpAddress_PublicAddressIpv6_ReturnsFalse()
{
bool result = IpAddressUtil.IsPrivateIpAddress("[fd74:20cf:81a2::]:5555");
var result = IpAddressUtil.IsPrivateIpAddress("2001:4860:4860::8888");

Assert.Equal(true, result);
Assert.Equal(false, result);
}

[Fact]
public void IsPrivateIpAddress_PublicIpAddressWithInitialSpace_ReturnsFalse()
{
bool result = IpAddressUtil.IsPrivateIpAddress(" 8.8.8.8");
var result = IpAddressUtil.IsPrivateIpAddress(" 8.8.8.8");

Assert.Equal(false, result);
}
}
}
}
3 changes: 1 addition & 2 deletions WebApiThrottle.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -33,4 +32,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
39 changes: 25 additions & 14 deletions WebApiThrottle.Tests/WebApiThrottle.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.core.2.3.0\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.3.0\build\xunit.core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -11,6 +12,8 @@
<AssemblyName>WebApiThrottle.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -39,36 +42,44 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
<Private>True</Private>
<Reference Include="xunit.assert, Version=2.3.0.3820, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.3.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
<Private>True</Private>
<Reference Include="xunit.core, Version=2.3.0.3820, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.3.0\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
<Private>True</Private>
<Reference Include="xunit.execution.desktop, Version=2.3.0.3820, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.3.0\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="IpAddressUtilTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WebApiThrottle.StrongName\WebApiThrottle.StrongName.csproj">
<Project>{FBF3012B-08EF-408C-9E7D-175ABF286CB4}</Project>
<Name>WebApiThrottle.StrongName</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\xunit.analyzers.0.7.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Este proyecto hace referencia a los paquetes NuGet que faltan en este equipo. Use la restauración de paquetes NuGet para descargarlos. Para obtener más información, consulte http://go.microsoft.com/fwlink/?LinkID=322105. El archivo que falta es {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.core.2.3.0\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.0\build\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.3.0\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.0\build\xunit.core.targets'))" />
</Target>
<Import Project="..\packages\xunit.core.2.3.0\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.3.0\build\xunit.core.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
12 changes: 12 additions & 0 deletions WebApiThrottle.Tests/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
14 changes: 8 additions & 6 deletions WebApiThrottle.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="xunit" version="2.1.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
<package id="xunit.assert" version="2.1.0" targetFramework="net452" />
<package id="xunit.core" version="2.1.0" targetFramework="net452" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net452" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net452" />
<package id="xunit" version="2.3.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" />
<package id="xunit.analyzers" version="0.7.0" targetFramework="net452" />
<package id="xunit.assert" version="2.3.0" targetFramework="net452" />
<package id="xunit.core" version="2.3.0" targetFramework="net452" />
<package id="xunit.extensibility.core" version="2.3.0" targetFramework="net452" />
<package id="xunit.extensibility.execution" version="2.3.0" targetFramework="net452" />
</packages>
41 changes: 21 additions & 20 deletions WebApiThrottle.WebApiDemo/App_Start/WebApiConfig.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Web.Http;
using System.Web.Http.Tracing;
using WebApiThrottle.Logging;
using WebApiThrottle.Models;
using WebApiThrottle.Repositories;
using WebApiThrottle.WebApiDemo.Net;

namespace WebApiThrottle.WebApiDemo
Expand All @@ -15,13 +16,13 @@ public static void Register(HttpConfiguration config)
config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
"DefaultApi",
"api/{controller}/{id}",
new {id = RouteParameter.Optional}
);

//trace provider
var traceWriter = new SystemDiagnosticsTraceWriter()
var traceWriter = new SystemDiagnosticsTraceWriter
{
IsVerbose = true
};
Expand All @@ -30,39 +31,39 @@ public static void Register(HttpConfiguration config)

//Web API throttling handler
config.MessageHandlers.Add(new ThrottlingHandler(
policy: new ThrottlePolicy(perMinute: 20, perHour: 30, perDay: 35, perWeek: 3000)
new ThrottlePolicy(perMinute: 20, perHour: 30, perDay: 35, perWeek: 3000)
{
//scope to IPs
IpThrottling = true,
IpRules = new Dictionary<string, RateLimits>
{
{ "::1/10", new RateLimits { PerSecond = 2 } },
{ "192.168.2.1", new RateLimits { PerMinute = 30, PerHour = 30*60, PerDay = 30*60*24 } }
{"::1/10", new RateLimits {PerSecond = 2}},
{"192.168.2.1", new RateLimits {PerMinute = 30, PerHour = 30 * 60, PerDay = 30 * 60 * 24}}
},
//white list the "::1" IP to disable throttling on localhost for Win8
IpWhitelist = new List<string> { "127.0.0.1", "192.168.0.0/24" },
IpWhitelist = new List<string> {"127.0.0.1", "192.168.0.0/24"},

//scope to clients (if IP throttling is applied then the scope becomes a combination of IP and client key)
ClientThrottling = true,
ClientRules = new Dictionary<string, RateLimits>
{
{ "api-client-key-1", new RateLimits { PerMinute = 60, PerHour = 600 } },
{ "api-client-key-9", new RateLimits { PerDay = 5000 } }
{"api-client-key-1", new RateLimits {PerMinute = 60, PerHour = 600}},
{"api-client-key-9", new RateLimits {PerDay = 5000}}
},
//white list API keys that don’t require throttling
ClientWhitelist = new List<string> { "admin-key" },
ClientWhitelist = new List<string> {"admin-key"},

//scope to endpoints
EndpointThrottling = true,
EndpointRules = new Dictionary<string, RateLimits>
{
{ "api/search", new RateLimits { PerSecond = 10, PerMinute = 100, PerHour = 1000 } }
{"api/search", new RateLimits {PerSecond = 10, PerMinute = 100, PerHour = 1000}}
}
},
policyRepository: new PolicyCacheRepository(),
repository: new CacheRepository(),
logger: new TracingThrottleLogger(traceWriter),
ipAddressParser: new CustomIpAddressParser()));
new PolicyCacheRepository(),
new CacheRepository(),
new TracingThrottleLogger(traceWriter),
new CustomIpAddressParser()));

//Web API throttling handler load policy from web.config
//config.MessageHandlers.Add(new ThrottlingHandler(
Expand Down Expand Up @@ -110,4 +111,4 @@ public static void Register(HttpConfiguration config)
// logger: new TracingThrottleLogger(traceWriter)));
}
}
}
}
Loading