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