Commit 3470b38de246d223d4c1bcd768a5c3e84c15c4ff
1 parent
96e8df03
完善 OAuth2ClientServiceImpl、OAuth2GrantServiceImpl 单元测试
Showing
2 changed files
with
25 additions
and
1 deletions
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java
| ... | ... | @@ -154,6 +154,19 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | @Test |
| 157 | + public void testGetOAuth2Client() { | |
| 158 | + // mock 数据 | |
| 159 | + OAuth2ClientDO clientDO = randomPojo(OAuth2ClientDO.class); | |
| 160 | + oauth2ClientMapper.insert(clientDO); | |
| 161 | + // 准备参数 | |
| 162 | + Long id = clientDO.getId(); | |
| 163 | + | |
| 164 | + // 调用,并断言 | |
| 165 | + OAuth2ClientDO dbClientDO = oauth2ClientService.getOAuth2Client(id); | |
| 166 | + assertPojoEquals(clientDO, dbClientDO); | |
| 167 | + } | |
| 168 | + | |
| 169 | + @Test | |
| 157 | 170 | public void testGetOAuth2ClientPage() { |
| 158 | 171 | // mock 数据 |
| 159 | 172 | OAuth2ClientDO dbOAuth2Client = randomPojo(OAuth2ClientDO.class, o -> { // 等会查询到 |
| ... | ... | @@ -203,10 +216,13 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { |
| 203 | 216 | null, null, Collections.singleton(randomString()), null), OAUTH2_CLIENT_SCOPE_OVER); |
| 204 | 217 | assertServiceException(() -> oauth2ClientService.validOAuthClientFromCache("default", |
| 205 | 218 | null, null, null, "test"), OAUTH2_CLIENT_REDIRECT_URI_NOT_MATCH, "test"); |
| 206 | - // 成功调用 | |
| 219 | + // 成功调用(1:参数完整) | |
| 207 | 220 | OAuth2ClientDO result = oauth2ClientService.validOAuthClientFromCache(client.getClientId(), client.getSecret(), |
| 208 | 221 | client.getAuthorizedGrantTypes().get(0), client.getScopes(), client.getRedirectUris().get(0)); |
| 209 | 222 | assertPojoEquals(client, result); |
| 223 | + // 成功调用(2:只有 clientId 参数) | |
| 224 | + result = oauth2ClientService.validOAuthClientFromCache(client.getClientId()); | |
| 225 | + assertPojoEquals(client, result); | |
| 210 | 226 | } |
| 211 | 227 | |
| 212 | 228 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2GrantServiceImplTest.java
| ... | ... | @@ -16,6 +16,7 @@ import java.util.List; |
| 16 | 16 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 17 | 17 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 18 | 18 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 19 | +import static java.util.Collections.emptyList; | |
| 19 | 20 | import static org.junit.jupiter.api.Assertions.*; |
| 20 | 21 | import static org.mockito.ArgumentMatchers.eq; |
| 21 | 22 | import static org.mockito.Mockito.when; |
| ... | ... | @@ -135,6 +136,13 @@ public class OAuth2GrantServiceImplTest extends BaseMockitoUnitTest { |
| 135 | 136 | } |
| 136 | 137 | |
| 137 | 138 | @Test |
| 139 | + public void testGrantClientCredentials() { | |
| 140 | + assertThrows(UnsupportedOperationException.class, | |
| 141 | + () -> oauth2GrantService.grantClientCredentials(randomString(), emptyList()), | |
| 142 | + "暂时不支持 client_credentials 授权模式"); | |
| 143 | + } | |
| 144 | + | |
| 145 | + @Test | |
| 138 | 146 | public void testRevokeToken_clientIdError() { |
| 139 | 147 | // 准备参数 |
| 140 | 148 | String clientId = randomString(); | ... | ... |