mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
* Upgrade `aws-sdk` to v3 Also vendored nodemailer-ses-transport * Moved default region to CE settings * Ensure timeout is added to `requestHandler` and `region` is populated * fix unsigned header in signed URL request The x-amz-acl header is not needed when using the signed request, as ACL are already defined when creating the signed URL in PutObjectCommand constructor. * Add default AWS region for latexqc service * remove unnecessary region in compose files * Use AWS_REGION=us-west-2 for history-v1 * prevent retries uploading streams with PutObjectCommand * Remove AWS SDK JS message suppression GitOrigin-RevId: 6fda6f02160023ffed76143397bbd965f86a9509
113 lines
3.1 KiB
JavaScript
113 lines
3.1 KiB
JavaScript
/* eslint-disable new-cap */
|
|
const sinon = require('sinon')
|
|
const chai = require('chai')
|
|
|
|
const { expect, assert } = chai
|
|
|
|
module.exports = function () {
|
|
const s3ClientStub = {
|
|
send: sinon.stub(),
|
|
middlewareStack: new Set(),
|
|
}
|
|
|
|
const assertSendCalledWith = (s3Command, payload) => {
|
|
for (let i = 0; i < s3ClientStub.send.callCount; i++) {
|
|
const call = s3ClientStub.send.getCall(i)
|
|
const callArg = call.args[0]
|
|
if (callArg?.name === new s3Command().name) {
|
|
if (payload) {
|
|
expect(callArg.payload).to.deep.equal(payload)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
assert.fail(
|
|
`Expected S3Client to be called with '${new s3Command().name}' command but it was not called`
|
|
)
|
|
}
|
|
|
|
const assertSendCallCount = (s3Command, expectedCount) => {
|
|
const callCount = s3ClientStub.send.callCount
|
|
let counter = 0
|
|
for (let i = 0; i < callCount; i++) {
|
|
const call = s3ClientStub.send.getCall(i)
|
|
const callArg = call.args[0]
|
|
if (callArg?.name === new s3Command().name) {
|
|
counter++
|
|
}
|
|
}
|
|
expect(counter).to.equal(expectedCount)
|
|
}
|
|
|
|
const assertSendNotCalledWith = s3Command => {
|
|
for (let i = 0; i < s3ClientStub.send.callCount; i++) {
|
|
const call = s3ClientStub.send.getCall(i)
|
|
const callArg = call.args[0]
|
|
if (callArg?.name === new s3Command().name) {
|
|
assert.fail(
|
|
`Expected S3Client not to be called with '${new s3Command().name}' command but it was called`
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
const mockSend = (s3Command, response, options = {}) => {
|
|
const mock = s3ClientStub.send.withArgs(sinon.match.instanceOf(s3Command))
|
|
const fn = options.rejects ? 'rejects' : 'resolves'
|
|
|
|
if (options.nextResponses?.length) {
|
|
mock.onCall(0)[fn](response)
|
|
for (let i = 0; i < options.nextResponses.length; i++) {
|
|
mock.onCall(i + 1)[fn](options.nextResponses[i])
|
|
}
|
|
} else {
|
|
mock[fn](response)
|
|
}
|
|
}
|
|
|
|
return {
|
|
s3ClientStub,
|
|
assertSendCalledWith,
|
|
assertSendCallCount,
|
|
assertSendNotCalledWith,
|
|
mockSend,
|
|
S3Client: sinon.stub().returns(s3ClientStub),
|
|
CopyObjectCommand: class DeleteObjectCommand {
|
|
constructor(payload) {
|
|
this.name = 'CopyObjectCommand'
|
|
this.payload = payload
|
|
}
|
|
},
|
|
DeleteObjectCommand: class DeleteObjectCommand {
|
|
constructor(payload) {
|
|
this.name = 'DeleteObjectCommand'
|
|
this.payload = payload
|
|
}
|
|
},
|
|
DeleteObjectsCommand: class DeleteObjectCommand {
|
|
constructor(payload) {
|
|
this.name = 'DeleteObjectsCommand'
|
|
this.payload = payload
|
|
}
|
|
},
|
|
GetObjectCommand: class DeleteObjectCommand {
|
|
constructor(payload) {
|
|
this.name = 'GetObjectCommand'
|
|
this.payload = payload
|
|
}
|
|
},
|
|
HeadObjectCommand: class DeleteObjectCommand {
|
|
constructor(payload) {
|
|
this.name = 'HeadObjectCommand'
|
|
this.payload = payload
|
|
}
|
|
},
|
|
ListObjectsV2Command: class DeleteObjectCommand {
|
|
constructor(payload) {
|
|
this.name = 'ListObjectsV2Command'
|
|
this.payload = payload
|
|
}
|
|
},
|
|
}
|
|
}
|