[GH-8911] Fix file upload request when CSRF protection is enabled (#8912)

* Fix file upload for csrf protection

* Fix use profile upload for csrf protection

* Fix tests

* Fix files.test.ts
This commit is contained in:
Kohei Adachi 2025-10-01 23:00:55 +09:00 committed by GitHub
parent a8ddf0472a
commit 85fcdacee7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 5 additions and 0 deletions

View file

@ -58,6 +58,7 @@ const user1 = {id: 'userid1', username: 'user1', email: 'user1@mattermost.com',
const user2 = {id: 'userid2', username: 'user2', email: 'user2@mattermost.com', roles: ''} as UserProfile;
const mockClient = {
getRequestHeaders: jest.fn(() => ({})),
getMe: jest.fn(() => ({id: 'userid1', username: 'user1', email: 'user1@mattermost.com', roles: ''})),
getStatus: jest.fn((id: string) => ({user_id: id === 'me' ? 'userid1' : id, status: 'online'})),
getProfilesInChannel: jest.fn(() => ([user1, user2])),

View file

@ -774,6 +774,7 @@ export const uploadUserProfileImage = async (serverUrl: string, localPath: strin
multipart: {
fileKey: 'image',
},
headers: client.getRequestHeaders('POST'),
});
}
return {};

View file

@ -87,6 +87,7 @@ test('uploadAttachment', () => {
},
},
timeoutInterval: 180000,
headers: {Accept: 'application/json'},
};
(client.apiClient.upload as jest.Mock).mockReturnValue({
@ -110,6 +111,7 @@ test('uploadAttachment', () => {
},
},
timeoutInterval: 180000,
headers: {Accept: 'application/json'},
};
client.uploadAttachment(file, channelId, onProgress, onComplete, onError);
expect(client.apiClient.upload).toHaveBeenCalledWith(client.getFilesRoute(), file.localPath, expectedDefaultOptions);

View file

@ -81,6 +81,7 @@ const ClientFiles = <TBase extends Constructor<ClientBase>>(superclass: TBase) =
},
},
timeoutInterval: toMilliseconds({minutes: 3}),
headers: this.getRequestHeaders('POST'),
};
if (!file.localPath) {
throw new Error('file does not have local path defined');