Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/cli-repl/src/cli-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,15 @@ describe('CliRepl', () => {
});
});

context('with an auth-required mongod', () => {
verifyAutocompletion({
testServer: startTestServer('not-shared', '--auth'),
wantWatch: false,
wantShardDistribution: false,
hasCollectionNames: false
});
});

function verifyAutocompletion({ testServer, wantWatch, wantShardDistribution, hasCollectionNames }: {
testServer: MongodSetup | null,
wantWatch: boolean,
Expand All @@ -786,6 +795,8 @@ describe('CliRepl', () => {

afterEach(async() => {
await cliRepl.mongoshRepl.close();
expect(output).not.to.include('Tab completion error');
expect(output).not.to.include('listCollections requires authentication');
});

it(`${wantWatch ? 'completes' : 'does not complete'} the watch method`, async() => {
Expand All @@ -799,6 +810,13 @@ describe('CliRepl', () => {
}
});

it('completes the db.version method', async() => {
output = '';
input.write('db.vers\u0009\u0009');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just super random thought .. we could have const TAB = "\u0009"; and db.vers${TAB}${TAB} or something .. not a life changing one :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, we already do that for e.g. arrow-up in the other tests. I’ll do that right after merging this.

await waitCompletion(cliRepl.bus);
expect(output).to.include('db.version');
});

it(`${wantShardDistribution ? 'completes' : 'does not complete'} the getShardDistribution method`, async() => {
output = '';
input.write('db.coll.getShardDis\u0009\u0009');
Expand Down
2 changes: 1 addition & 1 deletion packages/shell-api/src/shell-internal-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export default class ShellInternalState {
const collectionNames = await this.currentDb._getCollectionNamesForCompletion();
return collectionNames.filter((name) => name.startsWith(collName));
} catch (err) {
if (err.code === ShellApiErrors.NotConnected) {
if (err.code === ShellApiErrors.NotConnected || err.codeName === 'Unauthorized') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should 'Unauthorized' be also part ShellApiErrors to be consistent with the other?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a shell error, though, it’s a server error :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

return [];
}
throw err;
Expand Down