|
@@ -37,6 +37,7 @@ describe('S3PersistorManagerTests', function() {
|
|
|
S3Client,
|
|
S3Client,
|
|
|
S3ReadStream,
|
|
S3ReadStream,
|
|
|
S3NotFoundError,
|
|
S3NotFoundError,
|
|
|
|
|
+ S3AccessDeniedError,
|
|
|
FileNotFoundError,
|
|
FileNotFoundError,
|
|
|
EmptyPromise,
|
|
EmptyPromise,
|
|
|
settings
|
|
settings
|
|
@@ -84,6 +85,9 @@ describe('S3PersistorManagerTests', function() {
|
|
|
S3NotFoundError = new Error('not found')
|
|
S3NotFoundError = new Error('not found')
|
|
|
S3NotFoundError.code = 'NoSuchKey'
|
|
S3NotFoundError.code = 'NoSuchKey'
|
|
|
|
|
|
|
|
|
|
+ S3AccessDeniedError = new Error('access denied')
|
|
|
|
|
+ S3AccessDeniedError.code = 'AccessDenied'
|
|
|
|
|
+
|
|
|
S3ReadStream = {
|
|
S3ReadStream = {
|
|
|
on: sinon.stub(),
|
|
on: sinon.stub(),
|
|
|
pipe: sinon.stub().returns('s3Stream'),
|
|
pipe: sinon.stub().returns('s3Stream'),
|
|
@@ -291,6 +295,36 @@ describe('S3PersistorManagerTests', function() {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ describe('when access to the file is denied', function() {
|
|
|
|
|
+ let error, stream
|
|
|
|
|
+
|
|
|
|
|
+ beforeEach(async function() {
|
|
|
|
|
+ S3ReadStream.on = sinon.stub()
|
|
|
|
|
+ S3ReadStream.on.withArgs('error').yields(S3AccessDeniedError)
|
|
|
|
|
+ try {
|
|
|
|
|
+ stream = await S3PersistorManager.promises.getFileStream(bucket, key)
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ error = err
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('does not return a stream', function() {
|
|
|
|
|
+ expect(stream).not.to.exist
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('throws a NotFoundError', function() {
|
|
|
|
|
+ expect(error).to.be.an.instanceOf(Errors.NotFoundError)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('wraps the error from S3', function() {
|
|
|
|
|
+ expect(error.cause).to.equal(S3AccessDeniedError)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('stores the bucket and key in the error', function() {
|
|
|
|
|
+ expect(error.info).to.deep.equal({ Bucket: bucket, Key: key })
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
describe('when S3 encounters an unkown error', function() {
|
|
describe('when S3 encounters an unkown error', function() {
|
|
|
let error, stream
|
|
let error, stream
|
|
|
|
|
|