Skip to content

Commit 0bbb082

Browse files
committed
fix: Update validation
1 parent 53f686a commit 0bbb082

File tree

4 files changed

+42
-35
lines changed

4 files changed

+42
-35
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
### Fixes
33
- Underlying uploader fixes issues with tokens not being sent properly for users seeing
44
`Error!: Error: Error uploading to https://codecov.io: Error: Error uploading to Codecov: Error: Not Found`
5+
- #440 fix: Validation ordering
56

67
## 2.0.1
78
### Fixes

dist/index.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -13061,22 +13061,23 @@ const verify = (filename) => __awaiter(void 0, void 0, void 0, function* () {
1306113061
else {
1306213062
setFailure('Codecov: Error validating SHASUM signature', true);
1306313063
}
13064-
// Verify uploader
13065-
const uploaderSha = external_crypto_.createHash(`sha256`);
13066-
const stream = external_fs_.createReadStream(filename);
13067-
return yield stream
13068-
.on('data', (data) => {
13069-
uploaderSha.update(data);
13070-
}).on('end', () => __awaiter(void 0, void 0, void 0, function* () {
13071-
const hash = `${uploaderSha.digest('hex')} ${uploaderName}`;
13072-
if (hash !== shasum) {
13073-
setFailure('Codecov: Uploader shasum does not match\n' +
13074-
`uploader hash: ${hash}\npublic hash: ${shasum}`, true);
13075-
}
13076-
else {
13077-
core.info('==> Uploader SHASUM verified');
13078-
}
13079-
}));
13064+
const calculateHash = (filename) => __awaiter(void 0, void 0, void 0, function* () {
13065+
const stream = external_fs_.createReadStream(filename);
13066+
const uploaderSha = external_crypto_.createHash(`sha256`);
13067+
stream.pipe(uploaderSha);
13068+
return new Promise((resolve, reject) => {
13069+
stream.on('end', () => resolve(`${uploaderSha.digest('hex')} ${uploaderName}`));
13070+
stream.on('error', reject);
13071+
});
13072+
});
13073+
const hash = yield calculateHash(filename);
13074+
if (hash === shasum) {
13075+
core.info(`==> Uploader SHASUM verified (${hash})`);
13076+
}
13077+
else {
13078+
setFailure('Codecov: Uploader shasum does not match -- ' +
13079+
`uploader hash: ${hash}, public hash: ${shasum}`, true);
13080+
}
1308013081
}
1308113082
catch (err) {
1308213083
setFailure(`Codecov: Error validating uploader: ${err.message}`, true);

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/validate.ts

+23-18
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,29 @@ const verify = async (filename: string) => {
4444
setFailure('Codecov: Error validating SHASUM signature', true);
4545
}
4646

47-
// Verify uploader
48-
const uploaderSha = crypto.createHash(`sha256`);
49-
const stream = fs.createReadStream(filename);
50-
return await stream
51-
.on('data', (data) => {
52-
uploaderSha.update(data);
53-
}).on('end', async () => {
54-
const hash = `${uploaderSha.digest('hex')} ${uploaderName}`;
55-
if (hash !== shasum) {
56-
setFailure(
57-
'Codecov: Uploader shasum does not match\n' +
58-
`uploader hash: ${hash}\npublic hash: ${shasum}`,
59-
true,
60-
);
61-
} else {
62-
core.info('==> Uploader SHASUM verified');
63-
}
64-
});
47+
const calculateHash = async (filename: string) => {
48+
const stream = fs.createReadStream(filename);
49+
const uploaderSha = crypto.createHash(`sha256`);
50+
stream.pipe(uploaderSha);
51+
52+
return new Promise((resolve, reject) => {
53+
stream.on('end', () => resolve(
54+
`${uploaderSha.digest('hex')} ${uploaderName}`,
55+
));
56+
stream.on('error', reject);
57+
});
58+
};
59+
60+
const hash = await calculateHash(filename);
61+
if (hash === shasum) {
62+
core.info(`==> Uploader SHASUM verified (${hash})`);
63+
} else {
64+
setFailure(
65+
'Codecov: Uploader shasum does not match -- ' +
66+
`uploader hash: ${hash}, public hash: ${shasum}`,
67+
true,
68+
);
69+
}
6570
} catch (err) {
6671
setFailure(`Codecov: Error validating uploader: ${err.message}`, true);
6772
}

0 commit comments

Comments
 (0)