@@ -14,71 +14,42 @@ namespace Microsoft.Azure.WebJobs.Script.Tests.Extensions
14
14
public class ScriptJwtBearerExtensionsTests
15
15
{
16
16
[ Theory ]
17
- [ InlineData ( true , true ) ]
18
- [ InlineData ( true , false ) ]
19
- [ InlineData ( false , true ) ]
20
- [ InlineData ( false , false ) ]
21
- public void CreateTokenValidationParameters_HasExpectedAudiences ( bool isPlaceholderModeEnabled , bool isLinuxConsumptionOnLegion )
17
+ [ InlineData ( true , "FlexConsumption" , null , "1" , "RandomPodName" , "" , "RandomPodName" ) ] // Placeholder mode Flex Consumption
18
+ [ InlineData ( true , "Dynamic" , null , "1" , null , "RandomContainerName" , "RandomContainerName" ) ] // Placeholder mode Linux Consumption on Legion
19
+ [ InlineData ( true , "Dynamic" , null , null , null , "RandomContainerName" , "RandomContainerName" ) ] // Placeholder mode Linux Consumption on Atlas
20
+ [ InlineData ( false , "FlexConsumption" , null , "1" , "RandomPodName" , null , "https://RandomSiteName.azurewebsites.net/azurefunctions,https://RandomSiteName.azurewebsites.net" ) ]
21
+ [ InlineData ( false , "Dynamic" , null , null , null , "RandomContainerName" , "https://RandomSiteName.azurewebsites.net/azurefunctions,https://RandomSiteName.azurewebsites.net" ) ]
22
+ [ InlineData ( false , "Dynamic" , "123" , null , null , null , "https://RandomSiteName.azurewebsites.net/azurefunctions,https://RandomSiteName.azurewebsites.net" ) ]
23
+ public void CreateTokenValidationParameters_HasExpectedAudiences ( bool isPlaceholderModeEnabled , string sku ,
24
+ string websiteInstanceId , string legionServiceHost , string podName , string containerName , string expectedAudiences )
22
25
{
23
- var podName = "RandomPodName" ;
24
- var containerName = "RandomContainerName" ;
25
26
var siteName = "RandomSiteName" ;
26
-
27
- var expectedWithSiteName = new string [ ]
28
- {
29
- string . Format ( ScriptConstants . SiteAzureFunctionsUriFormat , siteName ) ,
30
- string . Format ( ScriptConstants . SiteUriFormat , siteName )
31
- } ;
32
- var expectedWithPodName = new string [ ] { podName } ;
33
- var expectedWithContainerName = Array . Empty < string > ( ) ;
34
-
35
27
var testData = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase )
36
28
{
37
29
[ AzureWebsiteName ] = siteName ,
38
30
[ WebsitePodName ] = podName ,
39
- [ ContainerName ] = string . Empty
31
+ [ ContainerName ] = containerName ,
32
+ [ AzureWebsiteSku ] = sku ,
33
+ [ LegionServiceHost ] = legionServiceHost ,
34
+ [ AzureWebsiteInstanceId ] = websiteInstanceId
40
35
} ;
41
36
42
37
if ( isPlaceholderModeEnabled )
43
38
{
44
39
testData [ AzureWebsitePlaceholderMode ] = "1" ;
45
40
}
46
41
47
- if ( isLinuxConsumptionOnLegion )
48
- {
49
- testData [ AzureWebsiteInstanceId ] = string . Empty ;
50
- testData [ WebsitePodName ] = podName ;
51
- testData [ LegionServiceHost ] = "1" ;
52
- }
53
- else
54
- {
55
- expectedWithContainerName = new string [ ] { containerName } ;
56
- testData [ AzureWebsiteInstanceId ] = string . Empty ;
57
- testData [ ContainerName ] = containerName ;
58
- }
59
-
60
42
testData [ ContainerEncryptionKey ] = Convert . ToBase64String ( TestHelpers . GenerateKeyBytes ( ) ) ;
61
43
using ( new TestScopedSettings ( ScriptSettingsManager . Instance , testData ) )
62
44
{
63
45
var tokenValidationParameters = ScriptJwtBearerExtensions . CreateTokenValidationParameters ( ) ;
64
46
var audiences = tokenValidationParameters . ValidAudiences . ToList ( ) ;
65
47
66
- if ( isPlaceholderModeEnabled &&
67
- isLinuxConsumptionOnLegion )
68
- {
69
- Assert . Equal ( audiences . Count , expectedWithPodName . Length ) ;
70
- Assert . Equal ( audiences [ 0 ] , expectedWithPodName [ 0 ] ) ;
71
- }
72
- else if ( isPlaceholderModeEnabled )
73
- {
74
- Assert . Equal ( audiences . Count , expectedWithContainerName . Length ) ;
75
- Assert . Equal ( audiences [ 0 ] , expectedWithContainerName [ 0 ] ) ;
76
- }
77
- else
48
+ string [ ] parsedAudiences = expectedAudiences . Split ( ',' ) ;
49
+ Assert . Equal ( audiences . Count , parsedAudiences . Length ) ;
50
+ for ( int i = 0 ; i < audiences . Count ; i ++ )
78
51
{
79
- Assert . Equal ( audiences . Count , expectedWithSiteName . Length ) ;
80
- Assert . True ( audiences . Contains ( expectedWithSiteName [ 0 ] ) ) ;
81
- Assert . True ( audiences . Contains ( expectedWithSiteName [ 1 ] ) ) ;
52
+ Assert . Equal ( audiences [ i ] , parsedAudiences [ i ] ) ;
82
53
}
83
54
}
84
55
}
0 commit comments