@@ -618,6 +618,69 @@ public async Task SpecializeMSISidecar_Succeeds()
618
618
p => Assert . StartsWith ( "Specialize MSI sidecar returned OK" , p ) ) ;
619
619
}
620
620
621
+ [ Fact ]
622
+ public async Task SpecializeMSISidecar_Succeeds_EncryptedMSIContextWithoutProvidedEndpoint ( )
623
+ {
624
+ var environment = new Dictionary < string , string > ( )
625
+ {
626
+ { EnvironmentSettingNames . MsiEndpoint , "http://localhost:8081" } ,
627
+ { EnvironmentSettingNames . MsiSecret , "secret" }
628
+ } ;
629
+ var assignmentContext = new HostAssignmentContext
630
+ {
631
+ SiteId = 1234 ,
632
+ SiteName = "TestSite" ,
633
+ Environment = environment ,
634
+ IsWarmupRequest = false ,
635
+ MSIContext = new MSIContext ( ) ,
636
+ EncryptedTokenServiceSpecializationPayload = "TestContext"
637
+ } ;
638
+
639
+ var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . OK , null ) ;
640
+
641
+ string error = await instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
642
+ Assert . Null ( error ) ;
643
+
644
+ var logs = _loggerProvider . GetAllLogMessages ( ) . Select ( p => p . FormattedMessage ) . ToArray ( ) ;
645
+ Assert . Collection ( logs ,
646
+ p => Assert . StartsWith ( "MSI enabled status: True" , p ) ,
647
+ p => Assert . StartsWith ( "Using encrypted TokenService payload format" , p ) ,
648
+ p => Assert . Equal ( $ "Specializing sidecar at http://localhost:8081{ ScriptConstants . LinuxEncryptedTokenServiceSpecializationStem } ", p ) ,
649
+ p => Assert . StartsWith ( "Specialize MSI sidecar returned OK" , p ) ) ;
650
+ }
651
+
652
+ [ Fact ]
653
+ public async Task SpecializeMSISidecar_Succeeds_EncryptedMSIContextWithProvidedEndpoint ( )
654
+ {
655
+ var environment = new Dictionary < string , string > ( )
656
+ {
657
+ { EnvironmentSettingNames . MsiEndpoint , "http://localhost:8081" } ,
658
+ { EnvironmentSettingNames . MsiSecret , "secret" }
659
+ } ;
660
+ var assignmentContext = new HostAssignmentContext
661
+ {
662
+ SiteId = 1234 ,
663
+ SiteName = "TestSite" ,
664
+ Environment = environment ,
665
+ IsWarmupRequest = false ,
666
+ MSIContext = new MSIContext ( ) ,
667
+ EncryptedTokenServiceSpecializationPayload = "TestContext" ,
668
+ TokenServiceApiEndpoint = "/api/TestEndpoint"
669
+ } ;
670
+
671
+ var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . OK , null ) ;
672
+
673
+ string error = await instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
674
+ Assert . Null ( error ) ;
675
+
676
+ var logs = _loggerProvider . GetAllLogMessages ( ) . Select ( p => p . FormattedMessage ) . ToArray ( ) ;
677
+ Assert . Collection ( logs ,
678
+ p => Assert . StartsWith ( "MSI enabled status: True" , p ) ,
679
+ p => Assert . StartsWith ( "Using encrypted TokenService payload format" , p ) ,
680
+ p => Assert . Equal ( $ "Specializing sidecar at http://localhost:8081{ assignmentContext . TokenServiceApiEndpoint } ", p ) ,
681
+ p => Assert . StartsWith ( "Specialize MSI sidecar returned OK" , p ) ) ;
682
+ }
683
+
621
684
[ Fact ]
622
685
public async Task SpecializeMsiSidecar_RequiredPropertiesInPayload ( )
623
686
{
@@ -751,7 +814,7 @@ public async Task DoesNotSpecializeMSISidecar_WhenMSIContextNull()
751
814
752
815
var meshServiceClient = new Mock < IMeshServiceClient > ( MockBehavior . Strict ) ;
753
816
meshServiceClient . Setup ( c => c . NotifyHealthEvent ( ContainerHealthEventType . Fatal ,
754
- It . Is < Type > ( t => t == typeof ( AtlasInstanceManager ) ) , "Could not specialize MSI sidecar since MSIContext was empty" ) ) . Returns ( Task . CompletedTask ) ;
817
+ It . Is < Type > ( t => t == typeof ( AtlasInstanceManager ) ) , "Could not specialize MSI sidecar since MSIContext and EncryptedTokenServiceSpecializationPayload were empty" ) ) . Returns ( Task . CompletedTask ) ;
755
818
756
819
var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . BadRequest , meshServiceClient . Object ) ;
757
820
@@ -761,10 +824,10 @@ public async Task DoesNotSpecializeMSISidecar_WhenMSIContextNull()
761
824
var logs = _loggerProvider . GetAllLogMessages ( ) . Select ( p => p . FormattedMessage ) . ToArray ( ) ;
762
825
Assert . Collection ( logs ,
763
826
p => Assert . StartsWith ( "MSI enabled status: True" , p ) ,
764
- p => Assert . StartsWith ( "Skipping specialization of MSI sidecar since MSIContext was absent" , p ) ) ;
827
+ p => Assert . StartsWith ( "Skipping specialization of MSI sidecar since MSIContext and EncryptedTokenServiceSpecializationPayload were absent" , p ) ) ;
765
828
766
829
meshServiceClient . Verify ( c => c . NotifyHealthEvent ( ContainerHealthEventType . Fatal ,
767
- It . Is < Type > ( t => t == typeof ( AtlasInstanceManager ) ) , "Could not specialize MSI sidecar since MSIContext was empty" ) , Times . Once ) ;
830
+ It . Is < Type > ( t => t == typeof ( AtlasInstanceManager ) ) , "Could not specialize MSI sidecar since MSIContext and EncryptedTokenServiceSpecializationPayload were empty" ) , Times . Once ) ;
768
831
}
769
832
770
833
[ Fact ]
@@ -1308,9 +1371,15 @@ private AtlasInstanceManager GetInstanceManagerForMSISpecialization(HostAssignme
1308
1371
1309
1372
var msiEndpoint = hostAssignmentContext . Environment [ EnvironmentSettingNames . MsiEndpoint ] + ScriptConstants . LinuxMSISpecializationStem ;
1310
1373
1374
+ var defaultEncryptedMsiEndpoint = hostAssignmentContext . Environment [ EnvironmentSettingNames . MsiEndpoint ] + ScriptConstants . LinuxEncryptedTokenServiceSpecializationStem ;
1375
+
1376
+ var providedEncryptedMsiEndpoint = hostAssignmentContext . Environment [ EnvironmentSettingNames . MsiEndpoint ] + hostAssignmentContext . TokenServiceApiEndpoint ;
1377
+
1311
1378
handlerMock . Protected ( ) . Setup < Task < HttpResponseMessage > > ( "SendAsync" ,
1312
1379
ItExpr . Is < HttpRequestMessage > ( request => request . Method == HttpMethod . Post
1313
- && request . RequestUri . AbsoluteUri . Equals ( msiEndpoint )
1380
+ && ( request . RequestUri . AbsoluteUri . Equals ( msiEndpoint )
1381
+ || request . RequestUri . AbsoluteUri . Equals ( defaultEncryptedMsiEndpoint )
1382
+ || request . RequestUri . AbsoluteUri . Equals ( providedEncryptedMsiEndpoint ) )
1314
1383
&& request . Content != null ) ,
1315
1384
ItExpr . IsAny < CancellationToken > ( ) )
1316
1385
. Callback < HttpRequestMessage , CancellationToken > ( ( request , token ) => customAction ? . Invoke ( request , token ) )
0 commit comments