@@ -618,6 +618,56 @@ 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_RequiredPropertiesInPayload ( )
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
+ {
637
+ SiteName = "TestSite" ,
638
+ MSISecret = "TestSecret1234" ,
639
+ Identities = new [ ] { new ManagedServiceIdentity ( ) } ,
640
+ SystemAssignedIdentity = new ManagedServiceIdentity ( ) ,
641
+ DelegatedIdentities = new [ ] { new ManagedServiceIdentity ( ) } ,
642
+ UserAssignedIdentities = new [ ] { new ManagedServiceIdentity ( ) } ,
643
+ }
644
+ } ;
645
+
646
+ static async void verifyProperties ( HttpRequestMessage request , CancellationToken token )
647
+ {
648
+ var requestContent = await request . Content . ReadAsStringAsync ( token ) ;
649
+ var msiContext = JsonConvert . DeserializeObject < MSIContext > ( requestContent ) ;
650
+ Assert . NotNull ( msiContext ) ;
651
+ Assert . NotNull ( msiContext . Identities ) ;
652
+ Assert . NotNull ( msiContext . SystemAssignedIdentity ) ;
653
+ Assert . NotNull ( msiContext . UserAssignedIdentities ) ;
654
+ Assert . NotNull ( msiContext . DelegatedIdentities ) ;
655
+ Assert . True ( ! string . IsNullOrEmpty ( msiContext . MSISecret ) ) ;
656
+ Assert . True ( ! string . IsNullOrEmpty ( msiContext . SiteName ) ) ;
657
+ }
658
+
659
+ var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . OK , null , customAction : verifyProperties ) ;
660
+
661
+ string error = await instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
662
+ Assert . Null ( error ) ;
663
+
664
+ var logs = _loggerProvider . GetAllLogMessages ( ) . Select ( p => p . FormattedMessage ) . ToArray ( ) ;
665
+ Assert . Collection ( logs ,
666
+ p => Assert . StartsWith ( "MSI enabled status: True" , p ) ,
667
+ p => Assert . StartsWith ( "Specializing sidecar at http://localhost:8081" , p ) ,
668
+ p => Assert . StartsWith ( "Specialize MSI sidecar returned OK" , p ) ) ;
669
+ }
670
+
621
671
[ Fact ]
622
672
public async Task SpecializeMSISidecar_NoOp_ForWarmup_Request ( )
623
673
{
@@ -1252,7 +1302,7 @@ private static bool MatchesRunFromPackageContext(RunFromPackageContext r, string
1252
1302
}
1253
1303
1254
1304
private AtlasInstanceManager GetInstanceManagerForMSISpecialization ( HostAssignmentContext hostAssignmentContext ,
1255
- HttpStatusCode httpStatusCode , IMeshServiceClient meshServiceClient )
1305
+ HttpStatusCode httpStatusCode , IMeshServiceClient meshServiceClient , Action < HttpRequestMessage , CancellationToken > customAction = null )
1256
1306
{
1257
1307
var handlerMock = new Mock < HttpMessageHandler > ( MockBehavior . Strict ) ;
1258
1308
@@ -1262,7 +1312,9 @@ private AtlasInstanceManager GetInstanceManagerForMSISpecialization(HostAssignme
1262
1312
ItExpr . Is < HttpRequestMessage > ( request => request . Method == HttpMethod . Post
1263
1313
&& request . RequestUri . AbsoluteUri . Equals ( msiEndpoint )
1264
1314
&& request . Content != null ) ,
1265
- ItExpr . IsAny < CancellationToken > ( ) ) . ReturnsAsync ( new HttpResponseMessage
1315
+ ItExpr . IsAny < CancellationToken > ( ) )
1316
+ . Callback < HttpRequestMessage , CancellationToken > ( ( request , token ) => customAction ? . Invoke ( request , token ) )
1317
+ . ReturnsAsync ( new HttpResponseMessage
1266
1318
{
1267
1319
StatusCode = httpStatusCode
1268
1320
} ) ;
0 commit comments