@@ -701,7 +701,7 @@ public async Task DoesNotSpecializeMSISidecar_WhenMSIContextNull()
701
701
702
702
var meshServiceClient = new Mock < IMeshServiceClient > ( MockBehavior . Strict ) ;
703
703
meshServiceClient . Setup ( c => c . NotifyHealthEvent ( ContainerHealthEventType . Fatal ,
704
- It . Is < Type > ( t => t == typeof ( InstanceManager ) ) , "Could not specialize MSI sidecar since MSIContext was empty" ) ) . Returns ( Task . CompletedTask ) ;
704
+ It . Is < Type > ( t => t == typeof ( InstanceManager ) ) , "Could not specialize MSI sidecar since MSIContext and EncryptedTokenServiceSpecializationPayload were empty" ) ) . Returns ( Task . CompletedTask ) ;
705
705
706
706
var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . BadRequest , meshServiceClient . Object ) ;
707
707
@@ -711,10 +711,73 @@ public async Task DoesNotSpecializeMSISidecar_WhenMSIContextNull()
711
711
var logs = _loggerProvider . GetAllLogMessages ( ) . Select ( p => p . FormattedMessage ) . ToArray ( ) ;
712
712
Assert . Collection ( logs ,
713
713
p => Assert . StartsWith ( "MSI enabled status: True" , p ) ,
714
- p => Assert . StartsWith ( "Skipping specialization of MSI sidecar since MSIContext was absent" , p ) ) ;
714
+ p => Assert . StartsWith ( "Skipping specialization of MSI sidecar since MSIContext and EncryptedTokenServiceSpecializationPayload were absent" , p ) ) ;
715
715
716
716
meshServiceClient . Verify ( c => c . NotifyHealthEvent ( ContainerHealthEventType . Fatal ,
717
- It . Is < Type > ( t => t == typeof ( InstanceManager ) ) , "Could not specialize MSI sidecar since MSIContext was empty" ) , Times . Once ) ;
717
+ It . Is < Type > ( t => t == typeof ( InstanceManager ) ) , "Could not specialize MSI sidecar since MSIContext and EncryptedTokenServiceSpecializationPayload were empty" ) , Times . Once ) ;
718
+ }
719
+
720
+ [ Fact ]
721
+ public async Task SpecializeMSISidecar_Succeeds_EncryptedMSIContextWithoutProvidedEndpoint ( )
722
+ {
723
+ var environment = new Dictionary < string , string > ( )
724
+ {
725
+ { EnvironmentSettingNames . MsiEndpoint , "http://localhost:8081" } ,
726
+ { EnvironmentSettingNames . MsiSecret , "secret" }
727
+ } ;
728
+ var assignmentContext = new HostAssignmentContext
729
+ {
730
+ SiteId = 1234 ,
731
+ SiteName = "TestSite" ,
732
+ Environment = environment ,
733
+ IsWarmupRequest = false ,
734
+ MSIContext = new MSIContext ( ) ,
735
+ EncryptedTokenServiceSpecializationPayload = "TestContext"
736
+ } ;
737
+
738
+ var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . OK , null ) ;
739
+
740
+ string error = await instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
741
+ Assert . Null ( error ) ;
742
+
743
+ var logs = _loggerProvider . GetAllLogMessages ( ) . Select ( p => p . FormattedMessage ) . ToArray ( ) ;
744
+ Assert . Collection ( logs ,
745
+ p => Assert . StartsWith ( "MSI enabled status: True" , p ) ,
746
+ p => Assert . StartsWith ( "Using encrypted TokenService payload format" , p ) ,
747
+ p => Assert . Equal ( $ "Specializing sidecar at http://localhost:8081{ ScriptConstants . LinuxEncryptedTokenServiceSpecializationStem } ", p ) ,
748
+ p => Assert . StartsWith ( "Specialize MSI sidecar returned OK" , p ) ) ;
749
+ }
750
+
751
+ [ Fact ]
752
+ public async Task SpecializeMSISidecar_Succeeds_EncryptedMSIContextWithProvidedEndpoint ( )
753
+ {
754
+ var environment = new Dictionary < string , string > ( )
755
+ {
756
+ { EnvironmentSettingNames . MsiEndpoint , "http://localhost:8081" } ,
757
+ { EnvironmentSettingNames . MsiSecret , "secret" }
758
+ } ;
759
+ var assignmentContext = new HostAssignmentContext
760
+ {
761
+ SiteId = 1234 ,
762
+ SiteName = "TestSite" ,
763
+ Environment = environment ,
764
+ IsWarmupRequest = false ,
765
+ MSIContext = new MSIContext ( ) ,
766
+ EncryptedTokenServiceSpecializationPayload = "TestContext" ,
767
+ TokenServiceApiEndpoint = "/api/TestEndpoint"
768
+ } ;
769
+
770
+ var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . OK , null ) ;
771
+
772
+ string error = await instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
773
+ Assert . Null ( error ) ;
774
+
775
+ var logs = _loggerProvider . GetAllLogMessages ( ) . Select ( p => p . FormattedMessage ) . ToArray ( ) ;
776
+ Assert . Collection ( logs ,
777
+ p => Assert . StartsWith ( "MSI enabled status: True" , p ) ,
778
+ p => Assert . StartsWith ( "Using encrypted TokenService payload format" , p ) ,
779
+ p => Assert . Equal ( $ "Specializing sidecar at http://localhost:8081{ assignmentContext . TokenServiceApiEndpoint } ", p ) ,
780
+ p => Assert . StartsWith ( "Specialize MSI sidecar returned OK" , p ) ) ;
718
781
}
719
782
720
783
[ Fact ]
@@ -1258,9 +1321,15 @@ private InstanceManager GetInstanceManagerForMSISpecialization(HostAssignmentCon
1258
1321
1259
1322
var msiEndpoint = hostAssignmentContext . Environment [ EnvironmentSettingNames . MsiEndpoint ] + ScriptConstants . LinuxMSISpecializationStem ;
1260
1323
1324
+ var defaultEncryptedMsiEndpoint = hostAssignmentContext . Environment [ EnvironmentSettingNames . MsiEndpoint ] + ScriptConstants . LinuxEncryptedTokenServiceSpecializationStem ;
1325
+
1326
+ var providedEncryptedMsiEndpoint = hostAssignmentContext . Environment [ EnvironmentSettingNames . MsiEndpoint ] + hostAssignmentContext . TokenServiceApiEndpoint ;
1327
+
1261
1328
handlerMock . Protected ( ) . Setup < Task < HttpResponseMessage > > ( "SendAsync" ,
1262
1329
ItExpr . Is < HttpRequestMessage > ( request => request . Method == HttpMethod . Post
1263
- && request . RequestUri . AbsoluteUri . Equals ( msiEndpoint )
1330
+ && ( request . RequestUri . AbsoluteUri . Equals ( msiEndpoint )
1331
+ || request . RequestUri . AbsoluteUri . Equals ( defaultEncryptedMsiEndpoint )
1332
+ || request . RequestUri . AbsoluteUri . Equals ( providedEncryptedMsiEndpoint ) )
1264
1333
&& request . Content != null ) ,
1265
1334
ItExpr . IsAny < CancellationToken > ( ) ) . ReturnsAsync ( new HttpResponseMessage
1266
1335
{
0 commit comments