Skip to content

Commit

Permalink
7.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
huangxiangyao committed Sep 17, 2023
1 parent cfb8c6d commit 1f0964e
Show file tree
Hide file tree
Showing 16 changed files with 2,102 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<PropertyGroup>
<MinVerVersion>6.0.22</MinVerVersion>
<MinVerVersion>7.0.11</MinVerVersion>
<MinVerDefaultPreReleaseIdentifiers>alpha</MinVerDefaultPreReleaseIdentifiers>
</PropertyGroup>
<Target Name="CustomFileVersion" AfterTargets="MinVer">
Expand Down
7 changes: 7 additions & 0 deletions WeixinAuth.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeixinAuth.UnitTest_3_1", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeixinAuth.UnitTest_5_0", "test\WeixinAuth.UnitTest_5_0\WeixinAuth.UnitTest_5_0.csproj", "{B812C99A-70DF-4EB6-95B6-E3B8CECE5A3A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QQConnect.UnitTest_6_0", "..\Myvas.AspNetCore.Authentication.QQConnect\test\QQConnect.UnitTest_6_0\QQConnect.UnitTest_6_0.csproj", "{5198DC01-2C6E-461C-A051-E9F0AF1A8640}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -50,6 +52,10 @@ Global
{B812C99A-70DF-4EB6-95B6-E3B8CECE5A3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B812C99A-70DF-4EB6-95B6-E3B8CECE5A3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B812C99A-70DF-4EB6-95B6-E3B8CECE5A3A}.Release|Any CPU.Build.0 = Release|Any CPU
{5198DC01-2C6E-461C-A051-E9F0AF1A8640}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5198DC01-2C6E-461C-A051-E9F0AF1A8640}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5198DC01-2C6E-461C-A051-E9F0AF1A8640}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5198DC01-2C6E-461C-A051-E9F0AF1A8640}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -59,6 +65,7 @@ Global
{94ABBE67-3755-4DD1-A25E-2407FB32C60E} = {73FCFCF4-3A1C-4D4D-939A-9CABDC2341DC}
{688F627F-FF2D-4FE4-BAA7-BD94C139798B} = {73FCFCF4-3A1C-4D4D-939A-9CABDC2341DC}
{B812C99A-70DF-4EB6-95B6-E3B8CECE5A3A} = {73FCFCF4-3A1C-4D4D-939A-9CABDC2341DC}
{5198DC01-2C6E-461C-A051-E9F0AF1A8640} = {73FCFCF4-3A1C-4D4D-939A-9CABDC2341DC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2AEDFD1F-BBE1-4727-9978-2FB04DCE84AF}
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.100",
"version": "7.0.100",
"rollForward": "latestFeature"
}
}
179 changes: 86 additions & 93 deletions src/WeixinAuth/Helpers/CompressionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,93 +1,86 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Myvas.AspNetCore.Authentication.WeixinAuth.Internal
{
/// <summary>
/// ref. https://stackoverflow.com/questions/7343465/compression-decompression-string-with-c-sharp
/// </summary>
static internal class CompressionExtensions
{
public static async Task<IEnumerable<byte>> Zip(this object obj)
{
byte[] bytes = obj.Serialize();

using (MemoryStream msi = new MemoryStream(bytes))
using (MemoryStream mso = new MemoryStream())
{
using (var gs = new GZipStream(mso, CompressionMode.Compress))
await msi.CopyToAsync(gs);

return mso.ToArray().AsEnumerable();
}
}

public static async Task<object> Unzip(this byte[] bytes)
{
using (MemoryStream msi = new MemoryStream(bytes))
using (MemoryStream mso = new MemoryStream())
{
using (var gs = new GZipStream(msi, CompressionMode.Decompress))
{
//gs.CopyTo(mso);
await gs.CopyToAsync(mso);
}

return mso.ToArray().Deserialize();
}
}
}

internal static class SerializerExtensions
{
/// <summary>
/// Writes the given object instance to a binary file.
/// <para>Object type (and all child types) must be decorated with the [Serializable] attribute.</para>
/// <para>To prevent a variable from being serialized, decorate it with the [NonSerialized] attribute; cannot be applied to properties.</para>
/// </summary>
/// <typeparam name="T">The type of object being written to the XML file.</typeparam>
/// <param name="filePath">The file path to write the object instance to.</param>
/// <param name="objectToWrite">The object instance to write to the XML file.</param>
/// <param name="append">If false the file will be overwritten if it already exists. If true the contents will be appended to the file.</param>
public static byte[] Serialize<T>(this T objectToWrite)
{
using (MemoryStream stream = new MemoryStream())
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(stream, objectToWrite);

return stream.GetBuffer();
}
}

/// <summary>
/// Reads an object instance from a binary file.
/// </summary>
/// <typeparam name="T">The type of object to read from the XML.</typeparam>
/// <param name="filePath">The file path to read the object instance from.</param>
/// <returns>Returns a new instance of the object read from the binary file.</returns>
public static async Task<T> _Deserialize<T>(this byte[] arr)
{
using (MemoryStream stream = new MemoryStream())
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
await stream.WriteAsync(arr, 0, arr.Length);
stream.Position = 0;

return (T)binaryFormatter.Deserialize(stream);
}
}

public static async Task<object> Deserialize(this byte[] arr)
{
object obj = await arr._Deserialize<object>();
return obj;
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Myvas.AspNetCore.Authentication.WeixinAuth.Internal
{
/// <summary>
/// ref. https://stackoverflow.com/questions/7343465/compression-decompression-string-with-c-sharp
/// </summary>
static internal class CompressionExtensions
{
public static async Task<IEnumerable<byte>> Zip(this object obj)
{
byte[] bytes = obj.Serialize();

using (MemoryStream msi = new MemoryStream(bytes))
using (MemoryStream mso = new MemoryStream())
{
using (var gs = new GZipStream(mso, CompressionMode.Compress))
await msi.CopyToAsync(gs);

return mso.ToArray().AsEnumerable();
}
}

public static async Task<object> Unzip(this byte[] bytes)
{
using (MemoryStream msi = new MemoryStream(bytes))
using (MemoryStream mso = new MemoryStream())
{
using (var gs = new GZipStream(msi, CompressionMode.Decompress))
{
//gs.CopyTo(mso);
await gs.CopyToAsync(mso);
}

return mso.ToArray().Deserialize();
}
}
}

internal static class SerializerExtensions
{
/// <summary>
/// Writes the given object instance to a binary file.
/// <para>Object type (and all child types) must be decorated with the [Serializable] attribute.</para>
/// <para>To prevent a variable from being serialized, decorate it with the [NonSerialized] attribute; cannot be applied to properties.</para>
/// </summary>
/// <typeparam name="T">The type of object being written to the XML file.</typeparam>
/// <param name="filePath">The file path to write the object instance to.</param>
/// <param name="objectToWrite">The object instance to write to the XML file.</param>
/// <param name="append">If false the file will be overwritten if it already exists. If true the contents will be appended to the file.</param>
public static byte[] Serialize<T>(this T objectToWrite)
{
using var stream = new MemoryStream();
var serializer = new XmlSerializer(typeof(T));
serializer.Serialize(stream, objectToWrite);
return stream.GetBuffer();
}

/// <summary>
/// Reads an object instance from a binary file.
/// </summary>
/// <typeparam name="T">The type of object to read from the XML.</typeparam>
/// <param name="filePath">The file path to read the object instance from.</param>
/// <returns>Returns a new instance of the object read from the binary file.</returns>
public static async Task<T> _Deserialize<T>(this byte[] arr)
{
using var stream = new MemoryStream(arr);
var serializer = new XmlSerializer(typeof(T));
return await Task.FromResult((T)serializer.Deserialize(stream));
}

public static async Task<object> Deserialize(this byte[] arr)
{
object obj = await arr._Deserialize<object>();
return obj;
}
}
}
6 changes: 5 additions & 1 deletion src/WeixinAuth/WeixinAuth.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<!--<Nullable>enable</Nullable>-->
<PackageId>Myvas.AspNetCore.Authentication.WeixinAuth</PackageId>
Expand All @@ -18,6 +18,10 @@
<Product>Myvas.AspNetCore.Authentication</Product>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="6.0.0" />
</ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions test/WeixinAuth.UnitTest/WeixinAuth.UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.22" />
<PackageReference Include="Microsoft.CodeCoverage" Version="17.7.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.*" />
<PackageReference Include="Microsoft.CodeCoverage" Version="17.7.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.*" />
<PackageReference Include="xunit" Version="2.5.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
9 changes: 5 additions & 4 deletions test/WeixinAuth.UnitTest/WeixinAuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ public async Task ChallengeWillTriggerApplyRedirectEvent()
}

[Fact]
public async Task AuthenticateWithoutCookieWillFail()
public async Task AuthenticateWithoutCookieWillReturnNone()
{
var server = CreateServer(o =>
{
Expand All @@ -748,9 +748,10 @@ public async Task AuthenticateWithoutCookieWillFail()
var res = context.Response;
if (req.Path == new PathString("/auth"))
{
var result = await context.AuthenticateAsync("WeixinAuth");
Assert.NotNull(result.Failure);
}
var result = await context.AuthenticateAsync("WeixinAuth");
//Assert.NotNull(result.Failure);
Assert.True(result.None);
}
});
var transaction = await server.SendAsync("https://example.com/auth");
Assert.Equal(HttpStatusCode.OK, transaction.Response.StatusCode);
Expand Down
8 changes: 4 additions & 4 deletions test/WeixinAuth.UnitTest_3_1/WeixinAuth.UnitTest_3_1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.32" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.*" />
<PackageReference Include="xunit" Version="2.4.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
9 changes: 4 additions & 5 deletions test/WeixinAuth.UnitTest_5_0/WeixinAuth.UnitTest_5_0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.15" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.*" />
<PackageReference Include="xunit" Version="2.4.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 1f0964e

Please sign in to comment.