mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 01:25:37 -05:00
Reenabling book trust manager tests (#23594)
* Reenabling book trust manager tests * Also fix trustbook test
This commit is contained in:
@@ -110,10 +110,10 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
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;
|
||||
if (bookPathToTrust) {
|
||||
let trustChanged = this._bookTrustManager.setBookAsTrusted(bookPathToTrust, true);
|
||||
let trustChanged = await this._bookTrustManager.setBookAsTrusted(bookPathToTrust, true);
|
||||
if (trustChanged) {
|
||||
let notebookDocuments = azdata.nb.notebookDocuments;
|
||||
if (notebookDocuments) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { BookVersion } from './bookVersionHandler';
|
||||
|
||||
export interface IBookTrustManager {
|
||||
isNotebookTrustedByDefault(notebookUri: string): boolean;
|
||||
setBookAsTrusted(bookRootPath: string, isTrusted: boolean): boolean;
|
||||
setBookAsTrusted(bookRootPath: string, isTrusted: boolean): Promise<boolean>;
|
||||
}
|
||||
|
||||
enum TrustBookOperation {
|
||||
@@ -58,7 +58,7 @@ export class BookTrustManager implements IBookTrustManager {
|
||||
.reduce((accumulator, currentBookItemList) => accumulator.concat(currentBookItemList), []);
|
||||
}
|
||||
|
||||
setBookAsTrusted(bookRootPath: string, isTrusted: boolean): boolean {
|
||||
async setBookAsTrusted(bookRootPath: string, isTrusted: boolean): Promise<boolean> {
|
||||
if (isTrusted) {
|
||||
return this.updateTrustedBooks(bookRootPath, TrustBookOperation.Add);
|
||||
}
|
||||
@@ -72,11 +72,11 @@ export class BookTrustManager implements IBookTrustManager {
|
||||
return trustedBookDirectories;
|
||||
}
|
||||
|
||||
setTrustedBookPathsInConfig(bookPaths: string[]) {
|
||||
async setTrustedBookPathsInConfig(bookPaths: string[]): Promise<void> {
|
||||
let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(constants.notebookConfigKey);
|
||||
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 {
|
||||
@@ -84,7 +84,7 @@ export class BookTrustManager implements IBookTrustManager {
|
||||
return workspaceFolders && workspaceFolders.length > 0;
|
||||
}
|
||||
|
||||
updateTrustedBooks(bookPath: string, operation: TrustBookOperation) {
|
||||
async updateTrustedBooks(bookPath: string, operation: TrustBookOperation): Promise<boolean> {
|
||||
let modifiedTrustedBooks = false;
|
||||
let bookPathToChange: string = path.join(bookPath, path.sep);
|
||||
|
||||
@@ -110,7 +110,7 @@ export class BookTrustManager implements IBookTrustManager {
|
||||
modifiedTrustedBooks = true;
|
||||
}
|
||||
|
||||
this.setTrustedBookPathsInConfig(trustedBooks);
|
||||
await this.setTrustedBookPathsInConfig(trustedBooks);
|
||||
|
||||
return modifiedTrustedBooks;
|
||||
}
|
||||
|
||||
@@ -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.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.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.searchProvidedBook', () => providedBookTreeViewProvider.searchJupyterBooks()));
|
||||
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.openBook', () => bookTreeViewProvider.openNewBook()));
|
||||
|
||||
@@ -210,17 +210,15 @@ describe('BooksTreeViewTests', function () {
|
||||
equalBookItems(notebook3, expectedNotebook3);
|
||||
});
|
||||
|
||||
// {{SQL CARBON TODO}} - disable failing test
|
||||
it.skip('should set notebooks trusted to true on trustBook', async () => {
|
||||
it('should set notebooks trusted to true on trustBook', async () => {
|
||||
let notebook1Path = notebook1.tooltip;
|
||||
let bookTrustManager: BookTrustManager = new BookTrustManager(bookTreeViewProvider.books);
|
||||
let isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path);
|
||||
should(isTrusted).equal(false, 'Notebook should not be trusted by default');
|
||||
|
||||
bookTreeViewProvider.trustBook(notebook1);
|
||||
await bookTreeViewProvider.trustBook(notebook1);
|
||||
isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path);
|
||||
should(isTrusted).equal(true, 'Failed to set trust on trustBook');
|
||||
|
||||
});
|
||||
|
||||
it('getNavigation should get previous and next urls correctly from the bookModel', async () => {
|
||||
|
||||
@@ -182,7 +182,7 @@ describe('BookTrustManagerTests', function () {
|
||||
should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted');
|
||||
|
||||
// add another book subfolder
|
||||
bookTrustManager.setBookAsTrusted('/SubFolder2/', true);
|
||||
await bookTrustManager.setBookAsTrusted('/SubFolder2/', true);
|
||||
|
||||
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 () => {
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
|
||||
await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
|
||||
|
||||
let notebookUri = run.book1.notInTocNb;
|
||||
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.skip('TrustingInFolder', () => {
|
||||
describe('TrustingInFolder', () => {
|
||||
|
||||
let bookTrustManager: IBookTrustManager;
|
||||
let books: BookModel[];
|
||||
@@ -330,7 +329,7 @@ describe('BookTrustManagerTests', function () {
|
||||
});
|
||||
|
||||
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 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 () => {
|
||||
//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 isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
@@ -355,13 +354,13 @@ describe('BookTrustManagerTests', function () {
|
||||
|
||||
it('should trust notebook after book has been added to a folder', async () => {
|
||||
//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 isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
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);
|
||||
|
||||
@@ -369,8 +368,8 @@ describe('BookTrustManagerTests', function () {
|
||||
});
|
||||
|
||||
it('should NOT trust a notebook when removing all books from folders', async () => {
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true);
|
||||
await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
|
||||
await bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true);
|
||||
let notebookUri = run.book1.notebook1;
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
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 () => {
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
|
||||
await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true);
|
||||
|
||||
let notebookUri = run.book1.notInTocNb;
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
Reference in New Issue
Block a user