@@ -19,15 +19,19 @@ namespace Ocelot.IntegrationTests
19
19
public class AdministrationTests : IDisposable
20
20
{
21
21
private readonly HttpClient _httpClient ;
22
+ private readonly HttpClient _httpClientTwo ;
22
23
private HttpResponseMessage _response ;
23
24
private IWebHost _builder ;
24
25
private IWebHostBuilder _webHostBuilder ;
25
26
private readonly string _ocelotBaseUrl ;
26
27
private BearerToken _token ;
28
+ private IWebHostBuilder _webHostBuilderTwo ;
29
+ private IWebHost _builderTwo ;
27
30
28
31
public AdministrationTests ( )
29
32
{
30
33
_httpClient = new HttpClient ( ) ;
34
+ _httpClientTwo = new HttpClient ( ) ;
31
35
_ocelotBaseUrl = "http://localhost:5000" ;
32
36
_httpClient . BaseAddress = new Uri ( _ocelotBaseUrl ) ;
33
37
}
@@ -70,6 +74,27 @@ public void should_return_response_200_with_call_re_routes_controller()
70
74
. BDDfy ( ) ;
71
75
}
72
76
77
+ [ Fact ]
78
+ public void should_be_able_to_use_token_from_ocelot_a_on_ocelot_b ( )
79
+ {
80
+ var configuration = new FileConfiguration
81
+ {
82
+ GlobalConfiguration = new FileGlobalConfiguration
83
+ {
84
+ AdministrationPath = "/administration"
85
+ }
86
+ } ;
87
+
88
+ this . Given ( x => GivenThereIsAConfiguration ( configuration ) )
89
+ . And ( x => GivenIdentityServerSigningEnvironmentalVariablesAreSet ( ) )
90
+ . And ( x => GivenOcelotIsRunning ( ) )
91
+ . And ( x => GivenIHaveAnOcelotToken ( "/administration" ) )
92
+ . And ( x => GivenAnotherOcelotIsRunning ( "http://localhost:5007" ) )
93
+ . When ( x => WhenIGetUrlOnTheSecondOcelot ( "/administration/configuration" ) )
94
+ . Then ( x => ThenTheStatusCodeShouldBe ( HttpStatusCode . OK ) )
95
+ . BDDfy ( ) ;
96
+ }
97
+
73
98
[ Fact ]
74
99
public void should_return_file_configuration ( )
75
100
{
@@ -193,6 +218,36 @@ public void should_get_file_configuration_edit_and_post_updated_version()
193
218
. BDDfy ( ) ;
194
219
}
195
220
221
+ private void GivenAnotherOcelotIsRunning ( string baseUrl )
222
+ {
223
+ _httpClientTwo . BaseAddress = new Uri ( baseUrl ) ;
224
+
225
+ _webHostBuilderTwo = new WebHostBuilder ( )
226
+ . UseUrls ( baseUrl )
227
+ . UseKestrel ( )
228
+ . UseContentRoot ( Directory . GetCurrentDirectory ( ) )
229
+ . ConfigureServices ( x => {
230
+ x . AddSingleton ( _webHostBuilderTwo ) ;
231
+ } )
232
+ . UseStartup < Startup > ( ) ;
233
+
234
+ _builderTwo = _webHostBuilderTwo . Build ( ) ;
235
+
236
+ _builderTwo . Start ( ) ;
237
+ }
238
+
239
+ private void GivenIdentityServerSigningEnvironmentalVariablesAreSet ( )
240
+ {
241
+ Environment . SetEnvironmentVariable ( "OCELOT_CERTIFICATE" , "idsrv3test.pfx" ) ;
242
+ Environment . SetEnvironmentVariable ( "OCELOT_CERTIFICATE_PASSWORD" , "idsrv3test" ) ;
243
+ }
244
+
245
+ private void WhenIGetUrlOnTheSecondOcelot ( string url )
246
+ {
247
+ _httpClientTwo . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , _token . AccessToken ) ;
248
+ _response = _httpClientTwo . GetAsync ( url ) . Result ;
249
+ }
250
+
196
251
private void WhenIPostOnTheApiGateway ( string url , FileConfiguration updatedConfiguration )
197
252
{
198
253
var json = JsonConvert . SerializeObject ( updatedConfiguration ) ;
@@ -305,6 +360,8 @@ private void ThenTheStatusCodeShouldBe(HttpStatusCode expectedHttpStatusCode)
305
360
306
361
public void Dispose ( )
307
362
{
363
+ Environment . SetEnvironmentVariable ( "OCELOT_CERTIFICATE" , "" ) ;
364
+ Environment . SetEnvironmentVariable ( "OCELOT_CERTIFICATE_PASSWORD" , "" ) ;
308
365
_builder ? . Dispose ( ) ;
309
366
_httpClient ? . Dispose ( ) ;
310
367
}
0 commit comments