forked from lunanting/cangku
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
import assert from 'node:assert/strict';
|
||
import test from 'node:test';
|
||
|
||
import {
|
||
getRequestErrorMessage,
|
||
isAuthSessionFailure,
|
||
} from '../src/api/authSessionPolicy.js';
|
||
|
||
test('recognizes explicit application authentication failures', () => {
|
||
assert.equal(isAuthSessionFailure({
|
||
status: 401,
|
||
data: { code: 'AUTH_TOKEN_INVALID', error: '无效的认证令牌' },
|
||
}), true);
|
||
assert.equal(isAuthSessionFailure({
|
||
status: 401,
|
||
data: { error: '未提供认证令牌' },
|
||
}), true);
|
||
});
|
||
|
||
test('does not treat an upstream 401 as an expired application session', () => {
|
||
const response = {
|
||
status: 401,
|
||
data: { error: 'AccessKey已过期,请重新获取' },
|
||
};
|
||
|
||
assert.equal(isAuthSessionFailure(response), false);
|
||
assert.equal(getRequestErrorMessage({ response }), 'AccessKey已过期,请重新获取');
|
||
});
|
||
|
||
test('does not treat gateway failures as authentication failures', () => {
|
||
assert.equal(isAuthSessionFailure({
|
||
status: 502,
|
||
data: { code: 'ALIBABA_1688_IMAGE_SEARCH_FAILED' },
|
||
}), false);
|
||
});
|