6
6
7
7
'use strict' ;
8
8
9
- const expect = require ( 'chai' ) . use ( require ( 'chai-as-promised' ) ) . expect ;
9
+ const assert = require ( 'chai' ) . use ( require ( 'chai-as-promised' ) ) . assert ;
10
10
const QuicTransportServer = require ( '../quicTransportServer.js' ) ;
11
11
const sinon = require ( 'sinon' ) ;
12
12
@@ -48,18 +48,58 @@ describe('Test QuicTransportServer.', () => {
48
48
const transportid1 = 'transportid1' ;
49
49
const transportid2 = 'transportid2' ;
50
50
server . addTransportId ( transportid1 ) ;
51
- expect ( server . createSendStream ( transportid2 ) ) . to . be . undefined ;
51
+ assert . equal ( server . createSendStream ( transportid2 ) , undefined ) ;
52
52
done ( ) ;
53
53
} ) ;
54
54
55
- it ( 'Test UUID convertions.' ,
56
- ( done ) => {
57
- const uuidString0 = '' ;
58
- const uuidString1 = '' ;
59
- const uuidString2 = '' ;
60
- const uuidArray0 = '' ;
61
- const uuidArray1 = '' ;
62
- const uuidArray2 = '' ;
63
- done ( ) ;
64
- } ) ;
55
+ it ( 'UUID convertions.' , ( done ) => {
56
+ const uuidStrings = [
57
+ '00000000000000000000000000000000' , 'd8bc24a9360b4320bf42704353d906db' ,
58
+ 'e6fc9b708b96418ab996c50bed964eb2'
59
+ ] ;
60
+ const uuidArrays = [
61
+ new Uint8Array ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ,
62
+ new Uint8Array ( [
63
+ 216 , 188 , 36 , 169 , 54 , 11 , 67 , 32 , 191 , 66 , 112 , 67 , 83 , 217 , 6 , 219
64
+ ] ) ,
65
+ new Uint8Array ( [
66
+ 230 , 252 , 155 , 112 , 139 , 150 , 65 , 138 , 185 , 150 , 197 , 11 , 237 , 150 , 78 ,
67
+ 178
68
+ ] )
69
+ ] ;
70
+ assert . equal ( uuidStrings . length , uuidArrays . length ) ;
71
+ for ( let i = 0 ; i < uuidStrings . length ; i ++ ) {
72
+ assert . deepEqual (
73
+ uuidArrays [ i ] , server . _uuidStringToUint8Array ( uuidStrings [ i ] ) ) ;
74
+ assert . deepEqual (
75
+ uuidStrings [ i ] , server . _uuidBytesToString ( uuidArrays [ i ] ) ) ;
76
+ }
77
+ done ( ) ;
78
+ } ) ;
79
+
80
+ it ( 'Correctly identify transport ID and content session ID.' , ( done ) => {
81
+ const connection1 = { close : sinon . stub ( ) } ;
82
+ const connection2 = { close : sinon . stub ( ) } ;
83
+ const stream10 = { } ;
84
+ const stream20 = { } ;
85
+ const transportId = '0123456789' ;
86
+ const unauthenticatedTransportId = '1234567890' ;
87
+ server . addTransportId ( transportId ) ;
88
+ fakeAddonServer . onconnection ( connection1 ) ;
89
+ connection1 . onincomingstream ( stream10 ) ;
90
+ stream10 . oncontentsessionid (
91
+ new Uint8Array ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ) ;
92
+ stream10 . ondata ( Buffer . from ( transportId , 'utf8' ) ) ;
93
+ assert . equal ( connection1 . transportId , transportId ) ;
94
+ assert . equal ( stream10 . transportId , transportId ) ;
95
+ fakeAddonServer . onconnection ( connection2 ) ;
96
+ connection2 . onincomingstream ( stream20 ) ;
97
+ stream20 . oncontentsessionid (
98
+ new Uint8Array ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ) ;
99
+ stream20 . ondata ( Buffer . from ( unauthenticatedTransportId , 'utf8' ) ) ;
100
+ sinon . assert . notCalled ( connection1 . close ) ;
101
+ // connection2 doesn't have an authenticated transport ID. Thus, it should be closed.
102
+ sinon . assert . calledOnce ( connection2 . close ) ;
103
+ done ( ) ;
104
+ } ) ;
65
105
} ) ;
0 commit comments