Skip to content

Commit

Permalink
auto adding the AntiForgeryPolicy. Closes FubuMvcArchiveGH-4
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Feb 18, 2014
1 parent 9f1213d commit 0b78275
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
Binary file modified src/FubuMVC.AntiForgery.Docs/pak-WebContent.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Linq;
using FubuMVC.Core;
using FubuMVC.Core.Registration;
using FubuMVC.StructureMap;
using FubuTestingSupport;
using HtmlTags;
using NUnit.Framework;
using StructureMap;

namespace FubuMVC.AntiForgery.Testing
{
[TestFixture]
public class Default_policy_applies_anti_forgery_to_post_routes
{
[Test]
public void the_order_of_the_configuration_action_was_wrong()
{
var registry = new FubuRegistry();
registry.Actions.IncludeType<TestEndpoint>();
using (var runtime = FubuApplication.For(registry).ContainerFacility(new StructureMapContainerFacility(new Container())).Bootstrap())
{
var graph = runtime.Factory.Get<BehaviorGraph>();

graph.BehaviorFor<TestEndpoint>(x => x.post_csrf(null))
.OfType<AntiForgeryNode>().Any()
.ShouldBeTrue();
}


}
}

public class TestEndpoint
{
public HtmlTag post_csrf(PostRequest request)
{
return new HtmlTag("h1", h => h.Text("POST HOLA"));
}

public HtmlTag get_csrf(GetRequest request)
{
return new HtmlTag("h1", h => h.Text("GET HOLA"));
}
}

public class GetResult
{
}

public class GetRequest
{
}

public class PostRequest
{
}

public class PostResult
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<Reference Include="FubuMVC.Core.View">
<HintPath>..\packages\FubuMVC.Core.View\lib\net40\FubuMVC.Core.View.dll</HintPath>
</Reference>
<Reference Include="FubuMVC.StructureMap">
<HintPath>..\packages\FubuMVC.StructureMap\lib\net40\FubuMVC.StructureMap.dll</HintPath>
</Reference>
<Reference Include="FubuTestingSupport">
<HintPath>..\packages\FubuTestingSupport\lib\FubuTestingSupport.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -92,6 +95,7 @@
<Compile Include="AntiForgeryTokenProviderTester.cs" />
<Compile Include="AntiForgeryValidatorTester.cs" />
<Compile Include="BinaryAntiForgerySerializerTester.cs" />
<Compile Include="Default_policy_applies_anti_forgery_to_post_routes.cs" />
<Compile Include="MachineKeyAntiForgeryEncoderTester.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/FubuMVC.AntiForgery/AntiForgeryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public void Configure(FubuRegistry registry)
{
registry.Services<AntiForgeryServiceRegistry>();
registry.Import<HtmlConventionRegistry>(x => x.Forms.Add(new AntiForgeryTagModifier()));
registry.Policies.Add<AntiForgeryPolicy>();
}
}
}
4 changes: 3 additions & 1 deletion src/FubuMVC.AntiForgery/AntiForgeryPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using FubuMVC.Core;
using FubuMVC.Core.Registration;

namespace FubuMVC.AntiForgery
{
[ConfigurationType(ConfigurationType.InjectNodes)]
public class AntiForgeryPolicy : IConfigurationAction
{
public void Configure(BehaviorGraph graph)
Expand Down

0 comments on commit 0b78275

Please sign in to comment.