|
| 1 | +const assert = require('assert'); |
| 2 | +const { makeS3Request } = require('../utils/makeRequest'); |
| 3 | +const HttpRequestAuthV4 = require('../utils/HttpRequestAuthV4'); |
| 4 | + |
| 5 | +const bucket = 'testunsupportedchecksumsbucket'; |
| 6 | +const objectKey = 'key'; |
| 7 | +const objData = Buffer.alloc(1024, 'a'); |
| 8 | + |
| 9 | +const authCredentials = { |
| 10 | + accessKey: 'accessKey1', |
| 11 | + secretKey: 'verySecretKey1', |
| 12 | +}; |
| 13 | + |
| 14 | +const itSkipIfAWS = process.env.AWS_ON_AIR ? it.skip : it; |
| 15 | + |
| 16 | +describe('unsupported checksum requests:', () => { |
| 17 | + before(done => { |
| 18 | + makeS3Request({ |
| 19 | + method: 'PUT', |
| 20 | + authCredentials, |
| 21 | + bucket, |
| 22 | + }, err => { |
| 23 | + assert.ifError(err); |
| 24 | + done(); |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + after(done => { |
| 29 | + makeS3Request({ |
| 30 | + method: 'DELETE', |
| 31 | + authCredentials, |
| 32 | + bucket, |
| 33 | + }, err => { |
| 34 | + assert.ifError(err); |
| 35 | + done(); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + itSkipIfAWS('should respond with BadRequest for trailing checksum', done => { |
| 40 | + const req = new HttpRequestAuthV4( |
| 41 | + `http://localhost:8000/${bucket}/${objectKey}`, |
| 42 | + Object.assign( |
| 43 | + { |
| 44 | + method: 'PUT', |
| 45 | + headers: { |
| 46 | + 'content-length': objData.length, |
| 47 | + 'x-amz-content-sha256': 'STREAMING-AWS4-HMAC-SHA256-PAYLOAD-TRAILER', |
| 48 | + 'x-amz-trailer': 'x-amz-checksum-sha256', |
| 49 | + }, |
| 50 | + }, |
| 51 | + authCredentials |
| 52 | + ), |
| 53 | + res => { |
| 54 | + assert.strictEqual(res.statusCode, 400); |
| 55 | + res.on('data', () => {}); |
| 56 | + res.on('end', done); |
| 57 | + } |
| 58 | + ); |
| 59 | + |
| 60 | + req.on('error', err => { |
| 61 | + assert.ifError(err); |
| 62 | + }); |
| 63 | + |
| 64 | + req.write(objData); |
| 65 | + |
| 66 | + req.once('drain', () => { |
| 67 | + req.end(); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments