use of com.stardata.starshop2.authcontext.domain.WxLoginErrorException in project starshop by beautautumn.
the class StarshopAuthLoginTests method should_wx_login_by_invalid_code_given_login_biz_exception.
// 3.4. 微信后台登录并校验;(组合任务,领域服务,微信code无效)
@Test
void should_wx_login_by_invalid_code_given_login_biz_exception() {
// given: 有效的微信前端code、有效的微信认证用户rawData和signature
String code = "testCode";
String rawData = "testRawData";
String signature = "testSignature";
WxAuthInfo wxAuthInfo = new WxAuthInfo(rawData, signature);
try {
// when: 调用微信登录服务 WxLoginService.wxLogin
WxOpenId wxOpenId = wxLoginService.wxLogin(code, wxAuthInfo);
// 正常情况下不应该执行到这儿
assertEquals(0, 1);
} catch (WxLoginErrorException e) {
// then: 抛出"微信登录错误"异常
assertTrue(e.getErrCode() == 40029 || e.getErrCode() == 45011 || e.getErrCode() == 40226);
assertNotNull(e);
}
}
use of com.stardata.starshop2.authcontext.domain.WxLoginErrorException in project starshop by beautautumn.
the class StarshopAuthLoginTests method should_wx_login_exception_given_valid_and_unused_code_but_signature_error.
// 3.2. 微信后台登录并校验;(组合任务,领域服务,微信code有效且未被使用过,但signature 不正确)
@Test
void should_wx_login_exception_given_valid_and_unused_code_but_signature_error() {
// given: 有效的微信前端code、有效的微信认证用户rawData和signature
String code = "081sloll28T8d94nl8nl2hxKhh3slolv";
String rawData = "{\"nickName\":\"深清秋\",\"gender\":0,\"language\":\"zh_CN\",\"city\":\"\",\"province\":\"\",\"country\":\"\",\"avatarUrl\":\"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKq2CRmib1mpu4hOFYtcIHgAmS7DicCEfYkUHoPmPQn74BXH5GerjoMOxIqib7iafNNBw2ZAicBj6gZGUQ/132\"}";
String signature = "06846a4ba8b003af5d98fadfaf376a652e5d75d8";
WxAuthInfo wxAuthInfo = new WxAuthInfo(rawData, signature);
try {
// when: 调用微信登录服务 WxLoginService.wxLogin
WxOpenId wxOpenId = wxLoginService.wxLogin(code, wxAuthInfo);
} catch (WxLoginErrorException e) {
// then: 抛出"Checking userinfo integrity failed"异常
assertNotNull(e);
assertEquals(e.getErrCode(), -99);
}
}
use of com.stardata.starshop2.authcontext.domain.WxLoginErrorException in project starshop by beautautumn.
the class StarshopAuthLoginTests method should_wx_login_with_token_exception_given_valid_and_unused_code_but_signature_error.
// 4.2. 微信登录异常,未生成微信登录令牌;(组合任务,领域服务)
@Test
@Transactional
@Rollback(true)
void should_wx_login_with_token_exception_given_valid_and_unused_code_but_signature_error() {
// given: 有效的微信前端code、有效的微信认证用户rawData和signature、有效的用户信息
String code = "081sloll28T8d94nl8nl2hxKhh3slolv";
String rawData = "{\"nickName\":\"深清秋\",\"gender\":0,\"language\":\"zh_CN\",\"city\":\"\",\"province\":\"\",\"country\":\"\",\"avatarUrl\":\"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKq2CRmib1mpu4hOFYtcIHgAmS7DicCEfYkUHoPmPQn74BXH5GerjoMOxIqib7iafNNBw2ZAicBj6gZGUQ/132\"}";
String signature = "06846a4ba8b003af5d98fadfaf376a652e5d75d8";
WxAuthInfo wxAuthInfo = new WxAuthInfo(rawData, signature);
User frontUser = User.of("testUser", 2).avatarUrl("testUrl").country("testCountry").province("testProvince").city("testCity").language("testLanguage");
try {
// when: 调用wxLoginWithTokenService.loginWithToken()
User loginUser = wxLoginWithTokenService.loginWithToken(code, wxAuthInfo, frontUser);
// 如下代码应该不被执行
UserToken token = loginUser.currentToken();
WxOpenId openid = loginUser.getOpenid();
assertNotNull(token);
assertFalse(StringUtils.isBlank(token.getToken()));
assertNotNull(openid);
assertFalse(StringUtils.isBlank(openid.toString()));
} catch (WxLoginErrorException e) {
// then: 有效的用户令牌
// then: 抛出"Checking userinfo integrity failed"异常
assertNotNull(e);
assertEquals(e.getErrCode(), -99);
}
}
Aggregations