-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add protectConnectionStrings option COMPASS-6066 (#3660)
- Loading branch information
Showing
29 changed files
with
992 additions
and
54 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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
103 changes: 103 additions & 0 deletions
103
packages/compass-e2e-tests/tests/protect-connection-strings.test.ts
This file contains 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,103 @@ | ||
import type { CompassBrowser } from '../helpers/compass-browser'; | ||
import { beforeTests, afterTests, afterTest } from '../helpers/compass'; | ||
import type { Compass } from '../helpers/compass'; | ||
import clipboard from 'clipboardy'; | ||
import { expect } from 'chai'; | ||
import * as Selectors from '../helpers/selectors'; | ||
import type { ConnectFormState } from '../helpers/connect-form-state'; | ||
|
||
async function expectCopyConnectionStringToClipboard( | ||
browser: CompassBrowser, | ||
favoriteName: string, | ||
expected: string | ||
): Promise<void> { | ||
if (process.env.COMPASS_E2E_DISABLE_CLIPBOARD_USAGE !== 'true') { | ||
await browser.selectConnectionMenuItem( | ||
favoriteName, | ||
Selectors.CopyConnectionStringItem | ||
); | ||
await browser.waitUntil( | ||
async () => { | ||
return (await clipboard.read()) === expected; | ||
}, | ||
{ timeoutMsg: 'Expected copy to clipboard to work' } | ||
); | ||
} | ||
} | ||
|
||
describe('protectConnectionStrings', function () { | ||
let compass: Compass; | ||
let browser: CompassBrowser; | ||
|
||
before(async function () { | ||
compass = await beforeTests(); | ||
browser = compass.browser; | ||
await browser.setFeature('protectConnectionStrings', false); | ||
}); | ||
|
||
after(async function () { | ||
await browser.setFeature('protectConnectionStrings', false); | ||
await afterTests(compass, this.currentTest); | ||
}); | ||
|
||
afterEach(async function () { | ||
await afterTest(compass, this.currentTest); | ||
}); | ||
|
||
it('hides connection string credentials from users', async function () { | ||
const favoriteName = 'protected fave'; | ||
const state: ConnectFormState = { | ||
hosts: ['localhost:12345'], | ||
authMethod: 'DEFAULT', | ||
defaultUsername: 'foo', | ||
defaultPassword: 'bar', | ||
}; | ||
await browser.setConnectFormState(state); | ||
await browser.saveFavorite(favoriteName, 'color4'); | ||
await browser.selectFavorite(favoriteName); | ||
|
||
expect( | ||
await browser.$(Selectors.ConnectionStringInput).getValue() | ||
).to.equal('mongodb://foo:*****@localhost:12345/?authMechanism=DEFAULT'); | ||
|
||
// Enter edit connection string mode | ||
await browser.clickVisible(Selectors.EditConnectionStringToggle); | ||
const confirmModal = await browser.$(Selectors.EditConnectionStringModal); | ||
await confirmModal.waitForDisplayed(); | ||
await browser.clickVisible( | ||
Selectors.EditConnectionStringModalConfirmButton | ||
); | ||
|
||
expect( | ||
await browser.$(Selectors.ConnectionStringInput).getValue() | ||
).to.equal('mongodb://foo:bar@localhost:12345/?authMechanism=DEFAULT'); | ||
await expectCopyConnectionStringToClipboard( | ||
browser, | ||
favoriteName, | ||
'mongodb://foo:bar@localhost:12345/?authMechanism=DEFAULT' | ||
); | ||
await browser | ||
.$(Selectors.EditConnectionStringToggle) | ||
.waitForExist({ reverse: false }); | ||
await browser | ||
.$(Selectors.ShowConnectionFormButton) | ||
.waitForExist({ reverse: false }); | ||
|
||
await browser.setFeature('protectConnectionStrings', true); | ||
|
||
expect( | ||
await browser.$(Selectors.ConnectionStringInput).getValue() | ||
).to.equal('mongodb://foo:*****@localhost:12345/?authMechanism=DEFAULT'); | ||
await expectCopyConnectionStringToClipboard( | ||
browser, | ||
favoriteName, | ||
'mongodb://<credentials>@localhost:12345/?authMechanism=DEFAULT' | ||
); | ||
await browser | ||
.$(Selectors.EditConnectionStringToggle) | ||
.waitForExist({ reverse: true }); | ||
await browser | ||
.$(Selectors.ShowConnectionFormButton) | ||
.waitForExist({ reverse: true }); | ||
}); | ||
}); |
This file contains 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 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 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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import preferences from 'compass-preferences-model'; | ||
import AppRegistry from 'hadron-app-registry'; | ||
import { expect } from 'chai'; | ||
import compiler from 'bson-transpilers'; | ||
import configureStore from './'; | ||
import { uriChanged } from '../modules/uri'; | ||
import { driverChanged } from '../modules/driver'; | ||
import sinon from 'sinon'; | ||
|
||
const subscribeCheck = (s, pipeline, check, done) => { | ||
const unsubscribe = s.subscribe(function () { | ||
|
@@ -89,6 +93,38 @@ describe('ExportToLanguage Store', function () { | |
); | ||
appRegistry.emit('open-aggregation-export-to-language', agg); | ||
}); | ||
|
||
for (const protectConnectionStrings of [false, true]) { | ||
context( | ||
`when protect connection strings is ${protectConnectionStrings}`, | ||
function () { | ||
let sandbox; | ||
beforeEach(function () { | ||
sandbox = sinon.createSandbox(); | ||
sandbox | ||
.stub(preferences, 'getPreferences') | ||
.returns({ protectConnectionStrings }); | ||
}); | ||
afterEach(function () { | ||
return sandbox.restore(); | ||
}); | ||
|
||
it('showes/hides the connection string as appropriate', function (done) { | ||
unsubscribe = subscribeCheck( | ||
store, | ||
agg, | ||
(s) => | ||
s.transpiledExpression.includes('foo:bar') === | ||
!protectConnectionStrings, | ||
done | ||
); | ||
store.dispatch(uriChanged('mongodb://foo:[email protected]')); | ||
store.dispatch(driverChanged(true)); | ||
appRegistry.emit('open-aggregation-export-to-language', agg); | ||
}); | ||
} | ||
); | ||
} | ||
}); | ||
|
||
describe('when query opens export to language with imperfect fields', function () { | ||
|
This file contains 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,8 @@ | ||
ignores: | ||
- '@mongodb-js/prettier-config-compass' | ||
- '@mongodb-js/tsconfig-compass' | ||
- '@types/chai' | ||
- '@types/sinon-chai' | ||
- 'sinon' | ||
ignore-patterns: | ||
- 'dist' |
2 changes: 2 additions & 0 deletions
2
packages/compass-maybe-protect-connection-string/.eslintignore
This file contains 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,2 @@ | ||
.nyc-output | ||
dist |
8 changes: 8 additions & 0 deletions
8
packages/compass-maybe-protect-connection-string/.eslintrc.js
This file contains 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,8 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['@mongodb-js/eslint-config-compass'], | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: ['./tsconfig-lint.json'], | ||
}, | ||
}; |
This file contains 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 @@ | ||
module.exports = require('@mongodb-js/mocha-config-compass'); |
3 changes: 3 additions & 0 deletions
3
packages/compass-maybe-protect-connection-string/.prettierignore
This file contains 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,3 @@ | ||
.nyc_output | ||
dist | ||
coverage |
1 change: 1 addition & 0 deletions
1
packages/compass-maybe-protect-connection-string/.prettierrc.json
This file contains 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 @@ | ||
"@mongodb-js/prettier-config-compass" |
Oops, something went wrong.