Skip to content

Commit

Permalink
Fix Storage Emulator crash on iOS 403
Browse files Browse the repository at this point in the history
  • Loading branch information
tohhsinpei committed Feb 22, 2022
1 parent 0d943fb commit 32c7764
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
30 changes: 30 additions & 0 deletions scripts/storage-emulator-integration/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,36 @@ describe("Storage emulator", () => {
})
.expect(200);
});

it("#uploadResumableHandlesAuthError", async () => {
const uploadURL = await supertest(STORAGE_EMULATOR_HOST)
.post(
`/v0/b/${storageBucket}/o/test_upload.jpg?uploadType=resumable&name=test_upload.jpg`
)
.set({
// Authorization missing
"X-Goog-Upload-Protocol": "resumable",
"X-Goog-Upload-Command": "start",
})
.expect(200)
.then((res) => new URL(res.header["x-goog-upload-url"]));

await supertest(STORAGE_EMULATOR_HOST)
.put(uploadURL.pathname + uploadURL.search)
.set({
"X-Goog-Upload-Protocol": "resumable",
"X-Goog-Upload-Command": "upload, finalize",
})
.expect(403);

await supertest(STORAGE_EMULATOR_HOST)
.put(uploadURL.pathname + uploadURL.search)
.set({
"X-Goog-Upload-Protocol": "resumable",
"X-Goog-Upload-Command": "cancel",
})
.expect(200);
});
});

after(async function (this) {
Expand Down
6 changes: 5 additions & 1 deletion src/emulator/storage/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ export class StorageLayer {
if (!upload) {
return undefined;
}

if (upload.status !== UploadStatus.FINISHED) {
this._persistence.deleteFile(upload.fileLocation);
}
upload.status = UploadStatus.CANCELLED;
this._persistence.deleteFile(upload.fileLocation);
return upload;
}

public uploadBytes(uploadId: string, bytes: Buffer): ResumableUpload | undefined {
Expand Down

0 comments on commit 32c7764

Please sign in to comment.