fix: 小程序服务号绑定先打开门户域名再跳转微信授权。
web-view 不能直接打开 open.weixin.qq.com,移动端改为打开已配置的业务域名中转页。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
459b820f95
commit
e7c1762113
7 files changed
+137
-8
No files matched your search
@@ -174,6 +174,32 @@ def test_callback_instructs_mobile_return_without_binding(binding, monkeypatch):
|
||||
assert response.headers['referrer-policy'] == 'no-referrer'
|
||||
|
||||
|
||||
def test_mobile_web_view_opens_business_domain_before_wechat(binding):
|
||||
from app.api.wechat_notices import oauth_launch
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
svc, _, redis, user, _ = binding
|
||||
started = svc.start_binding(user, mode='mobile')
|
||||
launch = urlparse(started['authorizeUrl'])
|
||||
assert launch.scheme == 'https'
|
||||
assert launch.netloc == 'portal.example.test'
|
||||
assert launch.path == '/api/public/wechat-notices/oauth/launch'
|
||||
assert 'open.weixin.qq.com' not in started['authorizeUrl']
|
||||
state = parse_qs(launch.query)['state'][0]
|
||||
page = oauth_launch(state)
|
||||
body = page.body.decode()
|
||||
assert 'location.replace' in body
|
||||
assert 'open.weixin.qq.com/connect/oauth2/authorize' in body
|
||||
assert state in body
|
||||
assert "'unsafe-inline'" not in page.headers['content-security-policy']
|
||||
assert redis.get('wechat:oa:state:' + state)
|
||||
missing = oauth_launch('a' * 32)
|
||||
assert '过期' in missing.body.decode()
|
||||
assert 'open.weixin.qq.com' not in missing.body.decode()
|
||||
invalid = oauth_launch('javascript:alert(1)')
|
||||
assert '无效' in invalid.body.decode()
|
||||
assert 'open.weixin.qq.com' not in invalid.body.decode()
|
||||
|
||||
|
||||
def test_mobile_callback_only_returns_to_original_authenticated_client(binding):
|
||||
from app.api.wechat_notices import callback, start, StartBinding
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
|
||||
Reference in new issue
Block a user