fix(auth): route session lifecycle through Square
This commit is contained in:
@@ -734,9 +734,10 @@ describe('auth host api routes', () => {
|
||||
);
|
||||
|
||||
expect(refreshResponse.statusCode).toBe(200);
|
||||
const [, refreshInit] = fetchMock.mock.calls[0] as [string, RequestInit];
|
||||
expect(String(refreshInit.body)).toBe(
|
||||
'grant_type=refresh_token&refresh_token=main-refresh-r1',
|
||||
const [refreshUrl, refreshInit] = fetchMock.mock.calls[0] as [string, RequestInit];
|
||||
expect(refreshUrl).toBe('https://square.nianxx.cn/api/auth/refresh');
|
||||
expect(refreshInit.body).toBe(
|
||||
JSON.stringify({ refresh_token: 'main-refresh-r1' }),
|
||||
);
|
||||
expect(String(refreshInit.body)).not.toContain('renderer-refresh-r0');
|
||||
});
|
||||
@@ -904,8 +905,9 @@ describe('auth host api routes', () => {
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'https://biz.nianxx.cn/auth/token/logout',
|
||||
'https://square.nianxx.cn/api/auth/logout',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
headers: { Authorization: 'Bearer main-current-access-token' },
|
||||
}),
|
||||
);
|
||||
@@ -1034,8 +1036,8 @@ describe('auth host api routes', () => {
|
||||
);
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'https://biz.nianxx.cn/auth/token/logout',
|
||||
expect.objectContaining({ method: 'DELETE' }),
|
||||
'https://square.nianxx.cn/api/auth/logout',
|
||||
expect.objectContaining({ method: 'POST' }),
|
||||
);
|
||||
expect(response.statusCode).toBe(500);
|
||||
});
|
||||
|
||||
@@ -71,18 +71,13 @@ describe('works-square-session service', () => {
|
||||
await expect(getValidWorksSquareAccessToken({ fetchImpl })).resolves.toBe('new-access-token');
|
||||
|
||||
expect(fetchImpl).toHaveBeenCalledWith(
|
||||
'https://biz.nianxx.cn/auth/oauth2/token',
|
||||
'https://square.nianxx.cn/api/auth/refresh',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
headers: expect.objectContaining({
|
||||
Authorization: `Basic ${Buffer.from('app:app').toString('base64')}`,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
}),
|
||||
body: expect.any(URLSearchParams),
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ refresh_token: 'old-refresh-token' }),
|
||||
}),
|
||||
);
|
||||
const body = fetchImpl.mock.calls[0][1].body as URLSearchParams;
|
||||
expect(String(body)).toBe('grant_type=refresh_token&refresh_token=old-refresh-token');
|
||||
expect(getWorksSquareSessionSnapshot()).toMatchObject({
|
||||
accessToken: 'new-access-token',
|
||||
tokenType: 'Bearer',
|
||||
@@ -453,8 +448,9 @@ describe('works-square-session service', () => {
|
||||
);
|
||||
await getValidWorksSquareAccessToken({ fetchImpl: secondFetch, forceRefresh: true });
|
||||
|
||||
const body = secondFetch.mock.calls[0][1].body as URLSearchParams;
|
||||
expect(String(body)).toContain('refresh_token=rotated-refresh-token');
|
||||
expect(secondFetch.mock.calls[0][1].body).toBe(JSON.stringify({
|
||||
refresh_token: 'rotated-refresh-token',
|
||||
}));
|
||||
});
|
||||
|
||||
it('uses user_id ahead of username for a stable opaque account partition', () => {
|
||||
|
||||
Reference in New Issue
Block a user