Skip to content

Commit

Permalink
fix: revert skip validation (#1718)
Browse files Browse the repository at this point in the history
* fix: revert skip validation

* fixed logic

* 馃 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
shaffeeullah and gcf-owl-bot[bot] committed Nov 19, 2021
1 parent c365254 commit 0c75e33
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 59 deletions.
18 changes: 4 additions & 14 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ class File extends ServiceObject<File> {

const throughStream = streamEvents(new PassThrough());

let isServedCompressed = true;
let isCompressed = true;
let crc32c = true;
let md5 = false;

Expand Down Expand Up @@ -1379,7 +1379,7 @@ class File extends ServiceObject<File> {
rawResponseStream.on('error', onComplete);

const headers = rawResponseStream.toJSON().headers;
isServedCompressed = headers['content-encoding'] === 'gzip';
isCompressed = headers['content-encoding'] === 'gzip';
const throughStreams: Writable[] = [];

if (shouldRunValidation) {
Expand All @@ -1400,7 +1400,7 @@ class File extends ServiceObject<File> {
throughStreams.push(validateStream);
}

if (isServedCompressed && options.decompress) {
if (isCompressed && options.decompress) {
throughStreams.push(zlib.createGunzip());
}

Expand Down Expand Up @@ -1440,23 +1440,13 @@ class File extends ServiceObject<File> {
return;
}

// TODO(https://github.com/googleapis/nodejs-storage/issues/709):
// Remove once the backend issue is fixed.
// If object is stored compressed (having
// metadata.contentEncoding === 'gzip') and was served decompressed,
// then skip checksum validation because the remote checksum is computed
// against the compressed version of the object.
if (!isServedCompressed) {
if (!isCompressed) {
try {
await this.getMetadata({userProject: options.userProject});
} catch (e) {
throughStream.destroy(e);
return;
}
if (this.metadata.contentEncoding === 'gzip') {
throughStream.end();
return;
}
}

// If we're doing validation, assume the worst-- a data integrity
Expand Down
27 changes: 0 additions & 27 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2502,33 +2502,6 @@ describe('storage', () => {
});
});

it('should skip validation if file is served decompressed', async () => {
const filename = 'logo-gzipped.png';
await bucket.upload(FILES.logo.path, {destination: filename, gzip: true});

tmp.setGracefulCleanup();
const {name: tmpFilePath} = tmp.fileSync();

const file = bucket.file(filename);

await new Promise((resolve, reject) => {
file
.createReadStream()
.on('error', reject)
.on('response', raw => {
assert.strictEqual(
raw.toJSON().headers['content-encoding'],
undefined
);
})
.pipe(fs.createWriteStream(tmpFilePath))
.on('error', reject)
.on('finish', resolve);
});

await file.delete();
});

describe('simple write', () => {
it('should save arbitrary data', done => {
const file = bucket.file('TestFile');
Expand Down
18 changes: 0 additions & 18 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1387,24 +1387,6 @@ describe('File', () => {
file.requestStream = getFakeSuccessfulRequest(data);
});

describe('server decompression', () => {
it('should skip validation if file was stored compressed', done => {
file.metadata.contentEncoding = 'gzip';

const validateStub = sinon.stub().returns(true);
fakeValidationStream.test = validateStub;

file
.createReadStream({validation: 'crc32c'})
.on('error', done)
.on('end', () => {
assert(validateStub.notCalled);
done();
})
.resume();
});
});

it('should emit errors from the validation stream', done => {
const error = new Error('Error.');

Expand Down

0 comments on commit 0c75e33

Please sign in to comment.