forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixes to trust service #14352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fixes to trust service #14352
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 27, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"1\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"name": ".venvnokernel", | ||
"display_name": ".venvnokernel" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.2-final" | ||
}, | ||
"orig_nbformat": 2 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/datascience/interactive-common/trustService.vscode.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
'use strict'; | ||
|
||
import { assert } from 'chai'; | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import * as uuid from 'uuid/v4'; | ||
import { Uri } from 'vscode'; | ||
import { ITrustService } from '../../../client/datascience/types'; | ||
import { IExtensionTestApi } from '../../common'; | ||
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../constants'; | ||
import { initialize } from '../../initialize'; | ||
|
||
suite('DataScience - TrustService', () => { | ||
let api: IExtensionTestApi; | ||
let trustService: ITrustService; | ||
const templateIpynb = Uri.file( | ||
path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src/test/datascience/interactive-common/nbToTrust.ipynb') | ||
); | ||
suiteSetup(async () => { | ||
api = await initialize(); | ||
trustService = api.serviceContainer.get<ITrustService>(ITrustService); | ||
}); | ||
|
||
test('Trusting a notebook', async () => { | ||
const uri = Uri.file(path.join(templateIpynb.fsPath, uuid())); | ||
|
||
const contents = await fs.readFile(templateIpynb.fsPath, { encoding: 'utf8' }); | ||
assert.isFalse(await trustService.isNotebookTrusted(uri, contents), 'Notebook is not trusted'); | ||
|
||
await trustService.trustNotebook(uri, contents); | ||
assert.isTrue(await trustService.isNotebookTrusted(uri, contents), 'Notebook is not trusted'); | ||
}); | ||
test('Trusting a notebook (json saved with different formats)', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something I should have added in the previous PR. |
||
const uri = Uri.file(path.join(templateIpynb.fsPath, uuid())); | ||
const contents = await fs.readFile(templateIpynb.fsPath, { encoding: 'utf8' }); | ||
const contentsWithNoIndentation = JSON.stringify(JSON.parse(contents), undefined, ''); | ||
|
||
await trustService.trustNotebook(uri, contentsWithNoIndentation); | ||
assert.isTrue(await trustService.isNotebookTrusted(uri, contentsWithNoIndentation), 'Notebook is not trusted'); | ||
|
||
// Confirm the same json formatted with 2 & 4 spaces are considered trusted. | ||
const contentsWith2Indentation = JSON.stringify(JSON.parse(contents), undefined, 2); | ||
const contentsWith4Indentation = JSON.stringify(JSON.parse(contents), undefined, 4); | ||
assert.isTrue( | ||
await trustService.isNotebookTrusted(uri, contentsWith2Indentation), | ||
'Not trusted with 2 indents' | ||
); | ||
assert.isTrue( | ||
await trustService.isNotebookTrusted(uri, contentsWith4Indentation), | ||
'Not trusted with 4 indents' | ||
); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull the old commented out code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove in next PR, as CI is slow.