1
- import { before , after , beforeEach , afterEach } from 'mocha' ;
1
+ import { before , beforeEach , afterEach } from 'mocha' ;
2
2
import { connect } from 'mongodb-data-service' ;
3
3
import { expect } from 'chai' ;
4
4
import sinon from 'sinon' ;
5
5
import type { DataService } from 'mongodb-data-service' ;
6
+ import mongoDBBuildInfo from 'mongodb-build-info' ;
6
7
7
8
import * as getCloudInfoModule from 'mongodb-cloud-info' ;
8
9
@@ -13,16 +14,14 @@ import { TEST_DATABASE_URI } from '../dbTestHelper';
13
14
suite ( 'ConnectionTelemetry Controller Test Suite' , function ( ) {
14
15
suite ( 'with mock data service' , function ( ) {
15
16
this . timeout ( 8000 ) ;
16
- let dataServiceStub : DataService ;
17
17
const sandbox = sinon . createSandbox ( ) ;
18
+ let dataServiceStub ;
19
+ let getConnectionStringStub ;
20
+ let isAtlasStub ;
18
21
19
22
before ( ( ) => {
20
- const getConnectionStringStub = sandbox . stub ( ) ;
21
- getConnectionStringStub . returns ( {
22
- hosts : [ 'localhost:27088' ] ,
23
- searchParams : { get : ( ) => null } ,
24
- username : 'authMechanism' ,
25
- } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
23
+ getConnectionStringStub = sandbox . stub ( ) ;
24
+ isAtlasStub = sinon . stub ( mongoDBBuildInfo , 'isAtlas' ) ;
26
25
27
26
const instanceStub = sandbox . stub ( ) ;
28
27
instanceStub . resolves ( {
@@ -46,11 +45,51 @@ suite('ConnectionTelemetry Controller Test Suite', function () {
46
45
) ;
47
46
} ) ;
48
47
49
- after ( ( ) => {
48
+ afterEach ( ( ) => {
50
49
sandbox . restore ( ) ;
51
50
} ) ;
52
51
52
+ test ( 'it returns atlas_host_id hostname for atlas clusters' , async ( ) => {
53
+ isAtlasStub . returns ( true ) ;
54
+ getConnectionStringStub . returns ( {
55
+ hosts : [ 'test-data-sets-a011bb.test.net' ] ,
56
+ searchParams : { get : ( ) => null } ,
57
+ } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
58
+
59
+ const instanceTelemetry = await getConnectionTelemetryProperties (
60
+ dataServiceStub ,
61
+ ConnectionTypes . CONNECTION_FORM
62
+ ) ;
63
+
64
+ expect ( instanceTelemetry . is_atlas ) . to . equal ( true ) ;
65
+ expect ( instanceTelemetry . atlas_host_id ) . to . equal (
66
+ 'test-data-sets-a011bb.test.net'
67
+ ) ;
68
+ } ) ;
69
+
70
+ test ( 'it returns atlas_host_id null for non atlas clusters' , async ( ) => {
71
+ isAtlasStub . returns ( false ) ;
72
+ getConnectionStringStub . returns ( {
73
+ hosts : [ 'localhost:27088' ] ,
74
+ searchParams : { get : ( ) => null } ,
75
+ } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
76
+
77
+ const instanceTelemetry = await getConnectionTelemetryProperties (
78
+ dataServiceStub ,
79
+ ConnectionTypes . CONNECTION_FORM
80
+ ) ;
81
+
82
+ expect ( instanceTelemetry . is_atlas ) . to . equal ( false ) ;
83
+ expect ( instanceTelemetry . atlas_host_id ) . to . equal ( null ) ;
84
+ } ) ;
85
+
53
86
test ( 'it returns is_used_connect_screen true when the connection type is form' , async ( ) => {
87
+ isAtlasStub . returns ( false ) ;
88
+ getConnectionStringStub . returns ( {
89
+ hosts : [ 'localhost:27088' ] ,
90
+ searchParams : { get : ( ) => null } ,
91
+ } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
92
+
54
93
const instanceTelemetry = await getConnectionTelemetryProperties (
55
94
dataServiceStub ,
56
95
ConnectionTypes . CONNECTION_FORM
@@ -62,6 +101,12 @@ suite('ConnectionTelemetry Controller Test Suite', function () {
62
101
} ) ;
63
102
64
103
test ( 'it returns is_used_command_palette true when the connection type is string' , async ( ) => {
104
+ isAtlasStub . returns ( false ) ;
105
+ getConnectionStringStub . returns ( {
106
+ hosts : [ 'localhost:27088' ] ,
107
+ searchParams : { get : ( ) => null } ,
108
+ } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
109
+
65
110
const instanceTelemetry = await getConnectionTelemetryProperties (
66
111
dataServiceStub ,
67
112
ConnectionTypes . CONNECTION_STRING
@@ -73,6 +118,12 @@ suite('ConnectionTelemetry Controller Test Suite', function () {
73
118
} ) ;
74
119
75
120
test ( 'it returns is_used_saved_connection true when the connection type is id' , async ( ) => {
121
+ isAtlasStub . returns ( false ) ;
122
+ getConnectionStringStub . returns ( {
123
+ hosts : [ 'localhost:27088' ] ,
124
+ searchParams : { get : ( ) => null } ,
125
+ } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
126
+
76
127
const instanceTelemetry = await getConnectionTelemetryProperties (
77
128
dataServiceStub ,
78
129
ConnectionTypes . CONNECTION_ID
@@ -83,7 +134,13 @@ suite('ConnectionTelemetry Controller Test Suite', function () {
83
134
expect ( instanceTelemetry . is_used_saved_connection ) . to . equal ( true ) ;
84
135
} ) ;
85
136
86
- test ( 'it has is_localhost false for a remote connection' , async ( ) => {
137
+ test ( 'it returns is_localhost false for a remote connection' , async ( ) => {
138
+ isAtlasStub . returns ( false ) ;
139
+ getConnectionStringStub . returns ( {
140
+ hosts : [ 'localhost:27088' ] ,
141
+ searchParams : { get : ( ) => null } ,
142
+ } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
143
+
87
144
const instanceTelemetry = await getConnectionTelemetryProperties (
88
145
dataServiceStub ,
89
146
ConnectionTypes . CONNECTION_STRING
@@ -92,22 +149,50 @@ suite('ConnectionTelemetry Controller Test Suite', function () {
92
149
expect ( instanceTelemetry . is_localhost ) . to . equal ( false ) ;
93
150
} ) ;
94
151
95
- test ( 'it has a default is atlas false' , async ( ) => {
152
+ test ( 'it returns DEFAULT when auth mechanism undefined and username is specified' , async ( ) => {
153
+ isAtlasStub . returns ( false ) ;
154
+ getConnectionStringStub . returns ( {
155
+ hosts : [ 'localhost:27088' ] ,
156
+ searchParams : { get : ( ) => null } ,
157
+ username : 'Artishok' ,
158
+ } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
159
+
96
160
const instanceTelemetry = await getConnectionTelemetryProperties (
97
161
dataServiceStub ,
98
162
ConnectionTypes . CONNECTION_STRING
99
163
) ;
100
164
101
- expect ( instanceTelemetry . is_atlas ) . to . equal ( false ) ;
165
+ expect ( instanceTelemetry . auth_strategy ) . to . equal ( 'DEFAULT' ) ;
102
166
} ) ;
103
167
104
- test ( 'it has a default driver auth mechanism undefined' , async ( ) => {
168
+ test ( 'it returns NONE when auth mechanism undefined and username undefined' , async ( ) => {
169
+ isAtlasStub . returns ( false ) ;
170
+ getConnectionStringStub . returns ( {
171
+ hosts : [ 'localhost:27088' ] ,
172
+ searchParams : { get : ( ) => null } ,
173
+ } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
174
+
105
175
const instanceTelemetry = await getConnectionTelemetryProperties (
106
176
dataServiceStub ,
107
177
ConnectionTypes . CONNECTION_STRING
108
178
) ;
109
179
110
- expect ( instanceTelemetry . auth_strategy ) . to . equal ( 'DEFAULT' ) ;
180
+ expect ( instanceTelemetry . auth_strategy ) . to . equal ( 'NONE' ) ;
181
+ } ) ;
182
+
183
+ test ( 'it returns authMechanism when specified' , async ( ) => {
184
+ isAtlasStub . returns ( false ) ;
185
+ getConnectionStringStub . returns ( {
186
+ hosts : [ 'localhost:27088' ] ,
187
+ searchParams : { get : ( ) => 'SCRAM-SHA-1' } ,
188
+ } as unknown as ReturnType < DataService [ 'getConnectionString' ] > ) ;
189
+
190
+ const instanceTelemetry = await getConnectionTelemetryProperties (
191
+ dataServiceStub ,
192
+ ConnectionTypes . CONNECTION_STRING
193
+ ) ;
194
+
195
+ expect ( instanceTelemetry . auth_strategy ) . to . equal ( 'SCRAM-SHA-1' ) ;
111
196
} ) ;
112
197
} ) ;
113
198
0 commit comments