@@ -29,7 +29,8 @@ public SecretsRepositoryTests(SecretsRepositoryTests.Fixture fixture)
29
29
public enum SecretsRepositoryType
30
30
{
31
31
FileSystem ,
32
- BlobStorage
32
+ BlobStorage ,
33
+ BlobStorageSas
33
34
}
34
35
35
36
[ Fact ]
@@ -38,10 +39,12 @@ public void FileSystemRepo_Constructor_CreatesSecretPathIfNotExists()
38
39
Constructor_CreatesSecretPathIfNotExists ( SecretsRepositoryType . FileSystem ) ;
39
40
}
40
41
41
- [ Fact ]
42
- public void BlobStorageRepo_Constructor_CreatesSecretPathIfNotExists ( )
42
+ [ Theory ]
43
+ [ InlineData ( SecretsRepositoryType . BlobStorage ) ]
44
+ [ InlineData ( SecretsRepositoryType . BlobStorageSas ) ]
45
+ public void BlobStorageRepo_Constructor_CreatesSecretPathIfNotExists ( SecretsRepositoryType repositoryType )
43
46
{
44
- Constructor_CreatesSecretPathIfNotExists ( SecretsRepositoryType . BlobStorage ) ;
47
+ Constructor_CreatesSecretPathIfNotExists ( repositoryType ) ;
45
48
}
46
49
47
50
private void Constructor_CreatesSecretPathIfNotExists ( SecretsRepositoryType repositoryType )
@@ -67,11 +70,13 @@ private void Constructor_CreatesSecretPathIfNotExists(SecretsRepositoryType repo
67
70
}
68
71
69
72
[ Theory ]
70
- [ InlineData ( ScriptSecretsType . Host ) ]
71
- [ InlineData ( ScriptSecretsType . Function ) ]
72
- public async Task BlobStorageRepo_ReadAsync_ReadsExpectedFile ( ScriptSecretsType secretsType )
73
+ [ InlineData ( SecretsRepositoryType . BlobStorage , ScriptSecretsType . Host ) ]
74
+ [ InlineData ( SecretsRepositoryType . BlobStorage , ScriptSecretsType . Function ) ]
75
+ [ InlineData ( SecretsRepositoryType . BlobStorageSas , ScriptSecretsType . Host ) ]
76
+ [ InlineData ( SecretsRepositoryType . BlobStorageSas , ScriptSecretsType . Function ) ]
77
+ public async Task BlobStorageRepo_ReadAsync_ReadsExpectedFile ( SecretsRepositoryType repositoryType , ScriptSecretsType secretsType )
73
78
{
74
- await ReadAsync_ReadsExpectedFile ( SecretsRepositoryType . BlobStorage , secretsType ) ;
79
+ await ReadAsync_ReadsExpectedFile ( repositoryType , secretsType ) ;
75
80
}
76
81
77
82
[ Theory ]
@@ -101,11 +106,13 @@ private async Task ReadAsync_ReadsExpectedFile(SecretsRepositoryType repositoryT
101
106
}
102
107
103
108
[ Theory ]
104
- [ InlineData ( ScriptSecretsType . Host ) ]
105
- [ InlineData ( ScriptSecretsType . Function ) ]
106
- public async Task BlobStorageRepo_WriteAsync_CreatesExpectedFile ( ScriptSecretsType secretsType )
109
+ [ InlineData ( SecretsRepositoryType . BlobStorage , ScriptSecretsType . Host ) ]
110
+ [ InlineData ( SecretsRepositoryType . BlobStorage , ScriptSecretsType . Function ) ]
111
+ [ InlineData ( SecretsRepositoryType . BlobStorageSas , ScriptSecretsType . Host ) ]
112
+ [ InlineData ( SecretsRepositoryType . BlobStorageSas , ScriptSecretsType . Function ) ]
113
+ public async Task BlobStorageRepo_WriteAsync_CreatesExpectedFile ( SecretsRepositoryType repositoryType , ScriptSecretsType secretsType )
107
114
{
108
- await WriteAsync_CreatesExpectedFile ( SecretsRepositoryType . BlobStorage , secretsType ) ;
115
+ await WriteAsync_CreatesExpectedFile ( repositoryType , secretsType ) ;
109
116
}
110
117
111
118
[ Theory ]
@@ -129,7 +136,7 @@ private async Task WriteAsync_CreatesExpectedFile(SecretsRepositoryType reposito
129
136
130
137
string filePath = Path . Combine ( directory . Path , $ "{ testFunctionName ?? "host" } .json") ;
131
138
132
- if ( repositoryType == SecretsRepositoryType . BlobStorage )
139
+ if ( repositoryType == SecretsRepositoryType . BlobStorage || repositoryType == SecretsRepositoryType . BlobStorageSas )
133
140
{
134
141
Assert . True ( _fixture . MarkerFileExists ( testFunctionName ?? "host" ) ) ;
135
142
}
@@ -143,10 +150,12 @@ public async Task FileSystemRepo_WriteAsync_ChangeNotificationUpdatesExistingSec
143
150
await WriteAsync_ChangeNotificationUpdatesExistingSecret ( SecretsRepositoryType . FileSystem ) ;
144
151
}
145
152
146
- [ Fact ]
147
- public async Task BlobStorageRepo_WriteAsync_ChangeNotificationUpdatesExistingSecret ( )
153
+ [ Theory ]
154
+ [ InlineData ( SecretsRepositoryType . BlobStorage ) ]
155
+ [ InlineData ( SecretsRepositoryType . BlobStorageSas ) ]
156
+ public async Task BlobStorageRepo_WriteAsync_ChangeNotificationUpdatesExistingSecret ( SecretsRepositoryType repositoryType )
148
157
{
149
- await WriteAsync_ChangeNotificationUpdatesExistingSecret ( SecretsRepositoryType . BlobStorage ) ;
158
+ await WriteAsync_ChangeNotificationUpdatesExistingSecret ( repositoryType ) ;
150
159
}
151
160
152
161
private async Task WriteAsync_ChangeNotificationUpdatesExistingSecret ( SecretsRepositoryType repositoryType )
@@ -202,6 +211,8 @@ public async Task FileSystemRepo_PurgeOldSecrets_RemovesOldAndKeepsCurrentSecret
202
211
[ InlineData ( SecretsRepositoryType . FileSystem , ScriptSecretsType . Function ) ]
203
212
[ InlineData ( SecretsRepositoryType . BlobStorage , ScriptSecretsType . Host ) ]
204
213
[ InlineData ( SecretsRepositoryType . BlobStorage , ScriptSecretsType . Function ) ]
214
+ [ InlineData ( SecretsRepositoryType . BlobStorageSas , ScriptSecretsType . Host ) ]
215
+ [ InlineData ( SecretsRepositoryType . BlobStorageSas , ScriptSecretsType . Function ) ]
205
216
public async Task GetSecretSnapshots_ReturnsExpected ( SecretsRepositoryType repositoryType , ScriptSecretsType secretsType )
206
217
{
207
218
using ( var directory = new TempDirectory ( ) )
@@ -229,7 +240,6 @@ public Fixture()
229
240
{
230
241
TestSiteName = "TestSiteName" ;
231
242
BlobConnectionString = AmbientConnectionStringProvider . Instance . GetConnectionString ( ConnectionStringNames . Storage ) ;
232
- BlobContainer = CloudStorageAccount . Parse ( BlobConnectionString ) . CreateCloudBlobClient ( ) . GetContainerReference ( "azure-webjobs-secrets" ) ;
233
243
}
234
244
235
245
public string TestSiteName { get ; private set ; }
@@ -238,6 +248,8 @@ public Fixture()
238
248
239
249
public string BlobConnectionString { get ; private set ; }
240
250
251
+ public Uri BlobSasConnectionUri { get ; private set ; }
252
+
241
253
public CloudBlobContainer BlobContainer { get ; private set ; }
242
254
243
255
public SecretsRepositoryType RepositoryType { get ; private set ; }
@@ -251,6 +263,16 @@ public void TestInitialize(SecretsRepositoryType repositoryType, string secretsD
251
263
TestSiteName = testSiteName ;
252
264
}
253
265
266
+ if ( RepositoryType == SecretsRepositoryType . BlobStorageSas )
267
+ {
268
+ BlobSasConnectionUri = TestHelpers . CreateBlobContainerSas ( BlobConnectionString , "azure-webjobs-secrets-sas" ) ;
269
+ BlobContainer = new CloudBlobContainer ( BlobSasConnectionUri ) ;
270
+ }
271
+ else
272
+ {
273
+ BlobContainer = CloudStorageAccount . Parse ( BlobConnectionString ) . CreateCloudBlobClient ( ) . GetContainerReference ( "azure-webjobs-secrets" ) ;
274
+ }
275
+
254
276
ClearAllBlobSecrets ( ) ;
255
277
ClearAllFileSecrets ( ) ;
256
278
}
@@ -261,6 +283,10 @@ public ISecretsRepository GetNewSecretRepository()
261
283
{
262
284
return new BlobStorageSecretsRepository ( SecretsDirectory , BlobConnectionString , TestSiteName ) ;
263
285
}
286
+ else if ( RepositoryType == SecretsRepositoryType . BlobStorageSas )
287
+ {
288
+ return new BlobStorageSasSecretsRepository ( SecretsDirectory , BlobSasConnectionUri . ToString ( ) , TestSiteName ) ;
289
+ }
264
290
return new FileSystemSecretsRepository ( SecretsDirectory ) ;
265
291
}
266
292
@@ -299,6 +325,7 @@ public void WriteSecret(string functionNameOrHost, string fileText)
299
325
WriteSecretsToFile ( functionNameOrHost , fileText ) ;
300
326
break ;
301
327
case SecretsRepositoryType . BlobStorage :
328
+ case SecretsRepositoryType . BlobStorageSas :
302
329
WriteSecretsBlobAndUpdateSentinelFile ( functionNameOrHost , fileText ) ;
303
330
break ;
304
331
default :
@@ -336,6 +363,7 @@ public string GetSecretText(string functionNameOrHost)
336
363
secretText = File . ReadAllText ( SecretsFileOrSentinelPath ( functionNameOrHost ) ) ;
337
364
break ;
338
365
case SecretsRepositoryType . BlobStorage :
366
+ case SecretsRepositoryType . BlobStorageSas :
339
367
secretText = GetSecretBlobText ( functionNameOrHost ) ;
340
368
break ;
341
369
default :
@@ -374,7 +402,13 @@ private void ClearAllFileSecrets()
374
402
375
403
private void ClearAllBlobSecrets ( )
376
404
{
377
- BlobContainer . CreateIfNotExists ( ) ;
405
+ // A sas connection requires the container to already exist, it
406
+ // doesn't have permission to create it
407
+ if ( RepositoryType != SecretsRepositoryType . BlobStorageSas )
408
+ {
409
+ BlobContainer . CreateIfNotExists ( ) ;
410
+ }
411
+
378
412
var blobs = BlobContainer . ListBlobs ( prefix : TestSiteName . ToLowerInvariant ( ) , useFlatBlobListing : true ) ;
379
413
foreach ( IListBlobItem blob in blobs )
380
414
{
0 commit comments