FIX: Validate type when picking an avatar. (#11602)

This change improves the "UsersController#pick_avatar" validations to raise an error when "allow_uploaded_avatars" is disabled.
This commit is contained in:
Roman Rizzi
2021-01-05 10:29:10 -03:00
committed by GitHub
parent 45671276bf
commit afebaf439f
3 changed files with 60 additions and 33 deletions

View File

@ -2309,6 +2309,29 @@ describe UsersController do
expect(response.status).to eq(422)
end
it 'ignores the upload if picking a system avatar' do
SiteSetting.allow_uploaded_avatars = false
another_upload = Fabricate(:upload)
put "/u/#{user.username}/preferences/avatar/pick.json", params: {
upload_id: another_upload.id, type: "system"
}
expect(response.status).to eq(200)
expect(user.reload.uploaded_avatar_id).to eq(nil)
end
it 'raises an error if the type is invalid' do
SiteSetting.allow_uploaded_avatars = false
another_upload = Fabricate(:upload)
put "/u/#{user.username}/preferences/avatar/pick.json", params: {
upload_id: another_upload.id, type: "x"
}
expect(response.status).to eq(422)
end
it 'can successfully pick the system avatar' do
put "/u/#{user.username}/preferences/avatar/pick.json"