@@ -172,7 +172,7 @@ describe('Master tests', function() {
172172 aimsKeyId : 'aimsKeyId' ,
173173 aimsKeySecret : 'aimsKeySecret' ,
174174 alApiEndpoint : 'alApiEndpoint' ,
175- alIngestEndpoint : 'alIngestEndpoint ' ,
175+ alAzcollectEndpoint : 'alAzcollectEndpoint ' ,
176176 alDataResidency : 'default'
177177 } ;
178178 var azureOpts = {
@@ -197,7 +197,77 @@ describe('Master tests', function() {
197197 done ( ) ;
198198 } ) ;
199199 } ) ;
200-
200+
201+ it ( 'Verify register with MSI' , function ( done ) {
202+ // Mock Azure HTTP calls
203+ nock ( 'http://127.0.0.1:41963' , { 'encodedQueryParams' :true } )
204+ . get ( / t o k e n \/ $ / , / .* / )
205+ . query ( true )
206+ . times ( 5 )
207+ . reply ( 200 , mock . AZURE_TOKEN_MOCK ) ;
208+
209+ nock ( 'https://management.azure.com:443' , { 'encodedQueryParams' :true } )
210+ . put ( / a p p s e t t i n g s / , / .* / )
211+ . query ( true )
212+ . times ( 4 )
213+ . reply ( 200 , { } ) ;
214+
215+ nock ( 'https://management.azure.com:443' , { 'encodedQueryParams' :true } )
216+ . post ( / a p p s e t t i n g s / , / .* / )
217+ . query ( true )
218+ . times ( 4 )
219+ . reply ( 200 , { } ) ;
220+
221+ // Mock Alert Logic HTTP calls
222+ fakePost = sinon . stub ( alcollector . AlServiceC . prototype , 'post' ) ;
223+ fakePost . withArgs ( '/azure/ehub/subscription-id/rg/app-name' )
224+ . resolves ( {
225+ source : {
226+ host : {
227+ id : 'new-host-id1'
228+ } ,
229+ id : 'new-source-id1'
230+ }
231+ } ) ;
232+
233+ var alOpts = {
234+ aimsKeyId : 'aimsKeyId' ,
235+ aimsKeySecret : 'aimsKeySecret' ,
236+ alApiEndpoint : 'alApiEndpoint' ,
237+ alDataResidency : 'default'
238+ } ;
239+
240+ delete process . env . COLLECTOR_HOST_ID ;
241+ delete process . env . COLLECTOR_SOURCE_ID ;
242+ process . env . WEBSITE_SITE_NAME = 'app-name' ;
243+ process . env . APP_SUBSCRIPTION_ID = 'subscription-id' ;
244+ process . env . APP_RESOURCE_GROUP = 'rg' ;
245+ process . env . MSI_SECRET = 'MSI secret' ;
246+ process . env . MSI_ENDPOINT = 'http://127.0.0.1:41963/MSI/token/' ;
247+ process . env . APP_PRINCIPAL_ID = 'msi-principal-id' ;
248+
249+ var master = new AlAzureMaster ( mock . DEFAULT_FUNCTION_CONTEXT , 'ehub' , '1.0.0' , [ ] , [ ] , alOpts ) ;
250+
251+ master . register ( { } , function ( err , collectorHostId , collectorSourceId ) {
252+ if ( err ) console . log ( err ) ;
253+ assert . equal ( collectorHostId , 'new-host-id1' ) ;
254+ assert . equal ( collectorSourceId , 'new-source-id1' ) ;
255+ const expectedBody = {
256+ body : {
257+ app_tenant_id : 'tenant-id' ,
258+ client_id : process . env . APP_PRINCIPAL_ID ,
259+ client_secret : 'Managed Service Identity' ,
260+ version : '1.0.0'
261+ }
262+ } ;
263+ sinon . assert . calledWith ( fakePost , '/azure/ehub/subscription-id/rg/app-name' , expectedBody ) ;
264+ delete process . env . MSI_SECRET ;
265+ delete process . env . MSI_ENDPOINT ;
266+ delete process . env . APP_PRINCIPAL_ID ;
267+ done ( ) ;
268+ } ) ;
269+ } ) ;
270+
201271 it ( 'Verify register reuse endpoints and collector ids from env' , function ( done ) {
202272 // Expected Alert Logic parameters
203273 process . env . WEBSITE_HOSTNAME = 'app-name' ;
0 commit comments