-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Fix WxCpTpUserService.listSimpleByDepartment using suite_access_token instead of access_token #3928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+141
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpUserServiceImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package me.chanjar.weixin.cp.tp.service.impl; | ||
|
|
||
| import me.chanjar.weixin.common.error.WxErrorException; | ||
| import me.chanjar.weixin.cp.bean.WxCpUser; | ||
| import me.chanjar.weixin.cp.config.WxCpTpConfigStorage; | ||
| import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl; | ||
| import me.chanjar.weixin.cp.tp.service.WxCpTpUserService; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
| import org.testng.annotations.AfterClass; | ||
| import org.testng.annotations.BeforeClass; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.User.USER_SIMPLE_LIST; | ||
| import static org.mockito.ArgumentMatchers.contains; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.testng.Assert.assertNotNull; | ||
|
|
||
| /** | ||
| * 企业微信-第三方开发-用户管理相关测试. | ||
| * | ||
| * @author GitHub Copilot | ||
| */ | ||
| public class WxCpTpUserServiceImplTest { | ||
|
|
||
| @Mock | ||
| private WxCpTpServiceApacheHttpClientImpl wxCpTpService; | ||
|
|
||
| @Mock | ||
| private WxCpTpConfigStorage configStorage; | ||
|
|
||
| private WxCpTpUserService wxCpTpUserService; | ||
|
|
||
| private AutoCloseable mockitoAnnotations; | ||
|
|
||
| /** | ||
| * Sets up. | ||
| */ | ||
| @BeforeClass | ||
| public void setUp() { | ||
| mockitoAnnotations = MockitoAnnotations.openMocks(this); | ||
| when(wxCpTpService.getWxCpTpConfigStorage()).thenReturn(configStorage); | ||
| WxCpTpDefaultConfigImpl defaultConfig = new WxCpTpDefaultConfigImpl(); | ||
| when(configStorage.getApiUrl(contains(USER_SIMPLE_LIST))) | ||
| .thenAnswer(invocation -> defaultConfig.getApiUrl(invocation.getArgument(0))); | ||
| wxCpTpUserService = new WxCpTpUserServiceImpl(wxCpTpService); | ||
| } | ||
|
|
||
| /** | ||
| * Tear down. | ||
| * | ||
| * @throws Exception the exception | ||
| */ | ||
| @AfterClass | ||
| public void tearDown() throws Exception { | ||
| mockitoAnnotations.close(); | ||
| } | ||
|
|
||
| /** | ||
| * 测试使用 corpId 的 listSimpleByDepartment 方法,验证请求使用了 access_token 而非 suite_access_token. | ||
| * | ||
| * @throws WxErrorException the wx error exception | ||
| */ | ||
| @Test | ||
| public void testListSimpleByDepartmentWithCorpId() throws WxErrorException { | ||
| Long departId = 1L; | ||
| String corpId = "test_corp_id"; | ||
| String accessToken = "test_access_token"; | ||
| String result = "{\"errcode\":0,\"errmsg\":\"ok\",\"userlist\":[{\"userid\":\"zhangsan\",\"name\":\"张三\"}]}"; | ||
|
|
||
| when(configStorage.getAccessToken(corpId)).thenReturn(accessToken); | ||
| String url = new WxCpTpDefaultConfigImpl().getApiUrl(USER_SIMPLE_LIST + departId); | ||
| when(wxCpTpService.get(eq(url), contains("access_token=" + accessToken), eq(true))).thenReturn(result); | ||
|
|
||
| List<WxCpUser> users = wxCpTpUserService.listSimpleByDepartment(departId, true, 0, corpId); | ||
| assertNotNull(users); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // 验证调用时传入了 withoutSuiteAccessToken=true,确保不会附加 suite_access_token | ||
| verify(wxCpTpService).get(eq(url), contains("access_token=" + accessToken), eq(true)); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里在公共接口
WxCpTpUserService上新增了一个非default方法签名,会对下游自定义实现该接口的项目造成编译期不兼容(必须新增实现)。建议确认这类 API 变更在当前版本发布语义下是可接受的。Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.