Skip to content

Commit 6f1b72d

Browse files
author
github-actions
committed
fix: load configuration with WS-federation options
closes #98
1 parent 0973f1c commit 6f1b72d

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

src/Aguacongas.AspNetCore.Authentication/AuthenticationSchemeOptionsSerializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AuthenticationSchemeOptionsSerializer : IAuthenticationSchemeOption
2626
NullValueHandling = NullValueHandling.Ignore,
2727
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
2828
Formatting = Formatting.None,
29-
DefaultValueHandling = DefaultValueHandling.Ignore,
29+
DefaultValueHandling = DefaultValueHandling.Include,
3030
ContractResolver = new ContractResolver()
3131
};
3232

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Microsoft.AspNetCore.Authentication.WsFederation;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Moq;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using Xunit;
8+
9+
namespace Aguacongas.AspNetCore.Authentication.Test
10+
{
11+
public class ApplicationBuilderExtensionsTest
12+
{
13+
[Fact]
14+
public void LoadDynamicAuthenticationConfiguration_should_load_WsFederationOptions()
15+
{
16+
var serializer = new AuthenticationSchemeOptionsSerializer();
17+
var serialized = serializer.SerializeOptions(new WsFederationOptions
18+
{
19+
RequireHttpsMetadata = false,
20+
MetadataAddress = "http://localhost:5000/wsfederation",
21+
Wtrealm = "urm:aspnetcorerp"
22+
}, typeof(WsFederationOptions));
23+
var storeMock = new Mock<IDynamicProviderStore<SchemeDefinition>>();
24+
storeMock.Setup(m => m.SchemeDefinitions).Returns(new List<string>
25+
{
26+
serialized
27+
}.Select(s => new SchemeDefinition
28+
{
29+
DisplayName = "test",
30+
HandlerType = typeof(WsFederationHandler),
31+
Options = serializer.DeserializeOptions(s, typeof(WsFederationOptions)),
32+
Scheme = "test"
33+
}).AsQueryable());
34+
var services = new ServiceCollection().AddTransient(p => storeMock.Object);
35+
36+
services.AddAuthentication()
37+
.AddDynamic<SchemeDefinition>()
38+
.AddWsFederation();
39+
40+
var provider = services.BuildServiceProvider();
41+
var applicationBuilderMock = new Mock<IApplicationBuilder>();
42+
applicationBuilderMock.SetupGet(m => m.ApplicationServices).Returns(provider);
43+
44+
applicationBuilderMock.Object.LoadDynamicAuthenticationConfiguration<SchemeDefinition>();
45+
46+
Assert.True(true);
47+
}
48+
49+
public class SchemeDefinition : SchemeDefinitionBase
50+
{
51+
52+
}
53+
}
54+
}

test/Aguacongas.AspNetCore.Authentication.Test/AuthenticationSchemeOptionsSerializerTest.cs

+16
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,21 @@ public void DeserializeOptions_should_deserialize_WsFederationOptions()
3838

3939
Assert.False(result.RequireHttpsMetadata);
4040
}
41+
42+
[Fact]
43+
public void SeserializeOptions_should_seserialize_default_value()
44+
{
45+
var sut = new AuthenticationSchemeOptionsSerializer();
46+
var result = sut.SerializeOptions(new WsFederationOptions
47+
{
48+
RequireHttpsMetadata = false
49+
}, typeof(WsFederationOptions));
50+
51+
Assert.Contains(nameof(WsFederationOptions.RequireHttpsMetadata), result);
52+
53+
var deserialized = sut.DeserializeOptions(result, typeof(WsFederationOptions)) as WsFederationOptions;
54+
55+
Assert.False(deserialized.RequireHttpsMetadata);
56+
}
4157
}
4258
}

test/Aguacongas.AspNetCore.Authentication.Test/DynamicManagerTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public async Task Assertions()
5555
await Assert.ThrowsAsync<ArgumentException>(() => manager.FindBySchemeAsync(""));
5656
await Assert.ThrowsAsync<ArgumentException>(() => manager.FindBySchemeAsync(" "));
5757
}
58+
5859
}
5960
public class FakeSchemeDefinition : SchemeDefinitionBase
6061
{ }

0 commit comments

Comments
 (0)