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
+
8
4
using System ;
9
5
using System . Collections . Generic ;
10
6
using System . Linq ;
11
7
using System . Net ;
12
8
using System . Net . Http ;
13
9
using System . Net . Http . Headers ;
14
10
using 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 ;
15
17
using Xunit ;
16
18
17
19
namespace Microsoft . Azure . WebJobs . Script . Tests . Integration . WebHostEndToEnd
@@ -68,7 +70,7 @@ public async Task InvokeFunction_FunctionLevel_ValidToken_Succeeds(string header
68
70
{
69
71
// if an admin token is passed, the function invocation succeeds
70
72
HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , "api/HttpTrigger-FunctionAuth?code=test" ) ;
71
- string token = _fixture . Host . GenerateAdminJwtToken ( ) ;
73
+ string token = GetSWAAdminJwtToken ( ) ;
72
74
73
75
if ( string . Compare ( nameof ( HttpRequestHeader . Authorization ) , headerName ) == 0 )
74
76
{
@@ -83,6 +85,16 @@ public async Task InvokeFunction_FunctionLevel_ValidToken_Succeeds(string header
83
85
response . EnsureSuccessStatusCode ( ) ;
84
86
}
85
87
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
+
86
98
[ Fact ]
87
99
public async Task SyncTriggers_Succeeds ( )
88
100
{
@@ -109,19 +121,28 @@ public class TestFixture : EndToEndTestFixture
109
121
110
122
public TestFixture ( ) : base ( @"TestScripts\CSharp" , "csharp" , RpcWorkerConstants . DotNetLanguageWorkerName , addTestSettings : false )
111
123
{
124
+ // SWA generates their own key and sets via AzureWebEncryptionKey
125
+ // This should take precedence over the default key
112
126
var testKeyBytes = TestHelpers . GenerateKeyBytes ( ) ;
113
127
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 ) ;
114
133
115
134
var settings = new Dictionary < string , string > ( )
116
135
{
117
136
{ "AzureWebEncryptionKey" , testKey } ,
118
- { EnvironmentSettingNames . WebSiteAuthEncryptionKey , testKey } ,
137
+ { EnvironmentSettingNames . WebSiteAuthEncryptionKey , defaultTestKey } ,
119
138
{ "AzureWebJobsStorage" , null } ,
120
139
{ EnvironmentSettingNames . AzureWebsiteName , "testsite" }
121
140
} ;
122
141
_scopedEnvironment = new TestScopedEnvironmentVariable ( settings ) ;
123
142
}
124
143
144
+ public string SWAEncryptionKey { get ; }
145
+
125
146
public override void ConfigureScriptHost ( IWebJobsBuilder webJobsBuilder )
126
147
{
127
148
base . ConfigureScriptHost ( webJobsBuilder ) ;
0 commit comments