@@ -36,6 +36,12 @@ public Task StartThrowsFormatExceptionIfNegotiationResponseHasNoConnectionId()
36
36
return RunInvalidNegotiateResponseTest < FormatException > ( ResponseUtils . CreateNegotiationContent ( connectionId : string . Empty ) , "Invalid connection id." ) ;
37
37
}
38
38
39
+ [ Fact ]
40
+ public Task NegotiateResponseWithNegotiateVersionRequiresConnectionToken ( )
41
+ {
42
+ return RunInvalidNegotiateResponseTest < InvalidDataException > ( ResponseUtils . CreateNegotiationContent ( negotiateVersion : 1 , connectionToken : null ) , "Invalid negotiation response received." ) ;
43
+ }
44
+
39
45
[ Fact ]
40
46
public Task ConnectionCannotBeStartedIfNoCommonTransportsBetweenClientAndServer ( )
41
47
{
@@ -50,12 +56,12 @@ public Task ConnectionCannotBeStartedIfNoTransportProvidedByServer()
50
56
}
51
57
52
58
[ Theory ]
53
- [ InlineData ( "http://fakeuri.org/" , "http://fakeuri.org/negotiate" ) ]
54
- [ InlineData ( "http://fakeuri.org/?q=1/0" , "http://fakeuri.org/negotiate?q=1/0" ) ]
55
- [ InlineData ( "http://fakeuri.org?q=1/0" , "http://fakeuri.org/negotiate?q=1/0" ) ]
56
- [ InlineData ( "http://fakeuri.org/endpoint" , "http://fakeuri.org/endpoint/negotiate" ) ]
57
- [ InlineData ( "http://fakeuri.org/endpoint/" , "http://fakeuri.org/endpoint/negotiate" ) ]
58
- [ InlineData ( "http://fakeuri.org/endpoint?q=1/0" , "http://fakeuri.org/endpoint/negotiate?q=1/0" ) ]
59
+ [ InlineData ( "http://fakeuri.org/" , "http://fakeuri.org/negotiate?negotiateVersion=1 " ) ]
60
+ [ InlineData ( "http://fakeuri.org/?q=1/0" , "http://fakeuri.org/negotiate?q=1/0&negotiateVersion=1 " ) ]
61
+ [ InlineData ( "http://fakeuri.org?q=1/0" , "http://fakeuri.org/negotiate?q=1/0&negotiateVersion=1 " ) ]
62
+ [ InlineData ( "http://fakeuri.org/endpoint" , "http://fakeuri.org/endpoint/negotiate?negotiateVersion=1 " ) ]
63
+ [ InlineData ( "http://fakeuri.org/endpoint/" , "http://fakeuri.org/endpoint/negotiate?negotiateVersion=1 " ) ]
64
+ [ InlineData ( "http://fakeuri.org/endpoint?q=1/0" , "http://fakeuri.org/endpoint/negotiate?q=1/0&negotiateVersion=1 " ) ]
59
65
public async Task CorrectlyHandlesQueryStringWhenAppendingNegotiateToUrl ( string requestedUrl , string expectedNegotiate )
60
66
{
61
67
var testHttpHandler = new TestHttpMessageHandler ( autoNegotiate : false ) ;
@@ -119,6 +125,124 @@ await WithConnectionAsync(
119
125
Assert . Equal ( "0rge0d00-0040-0030-0r00-000q00r00e00" , connectionId ) ;
120
126
}
121
127
128
+ [ Fact ]
129
+ public async Task NegotiateCanHaveNewFields ( )
130
+ {
131
+ string connectionId = null ;
132
+
133
+ var testHttpHandler = new TestHttpMessageHandler ( autoNegotiate : false ) ;
134
+ testHttpHandler . OnNegotiate ( ( request , cancellationToken ) => ResponseUtils . CreateResponse ( HttpStatusCode . OK ,
135
+ JsonConvert . SerializeObject ( new
136
+ {
137
+ connectionId = "0rge0d00-0040-0030-0r00-000q00r00e00" ,
138
+ availableTransports = new object [ ]
139
+ {
140
+ new
141
+ {
142
+ transport = "LongPolling" ,
143
+ transferFormats = new [ ] { "Text" }
144
+ } ,
145
+ } ,
146
+ newField = "ignore this" ,
147
+ } ) ) ) ;
148
+ testHttpHandler . OnLongPoll ( cancellationToken => ResponseUtils . CreateResponse ( HttpStatusCode . NoContent ) ) ;
149
+ testHttpHandler . OnLongPollDelete ( ( token ) => ResponseUtils . CreateResponse ( HttpStatusCode . Accepted ) ) ;
150
+
151
+ using ( var noErrorScope = new VerifyNoErrorsScope ( ) )
152
+ {
153
+ await WithConnectionAsync (
154
+ CreateConnection ( testHttpHandler , loggerFactory : noErrorScope . LoggerFactory ) ,
155
+ async ( connection ) =>
156
+ {
157
+ await connection . StartAsync ( ) . OrTimeout ( ) ;
158
+ connectionId = connection . ConnectionId ;
159
+ } ) ;
160
+ }
161
+
162
+ Assert . Equal ( "0rge0d00-0040-0030-0r00-000q00r00e00" , connectionId ) ;
163
+ }
164
+
165
+ [ Fact ]
166
+ public async Task ConnectionIdGetsSetWithNegotiateProtocolGreaterThanZero ( )
167
+ {
168
+ string connectionId = null ;
169
+
170
+ var testHttpHandler = new TestHttpMessageHandler ( autoNegotiate : false ) ;
171
+ testHttpHandler . OnNegotiate ( ( request , cancellationToken ) => ResponseUtils . CreateResponse ( HttpStatusCode . OK ,
172
+ JsonConvert . SerializeObject ( new
173
+ {
174
+ connectionId = "0rge0d00-0040-0030-0r00-000q00r00e00" ,
175
+ negotiateVersion = 1 ,
176
+ connectionToken = "different-id" ,
177
+ availableTransports = new object [ ]
178
+ {
179
+ new
180
+ {
181
+ transport = "LongPolling" ,
182
+ transferFormats = new [ ] { "Text" }
183
+ } ,
184
+ } ,
185
+ newField = "ignore this" ,
186
+ } ) ) ) ;
187
+ testHttpHandler . OnLongPoll ( cancellationToken => ResponseUtils . CreateResponse ( HttpStatusCode . NoContent ) ) ;
188
+ testHttpHandler . OnLongPollDelete ( ( token ) => ResponseUtils . CreateResponse ( HttpStatusCode . Accepted ) ) ;
189
+
190
+ using ( var noErrorScope = new VerifyNoErrorsScope ( ) )
191
+ {
192
+ await WithConnectionAsync (
193
+ CreateConnection ( testHttpHandler , loggerFactory : noErrorScope . LoggerFactory ) ,
194
+ async ( connection ) =>
195
+ {
196
+ await connection . StartAsync ( ) . OrTimeout ( ) ;
197
+ connectionId = connection . ConnectionId ;
198
+ } ) ;
199
+ }
200
+
201
+ Assert . Equal ( "0rge0d00-0040-0030-0r00-000q00r00e00" , connectionId ) ;
202
+ Assert . Equal ( "http://fakeuri.org/negotiate?negotiateVersion=1" , testHttpHandler . ReceivedRequests [ 0 ] . RequestUri . ToString ( ) ) ;
203
+ Assert . Equal ( "http://fakeuri.org/?id=different-id" , testHttpHandler . ReceivedRequests [ 1 ] . RequestUri . ToString ( ) ) ;
204
+ }
205
+
206
+ [ Fact ]
207
+ public async Task ConnectionTokenFieldIsIgnoredForNegotiateIdLessThanOne ( )
208
+ {
209
+ string connectionId = null ;
210
+
211
+ var testHttpHandler = new TestHttpMessageHandler ( autoNegotiate : false ) ;
212
+ testHttpHandler . OnNegotiate ( ( request , cancellationToken ) => ResponseUtils . CreateResponse ( HttpStatusCode . OK ,
213
+ JsonConvert . SerializeObject ( new
214
+ {
215
+ connectionId = "0rge0d00-0040-0030-0r00-000q00r00e00" ,
216
+ connectionToken = "different-id" ,
217
+ availableTransports = new object [ ]
218
+ {
219
+ new
220
+ {
221
+ transport = "LongPolling" ,
222
+ transferFormats = new [ ] { "Text" }
223
+ } ,
224
+ } ,
225
+ newField = "ignore this" ,
226
+ } ) ) ) ;
227
+ testHttpHandler . OnLongPoll ( cancellationToken => ResponseUtils . CreateResponse ( HttpStatusCode . NoContent ) ) ;
228
+ testHttpHandler . OnLongPollDelete ( ( token ) => ResponseUtils . CreateResponse ( HttpStatusCode . Accepted ) ) ;
229
+
230
+ using ( var noErrorScope = new VerifyNoErrorsScope ( ) )
231
+ {
232
+ await WithConnectionAsync (
233
+ CreateConnection ( testHttpHandler , loggerFactory : noErrorScope . LoggerFactory ) ,
234
+ async ( connection ) =>
235
+ {
236
+ await connection . StartAsync ( ) . OrTimeout ( ) ;
237
+ connectionId = connection . ConnectionId ;
238
+ } ) ;
239
+ }
240
+
241
+ Assert . Equal ( "0rge0d00-0040-0030-0r00-000q00r00e00" , connectionId ) ;
242
+ Assert . Equal ( "http://fakeuri.org/negotiate?negotiateVersion=1" , testHttpHandler . ReceivedRequests [ 0 ] . RequestUri . ToString ( ) ) ;
243
+ Assert . Equal ( "http://fakeuri.org/?id=0rge0d00-0040-0030-0r00-000q00r00e00" , testHttpHandler . ReceivedRequests [ 1 ] . RequestUri . ToString ( ) ) ;
244
+ }
245
+
122
246
[ Fact ]
123
247
public async Task NegotiateThatReturnsUrlGetFollowed ( )
124
248
{
@@ -172,8 +296,8 @@ await WithConnectionAsync(
172
296
} ) ;
173
297
}
174
298
175
- Assert . Equal ( "http://fakeuri.org/negotiate" , testHttpHandler . ReceivedRequests [ 0 ] . RequestUri . ToString ( ) ) ;
176
- Assert . Equal ( "https://another.domain.url/chat/negotiate" , testHttpHandler . ReceivedRequests [ 1 ] . RequestUri . ToString ( ) ) ;
299
+ Assert . Equal ( "http://fakeuri.org/negotiate?negotiateVersion=1 " , testHttpHandler . ReceivedRequests [ 0 ] . RequestUri . ToString ( ) ) ;
300
+ Assert . Equal ( "https://another.domain.url/chat/negotiate?negotiateVersion=1 " , testHttpHandler . ReceivedRequests [ 1 ] . RequestUri . ToString ( ) ) ;
177
301
Assert . Equal ( "https://another.domain.url/chat?id=0rge0d00-0040-0030-0r00-000q00r00e00" , testHttpHandler . ReceivedRequests [ 2 ] . RequestUri . ToString ( ) ) ;
178
302
Assert . Equal ( "https://another.domain.url/chat?id=0rge0d00-0040-0030-0r00-000q00r00e00" , testHttpHandler . ReceivedRequests [ 3 ] . RequestUri . ToString ( ) ) ;
179
303
Assert . Equal ( 5 , testHttpHandler . ReceivedRequests . Count ) ;
@@ -278,14 +402,76 @@ await WithConnectionAsync(
278
402
} ) ;
279
403
}
280
404
281
- Assert . Equal ( "http://fakeuri.org/negotiate" , testHttpHandler . ReceivedRequests [ 0 ] . RequestUri . ToString ( ) ) ;
282
- Assert . Equal ( "https://another.domain.url/chat/negotiate" , testHttpHandler . ReceivedRequests [ 1 ] . RequestUri . ToString ( ) ) ;
405
+ Assert . Equal ( "http://fakeuri.org/negotiate?negotiateVersion=1 " , testHttpHandler . ReceivedRequests [ 0 ] . RequestUri . ToString ( ) ) ;
406
+ Assert . Equal ( "https://another.domain.url/chat/negotiate?negotiateVersion=1 " , testHttpHandler . ReceivedRequests [ 1 ] . RequestUri . ToString ( ) ) ;
283
407
Assert . Equal ( "https://another.domain.url/chat?id=0rge0d00-0040-0030-0r00-000q00r00e00" , testHttpHandler . ReceivedRequests [ 2 ] . RequestUri . ToString ( ) ) ;
284
408
Assert . Equal ( "https://another.domain.url/chat?id=0rge0d00-0040-0030-0r00-000q00r00e00" , testHttpHandler . ReceivedRequests [ 3 ] . RequestUri . ToString ( ) ) ;
285
409
// Delete request
286
410
Assert . Equal ( 5 , testHttpHandler . ReceivedRequests . Count ) ;
287
411
}
288
412
413
+ [ Fact ]
414
+ public async Task NegotiateThatReturnsRedirectUrlDoesNotAddAnotherNegotiateVersionQueryString ( )
415
+ {
416
+ var testHttpHandler = new TestHttpMessageHandler ( autoNegotiate : false ) ;
417
+ var negotiateCount = 0 ;
418
+ testHttpHandler . OnNegotiate ( ( request , cancellationToken ) =>
419
+ {
420
+ negotiateCount ++ ;
421
+ if ( negotiateCount == 1 )
422
+ {
423
+ return ResponseUtils . CreateResponse ( HttpStatusCode . OK ,
424
+ JsonConvert . SerializeObject ( new
425
+ {
426
+ url = "https://another.domain.url/chat?negotiateVersion=1"
427
+ } ) ) ;
428
+ }
429
+ else
430
+ {
431
+ return ResponseUtils . CreateResponse ( HttpStatusCode . OK ,
432
+ JsonConvert . SerializeObject ( new
433
+ {
434
+ connectionId = "0rge0d00-0040-0030-0r00-000q00r00e00" ,
435
+ availableTransports = new object [ ]
436
+ {
437
+ new
438
+ {
439
+ transport = "LongPolling" ,
440
+ transferFormats = new [ ] { "Text" }
441
+ } ,
442
+ }
443
+ } ) ) ;
444
+ }
445
+ } ) ;
446
+
447
+ testHttpHandler . OnLongPoll ( ( token ) =>
448
+ {
449
+ var tcs = new TaskCompletionSource < HttpResponseMessage > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
450
+
451
+ token . Register ( ( ) => tcs . TrySetResult ( ResponseUtils . CreateResponse ( HttpStatusCode . NoContent ) ) ) ;
452
+
453
+ return tcs . Task ;
454
+ } ) ;
455
+
456
+ testHttpHandler . OnLongPollDelete ( ( token ) => ResponseUtils . CreateResponse ( HttpStatusCode . Accepted ) ) ;
457
+
458
+ using ( var noErrorScope = new VerifyNoErrorsScope ( ) )
459
+ {
460
+ await WithConnectionAsync (
461
+ CreateConnection ( testHttpHandler , loggerFactory : noErrorScope . LoggerFactory ) ,
462
+ async ( connection ) =>
463
+ {
464
+ await connection . StartAsync ( ) . OrTimeout ( ) ;
465
+ } ) ;
466
+ }
467
+
468
+ Assert . Equal ( "http://fakeuri.org/negotiate?negotiateVersion=1" , testHttpHandler . ReceivedRequests [ 0 ] . RequestUri . ToString ( ) ) ;
469
+ Assert . Equal ( "https://another.domain.url/chat/negotiate?negotiateVersion=1" , testHttpHandler . ReceivedRequests [ 1 ] . RequestUri . ToString ( ) ) ;
470
+ Assert . Equal ( "https://another.domain.url/chat?negotiateVersion=1&id=0rge0d00-0040-0030-0r00-000q00r00e00" , testHttpHandler . ReceivedRequests [ 2 ] . RequestUri . ToString ( ) ) ;
471
+ Assert . Equal ( "https://another.domain.url/chat?negotiateVersion=1&id=0rge0d00-0040-0030-0r00-000q00r00e00" , testHttpHandler . ReceivedRequests [ 3 ] . RequestUri . ToString ( ) ) ;
472
+ Assert . Equal ( 5 , testHttpHandler . ReceivedRequests . Count ) ;
473
+ }
474
+
289
475
[ Fact ]
290
476
public async Task StartSkipsOverTransportsThatTheClientDoesNotUnderstand ( )
291
477
{
0 commit comments