Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Utf8 bug #632

Merged
merged 7 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Requests/StoreVolumeMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function rules()
{
return [
'metadata_csv' => [
'required_without_all:metadata_text,ifdo_file',
'bail:required_without_all:metadata_text,ifdo_file',
mzur marked this conversation as resolved.
Show resolved Hide resolved
'file',
'mimetypes:text/plain,text/csv,application/csv',
new Utf8,
],
'metadata_text' => 'required_without_all:metadata_csv,ifdo_file',
'metadata_text' => 'bail:required_without_all:metadata_csv,ifdo_file',
mzur marked this conversation as resolved.
Show resolved Hide resolved
'ifdo_file' => 'required_without_all:metadata_csv,metadata_text|file',
'metadata' => 'filled',
];
Expand Down
72 changes: 35 additions & 37 deletions tests/php/Http/Controllers/Api/Volumes/MetadataControllerTest.php
mzur marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testStoreImageMetadata()

$this->doTestApiRoute('POST', "/api/v1/volumes/{$id}/metadata");

$csv = new UploadedFile(__DIR__."/../../../../../files/image-metadata.csv", 'image-metadata.csv', 'text/csv', null, true);
$csv = new UploadedFile(__DIR__.'/../../../../../files/image-metadata.csv', 'image-metadata.csv', 'text/csv', null, true);
$this->beEditor();
// no permissions
$this->postJson("/api/v1/volumes/{$id}/metadata", ['metadata_csv' => $csv])
Expand Down Expand Up @@ -82,11 +82,9 @@ public function testStoreStringMetadata()

$this->beAdmin();

$this->postJson("/api/v1/volumes/{$id}/metadata", ['metadata_csv' => "metadata_string"])
->assertStatus(422);
$this->postJson("/api/v1/volumes/{$id}/metadata", ['metadata_csv' => 'metadata_string'])
->assertStatus(422);

$this->postJson("/api/v1/volumes/{$id}/metadata", ['metadata_text' => "metadata_string"])
->assertStatus(422);
}

public function testStoreDeprecatedFileAttribute()
Expand All @@ -102,7 +100,7 @@ public function testStoreDeprecatedFileAttribute()
]],
]);

$csv = new UploadedFile(__DIR__."/../../../../../files/image-metadata.csv", 'metadata.csv', 'text/csv', null, true);
$csv = new UploadedFile(__DIR__.'/../../../../../files/image-metadata.csv', 'metadata.csv', 'text/csv', null, true);

$this->beAdmin();
$this->postJson("/api/v1/volumes/{$id}/metadata", ['file' => $csv])
Expand Down Expand Up @@ -153,7 +151,7 @@ public function testStoreVideoMetadataCsv()
]],
]);

$csv = new UploadedFile(__DIR__."/../../../../../files/video-metadata.csv", 'metadata.csv', 'text/csv', null, true);
$csv = new UploadedFile(__DIR__.'/../../../../../files/video-metadata.csv', 'metadata.csv', 'text/csv', null, true);

$this->beAdmin();
$this->postJson("/api/v1/volumes/{$id}/metadata", ['file' => $csv])
Expand Down Expand Up @@ -181,10 +179,10 @@ public function testStoreVideoMetadataText()
]);

$text = <<<TEXT
filename,taken_at,area,distance_to_ground
abc.mp4,2022-02-24 16:07:00,2.5,10
abc.mp4,2022-02-24 16:08:00,3.5,150
TEXT;
filename,taken_at,area,distance_to_ground
abc.mp4,2022-02-24 16:07:00,2.5,10
abc.mp4,2022-02-24 16:08:00,3.5,150
TEXT;

$this->beAdmin();
$this->postJson("/api/v1/volumes/{$id}/metadata", [
Expand Down Expand Up @@ -215,10 +213,10 @@ public function testStoreVideoMetadataMerge()
]);

$text = <<<TEXT
filename,taken_at,area,distance_to_ground
abc.mp4,2022-02-24 16:07:00,2.5,
abc.mp4,2022-02-24 16:09:00,3.5,150
TEXT;
filename,taken_at,area,distance_to_ground
abc.mp4,2022-02-24 16:07:00,2.5,
abc.mp4,2022-02-24 16:09:00,3.5,150
TEXT;

$this->beAdmin();
$this->postJson("/api/v1/volumes/{$id}/metadata", [
Expand Down Expand Up @@ -255,12 +253,12 @@ public function testStoreVideoMetadataFillOneVideoButNotTheOther()
]);

$text = <<<TEXT
filename,taken_at,area,distance_to_ground
abc.mp4,2022-02-24 16:07:00,2.5,10
abc.mp4,2022-02-24 16:09:00,3.5,150
def.mp4,2022-02-24 16:07:00,2.5,
def.mp4,2022-02-24 16:09:00,3.5,
TEXT;
filename,taken_at,area,distance_to_ground
abc.mp4,2022-02-24 16:07:00,2.5,10
abc.mp4,2022-02-24 16:09:00,3.5,150
def.mp4,2022-02-24 16:07:00,2.5,
def.mp4,2022-02-24 16:09:00,3.5,
TEXT;

$this->beAdmin();
$this->postJson("/api/v1/volumes/{$id}/metadata", [
Expand Down Expand Up @@ -313,10 +311,10 @@ public function testStoreVideoMetadataCannotUpdateBasicWithTimestamped()
]);

$text = <<<TEXT
filename,taken_at,area,distance_to_ground
abc.mp4,2022-02-24 16:07:00,2.5,10
abc.mp4,2022-02-24 16:09:00,3.5,150
TEXT;
filename,taken_at,area,distance_to_ground
abc.mp4,2022-02-24 16:07:00,2.5,10
abc.mp4,2022-02-24 16:09:00,3.5,150
TEXT;

$this->beAdmin();
// The video has basic metadata. There is no way the new area data with
Expand All @@ -338,9 +336,9 @@ public function testStoreVideoMetadataZerosSingle()
]);

$text = <<<TEXT
filename,taken_at,area
abc.mp4,2022-02-24 16:07:00,0
TEXT;
filename,taken_at,area
abc.mp4,2022-02-24 16:07:00,0
TEXT;

$this->beAdmin();
$this->postJson("/api/v1/volumes/{$id}/metadata", [
Expand All @@ -363,10 +361,10 @@ public function testStoreVideoMetadataZeros()
]);

$text = <<<TEXT
filename,taken_at,area
abc.mp4,2022-02-24 16:07:00,0
abc.mp4,2022-02-24 16:08:00,1
TEXT;
filename,taken_at,area
abc.mp4,2022-02-24 16:07:00,0
abc.mp4,2022-02-24 16:08:00,1
TEXT;

$this->beAdmin();
$this->postJson("/api/v1/volumes/{$id}/metadata", [
Expand All @@ -388,7 +386,7 @@ public function testStoreVideoMetadataIncorrectEncoding()
'volume_id' => $id,
]);

$csv = new UploadedFile(__DIR__."/../../../../../files/video-metadata-incorrect-encoding.csv", 'metadata.csv', 'text/csv', null, true);
$csv = new UploadedFile(__DIR__.'/../../../../../files/video-metadata-incorrect-encoding.csv', 'metadata.csv', 'text/csv', null, true);

$this->beAdmin();
$this->postJson("/api/v1/volumes/{$id}/metadata", ['file' => $csv])
Expand All @@ -399,7 +397,7 @@ public function testStoreImageIfdoFile()
{
$id = $this->volume()->id;
$this->beAdmin();
$file = new UploadedFile(__DIR__."/../../../../../files/image-ifdo.yaml", 'ifdo.yaml', 'application/yaml', null, true);
$file = new UploadedFile(__DIR__.'/../../../../../files/image-ifdo.yaml', 'ifdo.yaml', 'application/yaml', null, true);

Storage::fake('ifdos');

Expand All @@ -417,7 +415,7 @@ public function testStoreVideoIfdoFile()
$this->volume()->media_type_id = MediaType::videoId();
$this->volume()->save();
$this->beAdmin();
$file = new UploadedFile(__DIR__."/../../../../../files/video-ifdo.yaml", 'ifdo.yaml', 'application/yaml', null, true);
$file = new UploadedFile(__DIR__.'/../../../../../files/video-ifdo.yaml', 'ifdo.yaml', 'application/yaml', null, true);

Storage::fake('ifdos');

Expand All @@ -433,7 +431,7 @@ public function testStoreVideoIfdoFileForImageVolume()
{
$id = $this->volume()->id;
$this->beAdmin();
$file = new UploadedFile(__DIR__."/../../../../../files/video-ifdo.yaml", 'ifdo.yaml', 'application/yaml', null, true);
$file = new UploadedFile(__DIR__.'/../../../../../files/video-ifdo.yaml', 'ifdo.yaml', 'application/yaml', null, true);

$this->postJson("/api/v1/volumes/{$id}/metadata", ['ifdo_file' => $file])
->assertStatus(422);
Expand All @@ -445,7 +443,7 @@ public function testStoreImageIfdoFileForVideoVolume()
$this->volume()->media_type_id = MediaType::videoId();
$this->volume()->save();
$this->beAdmin();
$file = new UploadedFile(__DIR__."/../../../../../files/image-ifdo.yaml", 'ifdo.yaml', 'application/yaml', null, true);
$file = new UploadedFile(__DIR__.'/../../../../../files/image-ifdo.yaml', 'ifdo.yaml', 'application/yaml', null, true);

$this->postJson("/api/v1/volumes/{$id}/metadata", ['ifdo_file' => $file])
->assertStatus(422);
Expand Down