1- using Microsoft . Azure . WebJobs . Script . WebHost ;
2- using Microsoft . Azure . WebJobs . Script . WebHost . Management ;
3- using Microsoft . Azure . WebJobs . Script . WebHost . Security ;
4- using Microsoft . Azure . WebJobs . Script . Workers . Rpc ;
5- using Microsoft . Extensions . DependencyInjection ;
6- using Microsoft . Extensions . DependencyInjection . Extensions ;
7- using Newtonsoft . Json ;
1+ // Copyright (c) .NET Foundation. All rights reserved.
2+ // Licensed under the MIT License. See License.txt in the project root for license information.
3+
84using System ;
95using System . Collections . Generic ;
106using System . Linq ;
117using System . Net ;
128using System . Net . Http ;
139using System . Net . Http . Headers ;
1410using System . Threading . Tasks ;
11+ using Microsoft . Azure . WebJobs . Script . WebHost ;
12+ using Microsoft . Azure . WebJobs . Script . WebHost . Management ;
13+ using Microsoft . Azure . WebJobs . Script . Workers . Rpc ;
14+ using Microsoft . Extensions . DependencyInjection ;
15+ using Microsoft . Extensions . DependencyInjection . Extensions ;
16+ using Newtonsoft . Json ;
1517using Xunit ;
1618
1719namespace Microsoft . Azure . WebJobs . Script . Tests . Integration . WebHostEndToEnd
@@ -68,7 +70,7 @@ public async Task InvokeFunction_FunctionLevel_ValidToken_Succeeds(string header
6870 {
6971 // if an admin token is passed, the function invocation succeeds
7072 HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , "api/HttpTrigger-FunctionAuth?code=test" ) ;
71- string token = _fixture . Host . GenerateAdminJwtToken ( ) ;
73+ string token = GetSWAAdminJwtToken ( ) ;
7274
7375 if ( string . Compare ( nameof ( HttpRequestHeader . Authorization ) , headerName ) == 0 )
7476 {
@@ -83,6 +85,16 @@ public async Task InvokeFunction_FunctionLevel_ValidToken_Succeeds(string header
8385 response . EnsureSuccessStatusCode ( ) ;
8486 }
8587
88+ private string GetSWAAdminJwtToken ( )
89+ {
90+ // Ensure we use AzureWebEncryptionKey to generate tokens, as that's what SWA does
91+ string keyValue = _fixture . SWAEncryptionKey ;
92+ byte [ ] keyBytes = keyValue . ToKeyBytes ( ) ;
93+ string token = _fixture . Host . GenerateAdminJwtToken ( key : keyBytes ) ;
94+
95+ return token ;
96+ }
97+
8698 [ Fact ]
8799 public async Task SyncTriggers_Succeeds ( )
88100 {
@@ -109,19 +121,28 @@ public class TestFixture : EndToEndTestFixture
109121
110122 public TestFixture ( ) : base ( @"TestScripts\CSharp" , "csharp" , RpcWorkerConstants . DotNetLanguageWorkerName , addTestSettings : false )
111123 {
124+ // SWA generates their own key and sets via AzureWebEncryptionKey
125+ // This should take precedence over the default key
112126 var testKeyBytes = TestHelpers . GenerateKeyBytes ( ) ;
113127 var testKey = TestHelpers . GenerateKeyHexString ( testKeyBytes ) ;
128+ SWAEncryptionKey = testKey ;
129+
130+ // Default key provisioned by Antares and available via WEBSITE_AUTH_ENCRYPTION_KEY
131+ var defaultTestKeyBytes = TestHelpers . GenerateKeyBytes ( ) ;
132+ var defaultTestKey = TestHelpers . GenerateKeyHexString ( defaultTestKeyBytes ) ;
114133
115134 var settings = new Dictionary < string , string > ( )
116135 {
117136 { "AzureWebEncryptionKey" , testKey } ,
118- { EnvironmentSettingNames . WebSiteAuthEncryptionKey , testKey } ,
137+ { EnvironmentSettingNames . WebSiteAuthEncryptionKey , defaultTestKey } ,
119138 { "AzureWebJobsStorage" , null } ,
120139 { EnvironmentSettingNames . AzureWebsiteName , "testsite" }
121140 } ;
122141 _scopedEnvironment = new TestScopedEnvironmentVariable ( settings ) ;
123142 }
124143
144+ public string SWAEncryptionKey { get ; }
145+
125146 public override void ConfigureScriptHost ( IWebJobsBuilder webJobsBuilder )
126147 {
127148 base . ConfigureScriptHost ( webJobsBuilder ) ;
0 commit comments