Expose authenticated OneShop bridge readiness
Memind CI / Test, build, and release guards (push) Successful in 3m58s
Memind CI / Test, build, and release guards (push) Successful in 3m58s
This commit is contained in:
@@ -801,6 +801,7 @@ attachPortalOneShopRoutes({
|
||||
wechatNotifyBody,
|
||||
userAuthReady,
|
||||
getUserAuth: () => userAuth,
|
||||
getWechatOAuthService: () => wechatOAuthService,
|
||||
userToken,
|
||||
});
|
||||
attachPortalWebhookRoutes({
|
||||
|
||||
@@ -34,6 +34,7 @@ export function attachPortalOneShopRoutes({
|
||||
wechatNotifyBody,
|
||||
userAuthReady,
|
||||
getUserAuth,
|
||||
getWechatOAuthService = () => null,
|
||||
userToken,
|
||||
shopPublicUrl = process.env.ONE_SHOP_PUBLIC_URL,
|
||||
shopInternalUrl = process.env.ONE_SHOP_INTERNAL_URL || shopPublicUrl,
|
||||
@@ -92,6 +93,22 @@ export function attachPortalOneShopRoutes({
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/internal/one-shop/status', async (req, res) => {
|
||||
if (!hasBridgeKey(req, bridgeKey)) return res.sendStatus(403);
|
||||
res.set('Cache-Control', 'no-store');
|
||||
try {
|
||||
await userAuthReady;
|
||||
return res.json({
|
||||
login: Boolean(getUserAuth() && getWechatOAuthService()?.enabled),
|
||||
payment: Boolean(getPayClient()?.enabled),
|
||||
shop_origin: shopOrigin,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.warn('OneShop bridge status unavailable:', error.message);
|
||||
return res.sendStatus(503);
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/internal/one-shop/wechat-pay', jsonBody, async (req, res) => {
|
||||
if (!hasBridgeKey(req, bridgeKey)) return res.sendStatus(403);
|
||||
const { out_trade_no: outTradeNo, amount_cents: amountCents, memind_user_id: userId } = req.body || {};
|
||||
|
||||
@@ -20,6 +20,7 @@ test('OneShop login handoff and signed notification forwarding', async (t) => {
|
||||
getUserAuth: () => ({
|
||||
getMe: async (token) => token === 'fixture-session' ? { id: 'memind-user' } : null,
|
||||
}),
|
||||
getWechatOAuthService: () => ({ enabled: true }),
|
||||
userToken: (req) => req.get('cookie'),
|
||||
shopPublicUrl: 'https://shop.example.test',
|
||||
shopInternalUrl: 'http://shop-internal.example.test',
|
||||
@@ -50,6 +51,14 @@ test('OneShop login handoff and signed notification forwarding', async (t) => {
|
||||
t.after(() => new Promise((resolve) => server.close(resolve)));
|
||||
await once(server, 'listening');
|
||||
const base = `http://127.0.0.1:${server.address().port}`;
|
||||
assert.equal((await fetch(base + '/internal/one-shop/status')).status, 403);
|
||||
const status = await fetch(base + '/internal/one-shop/status', {
|
||||
headers: { 'X-One-Shop-Bridge-Key': bridgeKey },
|
||||
});
|
||||
assert.deepEqual(await status.json(), {
|
||||
login: true, payment: true, shop_origin: 'https://shop.example.test',
|
||||
});
|
||||
|
||||
const continuePath = `/auth/one-shop/continue?state=${state}`;
|
||||
const anonymous = await fetch(base + continuePath, {
|
||||
redirect: 'manual', headers: { 'User-Agent': 'MicroMessenger' },
|
||||
|
||||
Reference in New Issue
Block a user