33
44using System ;
55using System . Collections . Generic ;
6+ using System . Text ;
67using System . Threading . Tasks ;
78using Azure . Data . Tables ;
89using Microsoft . Extensions . Configuration ;
@@ -33,6 +34,48 @@ public async Task TryCreateHostingTableServiceClient_ConnectionInWebHostConfigur
3334 await VerifyTableServiceClientAvailable ( client ) ;
3435 }
3536
37+ [ Fact ]
38+ public async Task TryCreateHostingTableServiceClient_ConnectionInJobHostConfiguration ( )
39+ {
40+ var testConfiguration = TestHelpers . GetTestConfiguration ( ) ;
41+ var testData = new Dictionary < string , string > ( StringComparer . Ordinal )
42+ {
43+ { "ConnectionStrings:AzureWebJobsStorage" , testConfiguration . GetWebJobsConnectionString ( StorageConnection ) } ,
44+ { "AzureWebJobsStorage" , "" }
45+ } ;
46+
47+ var webHostConfiguration = new ConfigurationBuilder ( ) . Build ( ) ;
48+ var jobHostConfiguration = new ConfigurationBuilder ( )
49+ . AddInMemoryCollection ( testData )
50+ . Build ( ) ;
51+
52+ var azureTableStorageProvider = TestHelpers . GetAzureTableStorageProvider ( webHostConfiguration , jobHostConfiguration ) ;
53+ azureTableStorageProvider . TryCreateHostingTableServiceClient ( out TableServiceClient client ) ;
54+ await VerifyTableServiceClientAvailable ( client ) ;
55+ }
56+
57+ [ Theory ]
58+ [ InlineData ( "AzureWebJobsStorage:accountName" , "storage" ) ]
59+ [ InlineData ( "AzureWebJobsStorage:AccountName" , "storage" ) ]
60+ [ InlineData ( "AzureWebJobsStorage:tableServiceUri" , "https://mytable.functions" ) ]
61+ [ InlineData ( "AzureWebJobsStorage:TableServiceUri" , "https://mytable.functions" ) ]
62+ public void TryCreateHostingTableServiceClient_IdentityBasedConnections ( string key , string value )
63+ {
64+ var testData = new Dictionary < string , string > ( StringComparer . Ordinal )
65+ {
66+ { key , value }
67+ } ;
68+
69+ // Using a case sensitive data source to match the ScriptEnvironmentVariablesConfigurationSource behavior on Linux (case-sensitive env vars)
70+ var webHostConfiguration = new ConfigurationBuilder ( ) . Build ( ) ;
71+ var jobHostConfiguration = new ConfigurationBuilder ( )
72+ . Add ( new CaseSensitiveConfigurationSource ( testData ) )
73+ . Build ( ) ;
74+
75+ var azureTableStorageProvider = TestHelpers . GetAzureTableStorageProvider ( webHostConfiguration , jobHostConfiguration ) ;
76+ Assert . True ( azureTableStorageProvider . TryCreateHostingTableServiceClient ( out _ ) ) ;
77+ }
78+
3679 [ Fact ]
3780 public void TryCreateHostingTableServiceClient_NoConnectionThrowsException ( )
3881 {
@@ -45,6 +88,36 @@ public void TryCreateHostingTableServiceClient_NoConnectionThrowsException()
4588 Assert . False ( azureTableStorageProvider . TryCreateTableServiceClient ( ConnectionStringNames . Storage , out TableServiceClient blobServiceClient ) ) ;
4689 }
4790
91+ [ Theory ]
92+ [ InlineData ( "ConnectionStrings:AzureWebJobsStorage1" ) ]
93+ [ InlineData ( "AzureWebJobsStorage1" ) ]
94+ [ InlineData ( "Storage1" ) ]
95+ public void TestAzureBlobStorageProvider_JobHostConfigurationWinsConflict ( string connectionName )
96+ {
97+ var bytes = Encoding . UTF8 . GetBytes ( "someKey" ) ;
98+ var encodedString = Convert . ToBase64String ( bytes ) ;
99+
100+ var webHostConfigData = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase )
101+ {
102+ { connectionName , $ "DefaultEndpointsProtocol=https;AccountName=webHostAccount;AccountKey={ encodedString } ;EndpointSuffix=core.windows.net" } ,
103+ } ;
104+ var webHostConfiguration = new ConfigurationBuilder ( )
105+ . AddInMemoryCollection ( webHostConfigData )
106+ . Build ( ) ;
107+
108+ var jobHostConfigData = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase )
109+ {
110+ { connectionName , $ "DefaultEndpointsProtocol=https;AccountName=jobHostAccount;AccountKey={ encodedString } ;EndpointSuffix=core.windows.net" } ,
111+ } ;
112+ var jobHostConfiguration = new ConfigurationBuilder ( )
113+ . AddInMemoryCollection ( jobHostConfigData )
114+ . Build ( ) ;
115+
116+ var azureTableStorageProvider = TestHelpers . GetAzureTableStorageProvider ( webHostConfiguration , jobHostConfiguration ) ;
117+ Assert . True ( azureTableStorageProvider . TryCreateTableServiceClient ( "Storage1" , out TableServiceClient client ) ) ;
118+ Assert . Equal ( "webHostAccount" , client . AccountName , ignoreCase : true ) ;
119+ }
120+
48121 private async Task VerifyTableServiceClientAvailable ( TableServiceClient client )
49122 {
50123 try
@@ -57,5 +130,32 @@ private async Task VerifyTableServiceClientAvailable(TableServiceClient client)
57130 Assert . False ( true , $ "Could not establish connection to TableService. { e } ") ;
58131 }
59132 }
133+
134+ private class CaseSensitiveConfigurationSource : IConfigurationSource
135+ {
136+ private readonly Dictionary < string , string > _data ;
137+ public CaseSensitiveConfigurationSource ( Dictionary < string , string > data )
138+ {
139+ _data = data ;
140+ }
141+ public IConfigurationProvider Build ( IConfigurationBuilder builder )
142+ {
143+ return new CaseSensitiveConfigurationProvider ( _data ) ;
144+ }
145+ }
146+
147+ private class CaseSensitiveConfigurationProvider : ConfigurationProvider
148+ {
149+ private readonly Dictionary < string , string > _data ;
150+ public CaseSensitiveConfigurationProvider ( Dictionary < string , string > data )
151+ {
152+ _data = data ;
153+ }
154+ public override void Load ( )
155+ {
156+ // _data might be already case-insensitive but we want to ensure it's case-sensitive
157+ Data = new Dictionary < string , string > ( _data , StringComparer . Ordinal ) ;
158+ }
159+ }
60160 }
61161}
0 commit comments