TASK22224: harden getrepsblob against stale tag entries
This commit is contained in:
@@ -253,6 +253,60 @@ test("deleteblobrep handler dependency failure returns DELETE_BLOB_REP_FAILED",
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "DELETE_BLOB_REP_FAILED");
|
||||
});
|
||||
|
||||
test("getrepsblob handler success returns representations payload", async () => {
|
||||
const mod = loadModule("pages/api/file/getrepsblob.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
middleware: () => {},
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
consoleLogger: () => {},
|
||||
getRepsBlobs: async () => [
|
||||
{ path: "c/ref_rep.json", name: "ref_rep.json" }
|
||||
],
|
||||
downloadAllRepsFiles: async () => ({
|
||||
"@odata.count": 1,
|
||||
value: [{ id: "r1" }]
|
||||
})
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: { container: "c1", hash: "expected" }
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default.handler(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 200);
|
||||
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
|
||||
"@odata.count": 1,
|
||||
value: [{ id: "r1" }]
|
||||
});
|
||||
});
|
||||
|
||||
test("getrepsblob handler dependency failure returns GET_REPS_BLOB_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/file/getrepsblob.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
middleware: () => {},
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
consoleLogger: () => {},
|
||||
getRepsBlobs: async () => {
|
||||
throw new Error("storage failure");
|
||||
},
|
||||
downloadAllRepsFiles: async () => ({})
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: { container: "c1", hash: "expected" }
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default.handler(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "GET_REPS_BLOB_FAILED");
|
||||
});
|
||||
|
||||
test("getbloblist handler returns INVALID_HASH for mismatch", async () => {
|
||||
const mod = loadModule("pages/api/file/getbloblist.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
|
||||
Reference in New Issue
Block a user