Reenabling book trust manager tests (#23594)

* Reenabling book trust manager tests

* Also fix trustbook test
This commit is contained in:
Chris LaFreniere
2023-07-06 15:47:16 -07:00
committed by GitHub
parent 718bc0d737
commit 6125708b25
5 changed files with 21 additions and 24 deletions

View File

@@ -110,10 +110,10 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
void this._extensionContext.globalState.update(constants.visitedNotebooksMementoKey, value); void this._extensionContext.globalState.update(constants.visitedNotebooksMementoKey, value);
} }
trustBook(bookTreeItem?: BookTreeItem): void { async trustBook(bookTreeItem?: BookTreeItem): Promise<void> {
let bookPathToTrust: string = bookTreeItem ? bookTreeItem.root : this.currentBook?.bookPath; let bookPathToTrust: string = bookTreeItem ? bookTreeItem.root : this.currentBook?.bookPath;
if (bookPathToTrust) { if (bookPathToTrust) {
let trustChanged = this._bookTrustManager.setBookAsTrusted(bookPathToTrust, true); let trustChanged = await this._bookTrustManager.setBookAsTrusted(bookPathToTrust, true);
if (trustChanged) { if (trustChanged) {
let notebookDocuments = azdata.nb.notebookDocuments; let notebookDocuments = azdata.nb.notebookDocuments;
if (notebookDocuments) { if (notebookDocuments) {

View File

@@ -11,7 +11,7 @@ import { BookVersion } from './bookVersionHandler';
export interface IBookTrustManager { export interface IBookTrustManager {
isNotebookTrustedByDefault(notebookUri: string): boolean; isNotebookTrustedByDefault(notebookUri: string): boolean;
setBookAsTrusted(bookRootPath: string, isTrusted: boolean): boolean; setBookAsTrusted(bookRootPath: string, isTrusted: boolean): Promise<boolean>;
} }
enum TrustBookOperation { enum TrustBookOperation {
@@ -58,7 +58,7 @@ export class BookTrustManager implements IBookTrustManager {
.reduce((accumulator, currentBookItemList) => accumulator.concat(currentBookItemList), []); .reduce((accumulator, currentBookItemList) => accumulator.concat(currentBookItemList), []);
} }
setBookAsTrusted(bookRootPath: string, isTrusted: boolean): boolean { async setBookAsTrusted(bookRootPath: string, isTrusted: boolean): Promise<boolean> {
if (isTrusted) { if (isTrusted) {
return this.updateTrustedBooks(bookRootPath, TrustBookOperation.Add); return this.updateTrustedBooks(bookRootPath, TrustBookOperation.Add);
} }
@@ -72,11 +72,11 @@ export class BookTrustManager implements IBookTrustManager {
return trustedBookDirectories; return trustedBookDirectories;
} }
setTrustedBookPathsInConfig(bookPaths: string[]) { async setTrustedBookPathsInConfig(bookPaths: string[]): Promise<void> {
let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(constants.notebookConfigKey); let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(constants.notebookConfigKey);
let storeInWorspace: boolean = this.hasWorkspaceFolders(); let storeInWorspace: boolean = this.hasWorkspaceFolders();
void config.update(constants.trustedBooksConfigKey, bookPaths, storeInWorspace ? false : vscode.ConfigurationTarget.Global); return config.update(constants.trustedBooksConfigKey, bookPaths, storeInWorspace ? false : vscode.ConfigurationTarget.Global);
} }
hasWorkspaceFolders(): boolean { hasWorkspaceFolders(): boolean {
@@ -84,7 +84,7 @@ export class BookTrustManager implements IBookTrustManager {
return workspaceFolders && workspaceFolders.length > 0; return workspaceFolders && workspaceFolders.length > 0;
} }
updateTrustedBooks(bookPath: string, operation: TrustBookOperation) { async updateTrustedBooks(bookPath: string, operation: TrustBookOperation): Promise<boolean> {
let modifiedTrustedBooks = false; let modifiedTrustedBooks = false;
let bookPathToChange: string = path.join(bookPath, path.sep); let bookPathToChange: string = path.join(bookPath, path.sep);
@@ -110,7 +110,7 @@ export class BookTrustManager implements IBookTrustManager {
modifiedTrustedBooks = true; modifiedTrustedBooks = true;
} }
this.setTrustedBookPathsInConfig(trustedBooks); await this.setTrustedBookPathsInConfig(trustedBooks);
return modifiedTrustedBooks; return modifiedTrustedBooks;
} }

View File

@@ -51,7 +51,7 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openMarkdown', (resource: string) => bookTreeViewProvider.openMarkdown(resource))); extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openMarkdown', (resource: string) => bookTreeViewProvider.openMarkdown(resource)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openExternalLink', (resource: string) => bookTreeViewProvider.openExternalLink(resource))); extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openExternalLink', (resource: string) => bookTreeViewProvider.openExternalLink(resource)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.saveBook', () => providedBookTreeViewProvider.saveJupyterBooks())); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.saveBook', () => providedBookTreeViewProvider.saveJupyterBooks()));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.trustBook', (item: BookTreeItem) => bookTreeViewProvider.trustBook(item))); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.trustBook', async (item: BookTreeItem) => await bookTreeViewProvider.trustBook(item)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchBook', (item: BookTreeItem) => bookTreeViewProvider.searchJupyterBooks(item))); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchBook', (item: BookTreeItem) => bookTreeViewProvider.searchJupyterBooks(item)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchProvidedBook', () => providedBookTreeViewProvider.searchJupyterBooks())); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchProvidedBook', () => providedBookTreeViewProvider.searchJupyterBooks()));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.openBook', () => bookTreeViewProvider.openNewBook())); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.openBook', () => bookTreeViewProvider.openNewBook()));

View File

@@ -210,17 +210,15 @@ describe('BooksTreeViewTests', function () {
equalBookItems(notebook3, expectedNotebook3); equalBookItems(notebook3, expectedNotebook3);
}); });
// {{SQL CARBON TODO}} - disable failing test it('should set notebooks trusted to true on trustBook', async () => {
it.skip('should set notebooks trusted to true on trustBook', async () => {
let notebook1Path = notebook1.tooltip; let notebook1Path = notebook1.tooltip;
let bookTrustManager: BookTrustManager = new BookTrustManager(bookTreeViewProvider.books); let bookTrustManager: BookTrustManager = new BookTrustManager(bookTreeViewProvider.books);
let isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path); let isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path);
should(isTrusted).equal(false, 'Notebook should not be trusted by default'); should(isTrusted).equal(false, 'Notebook should not be trusted by default');
bookTreeViewProvider.trustBook(notebook1); await bookTreeViewProvider.trustBook(notebook1);
isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path); isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path);
should(isTrusted).equal(true, 'Failed to set trust on trustBook'); should(isTrusted).equal(true, 'Failed to set trust on trustBook');
}); });
it('getNavigation should get previous and next urls correctly from the bookModel', async () => { it('getNavigation should get previous and next urls correctly from the bookModel', async () => {

View File

@@ -182,7 +182,7 @@ describe('BookTrustManagerTests', function () {
should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted'); should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted');
// add another book subfolder // add another book subfolder
bookTrustManager.setBookAsTrusted('/SubFolder2/', true); await bookTrustManager.setBookAsTrusted('/SubFolder2/', true);
let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri); let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
@@ -211,7 +211,7 @@ describe('BookTrustManagerTests', function () {
}); });
it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => { it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => {
bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
let notebookUri = run.book1.notInTocNb; let notebookUri = run.book1.notInTocNb;
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri); let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
@@ -222,8 +222,7 @@ describe('BookTrustManagerTests', function () {
}); });
}); });
// {{SQL CARBON TODO}} - reenable this test suite https://github.com/microsoft/azuredatastudio/issues/23540 describe('TrustingInFolder', () => {
describe.skip('TrustingInFolder', () => {
let bookTrustManager: IBookTrustManager; let bookTrustManager: IBookTrustManager;
let books: BookModel[]; let books: BookModel[];
@@ -330,7 +329,7 @@ describe('BookTrustManagerTests', function () {
}); });
it('should trust notebooks in a trusted book in a folder', async () => { it('should trust notebooks in a trusted book in a folder', async () => {
bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
let notebookUri1 = run.book1.notebook1; let notebookUri1 = run.book1.notebook1;
let notebookUri2 = run.book1.notebook2; let notebookUri2 = run.book1.notebook2;
@@ -345,7 +344,7 @@ describe('BookTrustManagerTests', function () {
it('should NOT trust a notebook in an untrusted book in a folder', async () => { it('should NOT trust a notebook in an untrusted book in a folder', async () => {
//Set book as not trusted before running test //Set book as not trusted before running test
bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', false); await bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', false);
let notebookUri = run.book2.notebook1; let notebookUri = run.book2.notebook1;
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri); let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
@@ -355,13 +354,13 @@ describe('BookTrustManagerTests', function () {
it('should trust notebook after book has been added to a folder', async () => { it('should trust notebook after book has been added to a folder', async () => {
//Set book as not trusted before running test //Set book as not trusted before running test
bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', false); await bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', false);
let notebookUri = run.book2.notebook1; let notebookUri = run.book2.notebook1;
let isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri); let isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted'); should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted');
bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true); await bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true);
let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri); let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
@@ -369,8 +368,8 @@ describe('BookTrustManagerTests', function () {
}); });
it('should NOT trust a notebook when removing all books from folders', async () => { it('should NOT trust a notebook when removing all books from folders', async () => {
bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true); await bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true);
let notebookUri = run.book1.notebook1; let notebookUri = run.book1.notebook1;
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri); let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
let notebook2Uri = run.book2.notebook1; let notebook2Uri = run.book2.notebook1;
@@ -396,7 +395,7 @@ describe('BookTrustManagerTests', function () {
}); });
it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => { it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => {
bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
let notebookUri = run.book1.notInTocNb; let notebookUri = run.book1.notInTocNb;
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri); let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);