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

Clone of python-admin-sdk-support #5303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,39 @@ describe("GCS endpoint conformance tests", () => {
});
});
});

describe("Delete protocols", () => {
describe("delete objects", () => {
it("should delete objects in the provided bucket", async () => {
const pathPatterns = [
`/b/${storageBucket}/o/${TEST_FILE_NAME}`,
`/storage/v1/b/${storageBucket}/o/${TEST_FILE_NAME}`,
];

for (const deletePathPattern of pathPatterns) {
await supertest(storageHost)
.post(`/upload/storage/v1/b/${storageBucket}/o?name=${TEST_FILE_NAME}`)
.set(authHeader)
.send(Buffer.from("hello world"))
.expect(200);

let data = await supertest(storageHost)
.get(`/storage/v1/b/${storageBucket}/o`)
.set(authHeader)
.expect(200)
.then((res) => res.body);
expect(data.items.length).to.equal(1);

await supertest(storageHost).delete(deletePathPattern).set(authHeader).expect(204);

data = await supertest(storageHost)
.get(`/storage/v1/b/${storageBucket}/o`)
.set(authHeader)
.expect(200)
.then((res) => res.body);
expect(data.items.length).to.equal(0);
}
});
});
});
});
33 changes: 18 additions & 15 deletions src/emulator/storage/apis/gcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,26 @@ export function createCloudEndpoints(emulator: StorageEmulator): Router {
});
});

gcloudStorageAPI.delete("/b/:bucketId/o/:objectId", async (req, res) => {
try {
await adminStorageLayer.deleteObject({
bucketId: req.params.bucketId,
decodedObjectId: req.params.objectId,
});
} catch (err) {
if (err instanceof NotFoundError) {
return sendObjectNotFound(req, res);
}
if (err instanceof ForbiddenError) {
return res.sendStatus(403);
gcloudStorageAPI.delete(
["/b/:bucketId/o/:objectId", "/storage/v1/b/:bucketId/o/:objectId"],
async (req, res) => {
try {
await adminStorageLayer.deleteObject({
bucketId: req.params.bucketId,
decodedObjectId: req.params.objectId,
});
} catch (err) {
if (err instanceof NotFoundError) {
return sendObjectNotFound(req, res);
}
if (err instanceof ForbiddenError) {
return res.sendStatus(403);
}
throw err;
}
throw err;
return res.sendStatus(204);
}
return res.sendStatus(204);
});
);

gcloudStorageAPI.put("/upload/storage/v1/b/:bucketId/o", async (req, res) => {
if (!req.query.upload_id) {
Expand Down