Skip to content

Commit c6de376

Browse files
Move Wechat tests to Weixin
Move the Wechat-specific tests to the WeixinTests class to match the way the rest of the test project is organised.
1 parent 8a36e04 commit c6de376

File tree

4 files changed

+81
-133
lines changed

4 files changed

+81
-133
lines changed

test/AspNet.Security.OAuth.Providers.Tests/Wechat/WechatTests.cs

Lines changed: 0 additions & 78 deletions
This file was deleted.

test/AspNet.Security.OAuth.Providers.Tests/Wechat/bundle.json

Lines changed: 0 additions & 54 deletions
This file was deleted.

test/AspNet.Security.OAuth.Providers.Tests/Weixin/WeixinTests.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,67 @@ public async Task Can_Sign_In_Using_Weixin(string claimType, string claimValue)
4444
AssertClaim(claims, claimType, claimValue);
4545
}
4646

47+
[Theory]
48+
[InlineData(ClaimTypes.NameIdentifier, "my-id")]
49+
[InlineData(ClaimTypes.Name, "John Smith")]
50+
[InlineData(ClaimTypes.Gender, "Male")]
51+
[InlineData(ClaimTypes.Country, "CN")]
52+
[InlineData("urn:weixin:city", "Beijing")]
53+
[InlineData("urn:weixin:headimgurl", "https://weixin.qq.local/image.png")]
54+
[InlineData("urn:weixin:openid", "my-open-id")]
55+
[InlineData("urn:weixin:privilege", "a,b,c")]
56+
[InlineData("urn:weixin:province", "Hebei")]
57+
public async Task Can_Sign_In_Using_Wechat(string claimType, string claimValue)
58+
{
59+
// Arrange
60+
static void ConfigureServices(IServiceCollection services)
61+
{
62+
services.PostConfigureAll<WeixinAuthenticationOptions>((options) =>
63+
{
64+
options.AuthorizationEndpoint = "https://open.weixin.qq.com/connect/oauth2/authorize";
65+
});
66+
}
67+
68+
using var server = CreateTestServer(ConfigureServices);
69+
70+
// Act
71+
var claims = await AuthenticateUserAsync(server);
72+
73+
// Assert
74+
AssertClaim(claims, claimType, claimValue);
75+
}
76+
77+
[Theory]
78+
[InlineData(ClaimTypes.NameIdentifier, "my-open-id")]
79+
[InlineData(ClaimTypes.Name, "John Smith")]
80+
[InlineData(ClaimTypes.Gender, "Male")]
81+
[InlineData(ClaimTypes.Country, "CN")]
82+
[InlineData("urn:weixin:city", "Beijing")]
83+
[InlineData("urn:weixin:headimgurl", "https://weixin.qq.local/image.png")]
84+
[InlineData("urn:weixin:openid", "my-open-id")]
85+
[InlineData("urn:weixin:privilege", "a,b,c")]
86+
[InlineData("urn:weixin:province", "Hebei")]
87+
public async Task Can_Sign_In_Using_Weixin_With_No_Union_Id(string claimType, string claimValue)
88+
{
89+
// Arrange
90+
static void ConfigureServices(IServiceCollection services)
91+
{
92+
services.PostConfigureAll<WeixinAuthenticationOptions>((options) =>
93+
{
94+
options.AuthorizationEndpoint = "https://open.weixin.qq.com/connect/oauth2/authorize";
95+
options.UserInformationEndpoint = "https://api.weixin.qq.com/sns/userinfo/nounionid";
96+
});
97+
}
98+
99+
using var server = CreateTestServer(ConfigureServices);
100+
101+
// Act
102+
var claims = await AuthenticateUserAsync(server);
103+
104+
// Assert
105+
AssertClaim(claims, claimType, claimValue);
106+
}
107+
47108
[Theory]
48109
[InlineData(false)]
49110
[InlineData(true)]
@@ -55,7 +116,7 @@ public async Task BuildChallengeUrl_Generates_Correct_Url(bool usePkce)
55116
UsePkce = usePkce,
56117
};
57118

58-
string redirectUrl = "https://my-site.local/signin-weixin";
119+
var redirectUrl = "https://my-site.local/signin-weixin";
59120

60121
// Act
61122
Uri actual = await BuildChallengeUriAsync(

test/AspNet.Security.OAuth.Providers.Tests/Weixin/bundle.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@
3030
"c"
3131
]
3232
}
33+
},
34+
{
35+
"uri": "https://api.weixin.qq.com/sns/userinfo/nounionid?access_token=secret-access-token&openid=my-open-id",
36+
"contentFormat": "json",
37+
"contentJson": {
38+
"unionid": "",
39+
"nickname": "John Smith",
40+
"sex": "Male",
41+
"country": "CN",
42+
"openid": "my-open-id",
43+
"province": "Hebei",
44+
"city": "Beijing",
45+
"headimgurl": "https://weixin.qq.local/image.png",
46+
"privilege": [
47+
"a",
48+
"b",
49+
"c"
50+
]
51+
}
3352
}
3453
]
3554
}

0 commit comments

Comments
 (0)