mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-10 09:22:23 +00:00
QFix: Fix default timezone (#8547)
* QFix: Fix default timezone Signed-off-by: Artem Savchenko <armisav@gmail.com> * Clean up Signed-off-by: Artem Savchenko <armisav@gmail.com> * Potential fix for code scanning alert no. 165: Unvalidated dynamic method call Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Artyom Savchenko <armisav@gmail.com> --------- Signed-off-by: Artem Savchenko <armisav@gmail.com> Signed-off-by: Artyom Savchenko <armisav@gmail.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
parent
d2603d8629
commit
a8d6eaca92
@ -221,7 +221,7 @@ class AccountClientImpl implements AccountClient {
|
||||
|
||||
private async _rpc<T>(request: Request): Promise<T> {
|
||||
const timezone = getClientTimezone()
|
||||
const meta: Record<string, string> = timezone !== undefined ? { 'X-Timezone': timezone } : {}
|
||||
const meta: Record<string, string> = timezone !== undefined ? { 'x-timezone': timezone } : {}
|
||||
const response = await fetch(this.url, {
|
||||
...this.request,
|
||||
headers: {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
import account, {
|
||||
type AccountMethods,
|
||||
type Meta,
|
||||
EndpointKind,
|
||||
accountId,
|
||||
getAccountDB,
|
||||
@ -173,6 +174,10 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
|
||||
return extractAuthorizationToken(headers) ?? extractCookieToken(headers)
|
||||
}
|
||||
|
||||
const getRequestMeta = (headers: IncomingHttpHeaders): Meta => {
|
||||
return headers?.['x-timezone'] !== undefined ? { timezone: headers['x-timezone'] as string } : {}
|
||||
}
|
||||
|
||||
function getCookieOptions (ctx: Koa.Context): Cookies.SetOption {
|
||||
const requestUrl = ctx.request.href
|
||||
const url = new URL(requestUrl)
|
||||
@ -314,6 +319,7 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
|
||||
|
||||
router.post('rpc', '/', async (ctx) => {
|
||||
const token = extractToken(ctx.request.headers)
|
||||
const meta = getRequestMeta(ctx.request.headers)
|
||||
|
||||
const request = ctx.request.body as any
|
||||
const method = methods[request.method as AccountMethods]
|
||||
@ -339,7 +345,7 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
|
||||
}
|
||||
const branding = host !== undefined ? brandings[host] : null
|
||||
const result = await measureCtx.with(request.method, {}, (mctx) => {
|
||||
if (method === undefined) {
|
||||
if (method === undefined || typeof method !== 'function') {
|
||||
const response = {
|
||||
id: request.id,
|
||||
error: new Status(Severity.ERROR, platform.status.UnknownMethod, { method: request.method })
|
||||
@ -349,7 +355,7 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
|
||||
return
|
||||
}
|
||||
|
||||
return method(mctx, db, branding, request, token)
|
||||
return method(mctx, db, branding, request, token, meta)
|
||||
})
|
||||
|
||||
const body = JSON.stringify(result)
|
||||
|
@ -554,7 +554,7 @@ describe('account utils', () => {
|
||||
param1: 'value1',
|
||||
param2: 'value2'
|
||||
},
|
||||
{}
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
@ -567,7 +567,7 @@ describe('account utils', () => {
|
||||
const result = await wrappedMethod(mockCtx, mockDb, mockBranding, request, 'token')
|
||||
|
||||
expect(result).toEqual({ id: 'req1', result: mockResult })
|
||||
expect(mockMethod).toHaveBeenCalledWith(mockCtx, mockDb, mockBranding, 'token', { param1: 'value1' }, {})
|
||||
expect(mockMethod).toHaveBeenCalledWith(mockCtx, mockDb, mockBranding, 'token', { param1: 'value1' }, undefined)
|
||||
})
|
||||
|
||||
test('should handle PlatformError', async () => {
|
||||
@ -623,9 +623,9 @@ describe('account utils', () => {
|
||||
const mockMethod = jest.fn().mockResolvedValue(mockResult)
|
||||
const wrappedMethod = wrap(mockMethod)
|
||||
const mockTimezone = 'America/New_York'
|
||||
const request = { id: 'req1', params: { param1: 'value1' }, headers: { 'X-Timezone': mockTimezone } }
|
||||
const request = { id: 'req1', params: { param1: 'value1' } }
|
||||
|
||||
const result = await wrappedMethod(mockCtx, mockDb, mockBranding, request, 'token')
|
||||
const result = await wrappedMethod(mockCtx, mockDb, mockBranding, request, 'token', { timezone: mockTimezone })
|
||||
|
||||
expect(result).toEqual({ id: 'req1', result: mockResult })
|
||||
expect(mockMethod).toHaveBeenCalledWith(
|
||||
|
@ -119,12 +119,9 @@ export function wrap (
|
||||
db: AccountDB,
|
||||
branding: Branding | null,
|
||||
request: any,
|
||||
token?: string
|
||||
token?: string,
|
||||
meta?: Meta
|
||||
): Promise<any> {
|
||||
const meta =
|
||||
request.headers !== undefined && request.headers['X-Timezone'] !== undefined
|
||||
? { timezone: request.headers['X-Timezone'] }
|
||||
: {}
|
||||
return await accountMethod(ctx, db, branding, token, { ...request.params }, meta)
|
||||
.then((result) => ({ id: request.id, result }))
|
||||
.catch((err) => {
|
||||
|
Loading…
Reference in New Issue
Block a user