Skip to content

Commit 59a87fc

Browse files
committed
only show integrity check for things that have specified an sha
1 parent 7861896 commit 59a87fc

File tree

7 files changed

+16
-20
lines changed

7 files changed

+16
-20
lines changed

src/observers/CsharpLoggerObserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class CsharpLoggerObserver extends BaseLoggerObserver {
7575
}
7676

7777
private handleIntegrityCheckSuccess(event: Event.IntegrityCheckSuccess) {
78-
this.logger.appendLine("Integrity Check succeeded.")
78+
this.logger.appendLine("Integrity Check succeeded.");
7979
}
8080

8181
private handleIntegrityCheckFailure(event: Event.IntegrityCheckFailure) {

src/omnisharp/loggingEvents.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ export class IntegrityCheckSuccess {
170170
constructor() { }
171171
}
172172

173-
export class DownloadValidation {
174-
constructor(public packageDescription: string){ }
175-
}
176-
177173
export class RazorPluginPathSpecified implements BaseEvent {
178174
constructor(public path: string) {}
179175
}
@@ -213,4 +209,5 @@ export class OmnisharpServerOnStop implements BaseEvent { }
213209
export class OmnisharpServerOnStart implements BaseEvent { }
214210
export class LatestBuildDownloadStart implements BaseEvent { }
215211
export class OmnisharpRestart implements BaseEvent { }
216-
export class DotNetTestDebugComplete implements BaseEvent { }
212+
export class DotNetTestDebugComplete implements BaseEvent { }
213+
export class DownloadValidation implements BaseEvent { }

src/packageManager/downloadAndInstallPackages.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { EventStream } from '../EventStream';
1111
import { NetworkSettingsProvider } from "../NetworkSettings";
1212
import { AbsolutePathPackage } from "./AbsolutePathPackage";
1313
import { touchInstallFile, InstallFileType, deleteInstallFile, installFileExists } from "../common";
14-
import { InstallationFailure, IntegrityCheckFailure, DownloadValidation, IntegrityCheckSuccess } from "../omnisharp/loggingEvents";
14+
import { InstallationFailure, IntegrityCheckFailure } from "../omnisharp/loggingEvents";
1515
import { mkdirpSync } from "fs-extra";
1616
import { PackageInstallStart } from "../omnisharp/loggingEvents";
1717
import { isValidDownload } from './isValidDownload';
@@ -28,9 +28,7 @@ export async function downloadAndInstallPackages(packages: AbsolutePathPackage[]
2828
while (count < 2) {
2929
count++;
3030
let buffer = await DownloadFile(pkg.description, eventStream, provider, pkg.url, pkg.fallbackUrl);
31-
eventStream.post(new DownloadValidation(pkg.description));
32-
if (isValidDownload(buffer, pkg.integrity)) {
33-
eventStream.post(new IntegrityCheckSuccess());
31+
if (isValidDownload(buffer, pkg.integrity, eventStream)) {
3432
await InstallZip(buffer, pkg.description, pkg.installPath, pkg.binaries, eventStream);
3533
installationStage = 'touchLockFile';
3634
await touchInstallFile(pkg.installPath, InstallFileType.Lock);

src/packageManager/isValidDownload.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as crypto from "crypto";
7+
import { EventStream } from "../EventStream";
8+
import { IntegrityCheckSuccess, DownloadValidation } from "../omnisharp/loggingEvents";
79

8-
export function isValidDownload(buffer: Buffer, integrity: string): boolean {
10+
export function isValidDownload(buffer: Buffer, integrity: string, eventStream: EventStream): boolean {
911
let hash = crypto.createHash('sha256');
1012
if (integrity && integrity.length > 0) {
13+
eventStream.post(new DownloadValidation());
1114
hash.update(buffer);
1215
let value = hash.digest('hex');
1316
if (value.toUpperCase() == integrity.toUpperCase()) {
17+
eventStream.post(new IntegrityCheckSuccess());
1418
return true;
1519
}
1620
else {

test/unitTests/OmnisharpDownloader.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import MockHttpsServer from "./testAssets/MockHttpsServer";
1414
import {expect} from 'chai';
1515
import TestZip from "./testAssets/TestZip";
1616
import { createTestFile } from "./testAssets/TestFile";
17-
import { PackageInstallation, LogPlatformInfo, DownloadStart, DownloadSizeObtained, DownloadProgress, DownloadSuccess, InstallationStart, InstallationSuccess, PackageInstallStart, DownloadValidation, IntegrityCheckSuccess } from "../../src/omnisharp/loggingEvents";
17+
import { PackageInstallation, LogPlatformInfo, DownloadStart, DownloadSizeObtained, DownloadProgress, DownloadSuccess, InstallationStart, InstallationSuccess, PackageInstallStart } from "../../src/omnisharp/loggingEvents";
1818
import TestEventBus from "./testAssets/TestEventBus";
1919
import { testPackageJSON } from "./testAssets/testAssets";
2020

@@ -67,11 +67,9 @@ suite('OmnisharpDownloader', () => {
6767
new DownloadSizeObtained(testZip.size),
6868
new DownloadProgress(100, 'OmniSharp for Windows (.NET 4.6 / x86), Version = 1.2.3'),
6969
new DownloadSuccess(' Done!'),
70-
new DownloadValidation('OmniSharp for Windows (.NET 4.6 / x86), Version = 1.2.3'),
71-
new IntegrityCheckSuccess(),
7270
new InstallationStart('OmniSharp for Windows (.NET 4.6 / x86), Version = 1.2.3'),
7371
new InstallationSuccess()
74-
];
72+
];
7573

7674
expect(eventBus.getEvents()).to.be.empty;
7775
await downloader.DownloadAndInstallOmnisharp(version, server.baseUrl, installPath);

test/unitTests/Packages/downloadAndInstallPackages.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import TestZip from '../testAssets/TestZip';
1212
import { downloadAndInstallPackages } from '../../../src/packageManager/downloadAndInstallPackages';
1313
import NetworkSettings from '../../../src/NetworkSettings';
1414
import { EventStream } from '../../../src/EventStream';
15-
import { DownloadStart, DownloadSizeObtained, DownloadProgress, DownloadSuccess, InstallationStart, PackageInstallStart, DownloadValidation, IntegrityCheckSuccess } from '../../../src/omnisharp/loggingEvents';
15+
import { DownloadStart, DownloadSizeObtained, DownloadProgress, DownloadSuccess, InstallationStart, PackageInstallStart } from '../../../src/omnisharp/loggingEvents';
1616
import MockHttpsServer from '../testAssets/MockHttpsServer';
1717
import { createTestFile } from '../testAssets/TestFile';
1818
import TestEventBus from '../testAssets/TestEventBus';
@@ -91,8 +91,6 @@ suite(`${downloadAndInstallPackages.name}`, () => {
9191
new DownloadSizeObtained(testZip.size),
9292
new DownloadProgress(100, packageDescription),
9393
new DownloadSuccess(' Done!'),
94-
new DownloadValidation(packageDescription),
95-
new IntegrityCheckSuccess(),
9694
new InstallationStart(packageDescription)
9795
];
9896

test/unitTests/Packages/isValidDownload.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { isValidDownload } from "../../../src/packageManager/isValidDownload";
77
import * as chai from "chai";
8+
import { EventStream } from "../../../src/EventStream";
89

910
chai.should();
1011
const expect = chai.expect;
@@ -14,12 +15,12 @@ suite(`${isValidDownload.name}`, () => {
1415
const validIntegrity = "eb7201b5d986919e0ac67c820886358869d8f7059193d33c902ad7fe1688e1e9";
1516

1617
test('Returns false for non-matching integrity', async () => {
17-
let result = await isValidDownload(sampleBuffer, "inValidIntegrity");
18+
let result = await isValidDownload(sampleBuffer, "inValidIntegrity", new EventStream());
1819
expect(result).to.be.false;
1920
});
2021

2122
test('Returns true for matching integrity', async () => {
22-
let result = await isValidDownload(sampleBuffer, validIntegrity);
23+
let result = await isValidDownload(sampleBuffer, validIntegrity, new EventStream());
2324
expect(result).to.be.true;
2425
});
2526
});

0 commit comments

Comments
 (0)