@@ -18,7 +18,7 @@ public class ScriptJwtBearerExtensionsTests
18
18
[ InlineData ( true , false ) ]
19
19
[ InlineData ( false , true ) ]
20
20
[ InlineData ( false , false ) ]
21
- public void CreateTokenValidationParameters_HasExpectedAudience ( bool isPlaceholderModeEnabled , bool isLinuxConsumptionOnLegion )
21
+ public void CreateTokenValidationParameters_HasExpectedAudiences ( bool isPlaceholderModeEnabled , bool isLinuxConsumptionOnLegion )
22
22
{
23
23
var podName = "RandomPodName" ;
24
24
var containerName = "RandomContainerName" ;
@@ -82,5 +82,43 @@ public void CreateTokenValidationParameters_HasExpectedAudience(bool isPlacehold
82
82
}
83
83
}
84
84
}
85
+
86
+ [ Theory ]
87
+ [ InlineData ( "testsite" , "testsite" ) ]
88
+ [ InlineData ( "testsite" , "testsite__5bb5" ) ]
89
+ [ InlineData ( "testsite" , null ) ]
90
+ [ InlineData ( "testsite" , "" ) ]
91
+ public void CreateTokenValidationParameters_NonProductionSlot_HasExpectedAudiences ( string siteName , string runtimeSiteName )
92
+ {
93
+ string azFuncAudience = string . Format ( ScriptConstants . SiteAzureFunctionsUriFormat , siteName ) ;
94
+ string siteAudience = string . Format ( ScriptConstants . SiteUriFormat , siteName ) ;
95
+ string runtimeSiteAudience = string . Format ( ScriptConstants . SiteUriFormat , runtimeSiteName ) ;
96
+
97
+ var testEnv = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase )
98
+ {
99
+ { EnvironmentSettingNames . AzureWebsiteName , siteName } ,
100
+ { EnvironmentSettingNames . AzureWebsiteRuntimeSiteName , runtimeSiteName } ,
101
+ { ContainerEncryptionKey , Convert . ToBase64String ( TestHelpers . GenerateKeyBytes ( ) ) }
102
+ } ;
103
+
104
+ using ( new TestScopedSettings ( ScriptSettingsManager . Instance , testEnv ) )
105
+ {
106
+ var tokenValidationParameters = ScriptJwtBearerExtensions . CreateTokenValidationParameters ( ) ;
107
+ var audiences = tokenValidationParameters . ValidAudiences . ToArray ( ) ;
108
+
109
+ Assert . Equal ( audiences [ 0 ] , azFuncAudience ) ;
110
+ Assert . Equal ( audiences [ 1 ] , siteAudience ) ;
111
+
112
+ if ( string . Compare ( siteName , runtimeSiteName , StringComparison . OrdinalIgnoreCase ) == 0 )
113
+ {
114
+ Assert . Equal ( 2 , audiences . Length ) ;
115
+ }
116
+ else if ( ! string . IsNullOrEmpty ( runtimeSiteName ) )
117
+ {
118
+ Assert . Equal ( 3 , audiences . Length ) ;
119
+ Assert . Equal ( audiences [ 2 ] , runtimeSiteAudience ) ;
120
+ }
121
+ }
122
+ }
85
123
}
86
124
}
0 commit comments