mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
show notebook as trusted when it belongs to a trusted book (#15093)
* check for trusted books * don't add to trustedNotebooksMomento * update comment * added comments * remove empty line
This commit is contained in:
@@ -117,6 +117,7 @@ suite('CellToolbarActions', function (): void {
|
|||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
instantiationService.stub(INotificationService, new TestNotificationService());
|
instantiationService.stub(INotificationService, new TestNotificationService());
|
||||||
instantiationService.stub(INotebookService, notebookService);
|
instantiationService.stub(INotebookService, notebookService);
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ suite('MarkdownTextTransformer', () => {
|
|||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
mockNotebookService = TypeMoq.Mock.ofInstance(notebookService);
|
mockNotebookService = TypeMoq.Mock.ofInstance(notebookService);
|
||||||
|
|
||||||
|
|||||||
@@ -701,6 +701,7 @@ function setupServices(arg: { workbenchThemeService?: WorkbenchThemeService, ins
|
|||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
instantiationService.stub(INotebookService, notebookService);
|
instantiationService.stub(INotebookService, notebookService);
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ import { IProductService } from 'vs/platform/product/common/productService';
|
|||||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||||
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
|
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||||
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
|
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class to mock azdata.nb.ServerManager object
|
* class to mock azdata.nb.ServerManager object
|
||||||
@@ -120,6 +122,7 @@ suite.skip('NotebookService:', function (): void {
|
|||||||
didInstallExtensionEmitter: Emitter<DidInstallExtensionEvent>,
|
didInstallExtensionEmitter: Emitter<DidInstallExtensionEvent>,
|
||||||
uninstallExtensionEmitter: Emitter<IExtensionIdentifier>,
|
uninstallExtensionEmitter: Emitter<IExtensionIdentifier>,
|
||||||
didUninstallExtensionEmitter: Emitter<DidUninstallExtensionEvent>;
|
didUninstallExtensionEmitter: Emitter<DidUninstallExtensionEvent>;
|
||||||
|
let configurationService: IConfigurationService;
|
||||||
|
|
||||||
setup(() => {
|
setup(() => {
|
||||||
testNo++;
|
testNo++;
|
||||||
@@ -143,6 +146,7 @@ suite.skip('NotebookService:', function (): void {
|
|||||||
didInstallExtensionEmitter = new Emitter<DidInstallExtensionEvent>();
|
didInstallExtensionEmitter = new Emitter<DidInstallExtensionEvent>();
|
||||||
uninstallExtensionEmitter = new Emitter<IExtensionIdentifier>();
|
uninstallExtensionEmitter = new Emitter<IExtensionIdentifier>();
|
||||||
didUninstallExtensionEmitter = new Emitter<DidUninstallExtensionEvent>();
|
didUninstallExtensionEmitter = new Emitter<DidUninstallExtensionEvent>();
|
||||||
|
configurationService = new TestConfigurationService();
|
||||||
|
|
||||||
instantiationService.stub(IExtensionManagementService, ExtensionManagementService);
|
instantiationService.stub(IExtensionManagementService, ExtensionManagementService);
|
||||||
instantiationService.stub(IExtensionManagementService, 'onInstallExtension', installExtensionEmitter.event);
|
instantiationService.stub(IExtensionManagementService, 'onInstallExtension', installExtensionEmitter.event);
|
||||||
@@ -159,7 +163,7 @@ suite.skip('NotebookService:', function (): void {
|
|||||||
|
|
||||||
notebookService = new NotebookService(lifecycleService, storageService, extensionServiceMock.object, extensionManagementService,
|
notebookService = new NotebookService(lifecycleService, storageService, extensionServiceMock.object, extensionManagementService,
|
||||||
instantiationService, fileService, logServiceMock.object, queryManagementService, contextService, productService,
|
instantiationService, fileService, logServiceMock.object, queryManagementService, contextService, productService,
|
||||||
editorService, untitledTextEditorService, editorGroupsService);
|
editorService, untitledTextEditorService, editorGroupsService, configurationService);
|
||||||
sandbox = sinon.sandbox.create();
|
sandbox = sinon.sandbox.create();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -457,7 +461,7 @@ suite.skip('NotebookService:', function (): void {
|
|||||||
};
|
};
|
||||||
errorHandler.setUnexpectedErrorHandler(onUnexpectedErrorVerifier);
|
errorHandler.setUnexpectedErrorHandler(onUnexpectedErrorVerifier);
|
||||||
// The following call throws an exception internally with queryManagementService parameter being undefined.
|
// The following call throws an exception internally with queryManagementService parameter being undefined.
|
||||||
new NotebookService(lifecycleService, storageService, extensionService, extensionManagementService, instantiationService, fileService, logService, /* queryManagementService */ undefined, contextService, productService, editorService, untitledTextEditorService, editorGroupsService);
|
new NotebookService(lifecycleService, storageService, extensionService, extensionManagementService, instantiationService, fileService, logService, /* queryManagementService */ undefined, contextService, productService, editorService, untitledTextEditorService, editorGroupsService, configurationService);
|
||||||
await unexpectedErrorPromise;
|
await unexpectedErrorPromise;
|
||||||
assert.strictEqual(unexpectedErrorCalled, true, `onUnexpectedError must be have been raised when queryManagementService is undefined when calling NotebookService constructor`);
|
assert.strictEqual(unexpectedErrorCalled, true, `onUnexpectedError must be have been raised when queryManagementService is undefined when calling NotebookService constructor`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ suite('Notebook Editor Model', function (): void {
|
|||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
let mockNotebookService = TypeMoq.Mock.ofInstance(notebookService);
|
let mockNotebookService = TypeMoq.Mock.ofInstance(notebookService);
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import { IEditorInput, IEditorPane } from 'vs/workbench/common/editor';
|
|||||||
import { isINotebookInput } from 'sql/workbench/services/notebook/browser/interface';
|
import { isINotebookInput } from 'sql/workbench/services/notebook/browser/interface';
|
||||||
import { INotebookShowOptions } from 'sql/workbench/api/common/sqlExtHost.protocol';
|
import { INotebookShowOptions } from 'sql/workbench/api/common/sqlExtHost.protocol';
|
||||||
import { NotebookLanguage } from 'sql/workbench/common/constants';
|
import { NotebookLanguage } from 'sql/workbench/common/constants';
|
||||||
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
|
|
||||||
const languageAssociationRegistry = Registry.as<ILanguageAssociationRegistry>(LanguageAssociationExtensions.LanguageAssociations);
|
const languageAssociationRegistry = Registry.as<ILanguageAssociationRegistry>(LanguageAssociationExtensions.LanguageAssociations);
|
||||||
|
|
||||||
@@ -140,7 +141,8 @@ export class NotebookService extends Disposable implements INotebookService {
|
|||||||
@IProductService private readonly productService: IProductService,
|
@IProductService private readonly productService: IProductService,
|
||||||
@IEditorService private _editorService: IEditorService,
|
@IEditorService private _editorService: IEditorService,
|
||||||
@IUntitledTextEditorService private _untitledEditorService: IUntitledTextEditorService,
|
@IUntitledTextEditorService private _untitledEditorService: IUntitledTextEditorService,
|
||||||
@IEditorGroupsService private _editorGroupService: IEditorGroupsService
|
@IEditorGroupsService private _editorGroupService: IEditorGroupsService,
|
||||||
|
@IConfigurationService private _configurationService: IConfigurationService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this._providersMemento = new Memento('notebookProviders', this._storageService);
|
this._providersMemento = new Memento('notebookProviders', this._storageService);
|
||||||
@@ -581,12 +583,22 @@ export class NotebookService extends Disposable implements INotebookService {
|
|||||||
if (notebookUri.scheme === Schemas.untitled) {
|
if (notebookUri.scheme === Schemas.untitled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
const trustedBooksConfigKey = 'notebook.trustedBooks';
|
||||||
|
|
||||||
let cacheInfo = this.trustedNotebooksMemento.trustedNotebooksCache[notebookUri.toString()];
|
let cacheInfo = this.trustedNotebooksMemento.trustedNotebooksCache[notebookUri.toString()];
|
||||||
if (!cacheInfo) {
|
if (!cacheInfo) {
|
||||||
|
// Check if the notebook belongs to a book that's trusted
|
||||||
|
// and is not part of untrusted queue.
|
||||||
|
let trustedBookDirectories: string[] = !this._unTrustedCacheQueue.find(n => n === notebookUri) ? this._configurationService?.getValue(trustedBooksConfigKey) ?? [] : [];
|
||||||
|
if (trustedBookDirectories.find(b => notebookUri.fsPath.indexOf(b) > -1)) {
|
||||||
|
return true;
|
||||||
|
// note: we're ignoring the dirty check below since that's needed only when
|
||||||
|
// someone trusts notebook after it's loaded and this check is during the load time
|
||||||
|
} else {
|
||||||
// This notebook was never trusted
|
// This notebook was never trusted
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// This was trusted. If it's not dirty (e.g. if we're not working on our cached copy)
|
// This was trusted. If it's not dirty (e.g. if we're not working on our cached copy)
|
||||||
// then should verify it's not been modified on disk since that invalidates trust relationship
|
// then should verify it's not been modified on disk since that invalidates trust relationship
|
||||||
if (!isDirty) {
|
if (!isDirty) {
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ suite('MainThreadNotebook Tests', () => {
|
|||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
mockNotebookService = TypeMoq.Mock.ofInstance(notebookService);
|
mockNotebookService = TypeMoq.Mock.ofInstance(notebookService);
|
||||||
notebookUri = URI.parse('file:/user/default/my.ipynb');
|
notebookUri = URI.parse('file:/user/default/my.ipynb');
|
||||||
|
|||||||
Reference in New Issue
Block a user