Skip to content

Commit a58eddf

Browse files
committed
fix: prevent customer uploads for non file based metadata types
1 parent 1819fe7 commit a58eddf

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

app/code/Magento/Customer/Model/FileUploader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public function __construct(
8383
*/
8484
public function validate()
8585
{
86+
if (!in_array($this->attributeMetadata->getFrontendInput(), ['file', 'image'])) {
87+
return [
88+
__('"%1" is not a valid input to accept file uploads.', $this->attributeMetadata->getFrontendInput())
89+
];
90+
}
91+
8692
$formElement = $this->elementFactory->create(
8793
$this->attributeMetadata,
8894
null,

app/code/Magento/Customer/Test/Unit/Model/FileUploaderTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Customer\Model\FileUploader;
1717
use Magento\Customer\Model\Metadata\ElementFactory;
1818
use Magento\Customer\Model\Metadata\Form\Image;
19+
use Magento\Customer\Model\Metadata\Form\Select;
1920
use PHPUnit\Framework\MockObject\MockObject;
2021
use PHPUnit\Framework\TestCase;
2122

@@ -118,10 +119,39 @@ public function testValidate()
118119
->with($this->attributeMetadata, null, CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER)
119120
->willReturn($formElement);
120121

122+
$this->attributeMetadata->expects($this->once())
123+
->method('getFrontendInput')
124+
->willReturn('image');
125+
121126
$model = $this->getModel(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'customer');
122127
$this->assertTrue($model->validate());
123128
}
124129

130+
public function testValidateInvalidAttributeType()
131+
{
132+
$attributeType = 'select';
133+
$attributeCode = 'attribute_code';
134+
$filename = 'filename.ext1';
135+
136+
$_FILES = [
137+
'customer' => [
138+
'name' => [
139+
$attributeCode => $filename,
140+
],
141+
],
142+
];
143+
144+
$this->attributeMetadata->expects($this->exactly(2))
145+
->method('getFrontendInput')
146+
->willReturn($attributeType);
147+
148+
$model = $this->getModel(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'customer');
149+
$expectedErrors = [
150+
__('"%1" is not a valid input to accept file uploads.', $attributeType)
151+
];
152+
$this->assertEquals($expectedErrors, $model->validate());
153+
}
154+
125155
public function testUpload()
126156
{
127157
$attributeCode = 'attribute_code';

0 commit comments

Comments
 (0)