Skip to content

Commit 2a51dc6

Browse files
ege0zcanEge Ozcan
andauthored
chore: add eslint rule to prevent usage of global crypto (#1519)
* chore: add eslint rule to prevent usage of global crypto * chore: add smoke test for workspaceContextServer --------- Co-authored-by: Ege Ozcan <[email protected]>
1 parent b01610c commit 2a51dc6

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

server/aws-lsp-codewhisperer/.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ module.exports = {
99
rules: {
1010
'import/no-nodejs-modules': 'warn',
1111
'@typescript-eslint/no-floating-promises': 'error',
12+
'no-restricted-globals': [
13+
'error',
14+
{
15+
name: 'crypto',
16+
message: 'Do not use global crypto object which only exists in browsers and fails for node runtimes',
17+
},
18+
],
1219
},
1320
ignorePatterns: ['**/*.test.ts', 'out/', 'src.gen/', 'src/client/**/*.d.ts'],
1421
overrides: [
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { InitializeParams, Server } from '@aws/language-server-runtimes/server-interface'
2+
import { TestFeatures } from '@aws/language-server-runtimes/testing'
3+
import sinon from 'ts-sinon'
4+
import { WorkspaceContextServer } from './workspaceContextServer'
5+
6+
describe('WorkspaceContext Server', () => {
7+
let features: TestFeatures
8+
let server: Server
9+
10+
before(() => {
11+
features = new TestFeatures()
12+
server = WorkspaceContextServer()
13+
})
14+
15+
afterEach(() => {
16+
sinon.restore()
17+
})
18+
19+
describe('Initialization', () => {
20+
it('should generate a workspace identifier when none is provided', async () => {
21+
// Set up the test to simulate no workspaceIdentifier in initialization
22+
features.lsp.getClientInitializeParams.returns({
23+
initializationOptions: {
24+
aws: {
25+
clientInfo: {
26+
name: 'AmazonQ-For-VSCode',
27+
version: '0.0.1',
28+
extension: {
29+
name: 'AmazonQ-For-VSCode',
30+
version: '0.0.1',
31+
},
32+
},
33+
},
34+
},
35+
} as InitializeParams)
36+
37+
await features.initialize(server)
38+
39+
// Verify that a warning was logged (indicating the workspaceIdentifier was generated)
40+
sinon.assert.calledWith(features.logging.warn, sinon.match(/No workspaceIdentifier set/))
41+
})
42+
})
43+
})

0 commit comments

Comments
 (0)