@@ -21,13 +21,15 @@ public class AuthorisationTests : IDisposable
21
21
private IWebHost _identityServerBuilder ;
22
22
private readonly Steps _steps ;
23
23
private readonly Action < IdentityServerAuthenticationOptions > _options ;
24
- private string _identityServerRootUrl = "http://localhost:51888" ;
24
+ private string _identityServerRootUrl ;
25
25
private readonly ServiceHandler _serviceHandler ;
26
26
27
27
public AuthorisationTests ( )
28
28
{
29
29
_serviceHandler = new ServiceHandler ( ) ;
30
- _steps = new Steps ( ) ;
30
+ _steps = new Steps ( ) ;
31
+ var identityServerPort = RandomPortFinder . GetRandomPort ( ) ;
32
+ _identityServerRootUrl = $ "http://localhost:{ identityServerPort } ";
31
33
_options = o =>
32
34
{
33
35
o . Authority = _identityServerRootUrl ;
@@ -41,7 +43,7 @@ public AuthorisationTests()
41
43
[ Fact ]
42
44
public void should_return_response_200_authorising_route ( )
43
45
{
44
- int port = 52875 ;
46
+ int port = RandomPortFinder . GetRandomPort ( ) ;
45
47
46
48
var configuration = new FileConfiguration
47
49
{
@@ -86,9 +88,9 @@ public void should_return_response_200_authorising_route()
86
88
}
87
89
} ;
88
90
89
- this . Given ( x => x . GivenThereIsAnIdentityServerOn ( "http://localhost:51888" , "api" , AccessTokenType . Jwt ) )
91
+ this . Given ( x => x . GivenThereIsAnIdentityServerOn ( _identityServerRootUrl , "api" , AccessTokenType . Jwt ) )
90
92
. And ( x => x . GivenThereIsAServiceRunningOn ( $ "http://localhost:{ port } ", 200 , "Hello from Laura" ) )
91
- . And ( x => _steps . GivenIHaveAToken ( "http://localhost:51888" ) )
93
+ . And ( x => _steps . GivenIHaveAToken ( _identityServerRootUrl ) )
92
94
. And ( x => _steps . GivenThereIsAConfiguration ( configuration ) )
93
95
. And ( x => _steps . GivenOcelotIsRunning ( _options , "Test" ) )
94
96
. And ( x => _steps . GivenIHaveAddedATokenToMyRequest ( ) )
@@ -101,7 +103,7 @@ public void should_return_response_200_authorising_route()
101
103
[ Fact ]
102
104
public void should_return_response_403_authorising_route ( )
103
105
{
104
- int port = 59471 ;
106
+ int port = RandomPortFinder . GetRandomPort ( ) ;
105
107
106
108
var configuration = new FileConfiguration
107
109
{
@@ -145,9 +147,9 @@ public void should_return_response_403_authorising_route()
145
147
}
146
148
} ;
147
149
148
- this . Given ( x => x . GivenThereIsAnIdentityServerOn ( "http://localhost:51888" , "api" , AccessTokenType . Jwt ) )
150
+ this . Given ( x => x . GivenThereIsAnIdentityServerOn ( _identityServerRootUrl , "api" , AccessTokenType . Jwt ) )
149
151
. And ( x => x . GivenThereIsAServiceRunningOn ( $ "http://localhost:{ port } ", 200 , "Hello from Laura" ) )
150
- . And ( x => _steps . GivenIHaveAToken ( "http://localhost:51888" ) )
152
+ . And ( x => _steps . GivenIHaveAToken ( _identityServerRootUrl ) )
151
153
. And ( x => _steps . GivenThereIsAConfiguration ( configuration ) )
152
154
. And ( x => _steps . GivenOcelotIsRunning ( _options , "Test" ) )
153
155
. And ( x => _steps . GivenIHaveAddedATokenToMyRequest ( ) )
@@ -159,7 +161,7 @@ public void should_return_response_403_authorising_route()
159
161
[ Fact ]
160
162
public void should_return_response_200_using_identity_server_with_allowed_scope ( )
161
163
{
162
- int port = 63471 ;
164
+ int port = RandomPortFinder . GetRandomPort ( ) ;
163
165
164
166
var configuration = new FileConfiguration
165
167
{
@@ -188,9 +190,9 @@ public void should_return_response_200_using_identity_server_with_allowed_scope(
188
190
}
189
191
} ;
190
192
191
- this . Given ( x => x . GivenThereIsAnIdentityServerOn ( "http://localhost:51888" , "api" , AccessTokenType . Jwt ) )
193
+ this . Given ( x => x . GivenThereIsAnIdentityServerOn ( _identityServerRootUrl , "api" , AccessTokenType . Jwt ) )
192
194
. And ( x => x . GivenThereIsAServiceRunningOn ( $ "http://localhost:{ port } ", 200 , "Hello from Laura" ) )
193
- . And ( x => _steps . GivenIHaveATokenForApiReadOnlyScope ( "http://localhost:51888" ) )
195
+ . And ( x => _steps . GivenIHaveATokenForApiReadOnlyScope ( _identityServerRootUrl ) )
194
196
. And ( x => _steps . GivenThereIsAConfiguration ( configuration ) )
195
197
. And ( x => _steps . GivenOcelotIsRunning ( _options , "Test" ) )
196
198
. And ( x => _steps . GivenIHaveAddedATokenToMyRequest ( ) )
@@ -202,7 +204,7 @@ public void should_return_response_200_using_identity_server_with_allowed_scope(
202
204
[ Fact ]
203
205
public void should_return_response_403_using_identity_server_with_scope_not_allowed ( )
204
206
{
205
- int port = 60571 ;
207
+ int port = RandomPortFinder . GetRandomPort ( ) ;
206
208
207
209
var configuration = new FileConfiguration
208
210
{
@@ -231,9 +233,9 @@ public void should_return_response_403_using_identity_server_with_scope_not_allo
231
233
}
232
234
} ;
233
235
234
- this . Given ( x => x . GivenThereIsAnIdentityServerOn ( "http://localhost:51888" , "api" , AccessTokenType . Jwt ) )
236
+ this . Given ( x => x . GivenThereIsAnIdentityServerOn ( _identityServerRootUrl , "api" , AccessTokenType . Jwt ) )
235
237
. And ( x => x . GivenThereIsAServiceRunningOn ( $ "http://localhost:{ port } ", 200 , "Hello from Laura" ) )
236
- . And ( x => _steps . GivenIHaveATokenForApiReadOnlyScope ( "http://localhost:51888" ) )
238
+ . And ( x => _steps . GivenIHaveATokenForApiReadOnlyScope ( _identityServerRootUrl ) )
237
239
. And ( x => _steps . GivenThereIsAConfiguration ( configuration ) )
238
240
. And ( x => _steps . GivenOcelotIsRunning ( _options , "Test" ) )
239
241
. And ( x => _steps . GivenIHaveAddedATokenToMyRequest ( ) )
@@ -245,7 +247,7 @@ public void should_return_response_403_using_identity_server_with_scope_not_allo
245
247
[ Fact ]
246
248
public void should_fix_issue_240 ( )
247
249
{
248
- int port = 61071 ;
250
+ int port = RandomPortFinder . GetRandomPort ( ) ;
249
251
250
252
var configuration = new FileConfiguration
251
253
{
@@ -292,9 +294,9 @@ public void should_fix_issue_240()
292
294
}
293
295
} ;
294
296
295
- this . Given ( x => x . GivenThereIsAnIdentityServerOn ( "http://localhost:51888" , "api" , AccessTokenType . Jwt , users ) )
297
+ this . Given ( x => x . GivenThereIsAnIdentityServerOn ( _identityServerRootUrl , "api" , AccessTokenType . Jwt , users ) )
296
298
. And ( x => x . GivenThereIsAServiceRunningOn ( $ "http://localhost:{ port } ", 200 , "Hello from Laura" ) )
297
- . And ( x => _steps . GivenIHaveAToken ( "http://localhost:51888" ) )
299
+ . And ( x => _steps . GivenIHaveAToken ( _identityServerRootUrl ) )
298
300
. And ( x => _steps . GivenThereIsAConfiguration ( configuration ) )
299
301
. And ( x => _steps . GivenOcelotIsRunning ( _options , "Test" ) )
300
302
. And ( x => _steps . GivenIHaveAddedATokenToMyRequest ( ) )
0 commit comments