mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 01:56:27 +08:00
fix(server): disable Apple oauth on client version < 0.22.0 (#12984)
close AF-2705 #### PR Dependency Tree * **PR #12984** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * The Apple OAuth provider is now available only for clients version 0.22.0 or higher. * Client version detection has been improved by extracting version information from request headers. * **Bug Fixes** * Ensured that the Apple OAuth provider is hidden for clients below version 0.22.0. * **Tests** * Added comprehensive end-to-end and utility tests for OAuth provider selection and client version extraction. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import test from 'ava';
|
||||
import { Request } from 'express';
|
||||
|
||||
import { getClientVersionFromRequest } from '../request';
|
||||
|
||||
test('should get client version from x-affine-version header', t => {
|
||||
const req = {
|
||||
headers: {
|
||||
'x-affine-version': '0.22.2',
|
||||
},
|
||||
} as unknown as Request;
|
||||
|
||||
t.is(getClientVersionFromRequest(req), '0.22.2');
|
||||
|
||||
const req2 = {
|
||||
headers: {
|
||||
'x-affine-version': ['0.22.2', '0.23.0-beta.2'],
|
||||
},
|
||||
} as unknown as Request;
|
||||
|
||||
t.is(getClientVersionFromRequest(req2), '0.22.2');
|
||||
});
|
||||
|
||||
test('should not get client version from x-affine-version header', t => {
|
||||
const req = {
|
||||
headers: {
|
||||
'user-agent':
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.6998.205 Safari/537.36',
|
||||
},
|
||||
} as unknown as Request;
|
||||
|
||||
t.is(getClientVersionFromRequest(req), undefined);
|
||||
});
|
||||
@@ -118,3 +118,11 @@ export function getRequestIdFromHost(host: ArgumentsHost) {
|
||||
const req = getRequestFromHost(host);
|
||||
return getRequestIdFromRequest(req, type);
|
||||
}
|
||||
|
||||
export function getClientVersionFromRequest(req: Request) {
|
||||
let version = req.headers['x-affine-version'];
|
||||
if (Array.isArray(version)) {
|
||||
version = version[0];
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user