@@ -31,15 +31,15 @@ describe('getStudioBundle', () => {
3131        createWriteStream : createWriteStreamStub , 
3232      } , 
3333      'cross-fetch' : crossFetchStub , 
34-       '../../encryption' : { 
35-         verifySignatureFromFile : verifySignatureFromFileStub , 
36-       } , 
3734      'os' : { 
3835        platform : ( )  =>  'linux' , 
3936      } , 
4037      '@packages/root' : { 
4138        version : '1.2.3' , 
4239      } , 
40+       '../../encryption' : { 
41+         verifySignatureFromFile : verifySignatureFromFileStub , 
42+       } , 
4343    } ) . getStudioBundle 
4444  } ) 
4545
@@ -53,15 +53,17 @@ describe('getStudioBundle', () => {
5353          if  ( header  ===  'x-cypress-signature' )  { 
5454            return  '159' 
5555          } 
56+ 
57+           if  ( header  ===  'x-cypress-manifest-signature' )  { 
58+             return  '160' 
59+           } 
5660        } , 
5761      } , 
5862    } ) 
5963
6064    verifySignatureFromFileStub . resolves ( true ) 
6165
62-     const  projectId  =  '12345' 
63- 
64-     await  getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  projectId,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) 
66+     const  responseSignature  =  await  getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) 
6567
6668    expect ( crossFetchStub ) . to . be . calledWith ( 'http://localhost:1234/studio/bundle/abc.tgz' ,  { 
6769      agent : sinon . match . any , 
@@ -78,6 +80,8 @@ describe('getStudioBundle', () => {
7880    expect ( writeResult ) . to . eq ( 'console.log("studio bundle")' ) 
7981
8082    expect ( verifySignatureFromFileStub ) . to . be . calledWith ( '/tmp/cypress/studio/abc/bundle.tar' ,  '159' ) 
83+ 
84+     expect ( responseSignature ) . to . eq ( '160' ) 
8185  } ) 
8286
8387  it ( 'downloads the studio bundle and extracts it after 1 fetch failure' ,  async  ( )  =>  { 
@@ -91,15 +95,17 @@ describe('getStudioBundle', () => {
9195          if  ( header  ===  'x-cypress-signature' )  { 
9296            return  '159' 
9397          } 
98+ 
99+           if  ( header  ===  'x-cypress-manifest-signature' )  { 
100+             return  '160' 
101+           } 
94102        } , 
95103      } , 
96104    } ) 
97105
98106    verifySignatureFromFileStub . resolves ( true ) 
99107
100-     const  projectId  =  '12345' 
101- 
102-     await  getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  projectId,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) 
108+     const  responseSignature  =  await  getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) 
103109
104110    expect ( crossFetchStub ) . to . be . calledWith ( 'http://localhost:1234/studio/bundle/abc.tgz' ,  { 
105111      agent : sinon . match . any , 
@@ -116,16 +122,16 @@ describe('getStudioBundle', () => {
116122    expect ( writeResult ) . to . eq ( 'console.log("studio bundle")' ) 
117123
118124    expect ( verifySignatureFromFileStub ) . to . be . calledWith ( '/tmp/cypress/studio/abc/bundle.tar' ,  '159' ) 
125+ 
126+     expect ( responseSignature ) . to . eq ( '160' ) 
119127  } ) 
120128
121129  it ( 'throws an error and returns a studio manager in error state if the fetch fails more than twice' ,  async  ( )  =>  { 
122130    const  error  =  new  HttpError ( 'Failed to fetch' ,  'url' ,  502 ,  'Bad Gateway' ,  'Bad Gateway' ,  sinon . stub ( ) ) 
123131
124132    crossFetchStub . rejects ( error ) 
125133
126-     const  projectId  =  '12345' 
127- 
128-     await  expect ( getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  projectId,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) ) . to . be . rejected 
134+     await  expect ( getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) ) . to . be . rejected 
129135
130136    expect ( crossFetchStub ) . to . be . calledThrice 
131137    expect ( crossFetchStub ) . to . be . calledWith ( 'http://localhost:1234/studio/bundle/abc.tgz' ,  { 
@@ -147,9 +153,7 @@ describe('getStudioBundle', () => {
147153      statusText : 'Some failure' , 
148154    } ) 
149155
150-     const  projectId  =  '12345' 
151- 
152-     await  expect ( getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  projectId,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) ) . to . be . rejected 
156+     await  expect ( getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) ) . to . be . rejected 
153157
154158    expect ( crossFetchStub ) . to . be . calledWith ( 'http://localhost:1234/studio/bundle/abc.tgz' ,  { 
155159      agent : sinon . match . any , 
@@ -164,7 +168,7 @@ describe('getStudioBundle', () => {
164168    } ) 
165169  } ) 
166170
167-   it ( 'throws an error and returns a studio  manager in error state if the signature verification fails' ,  async  ( )  =>  { 
171+   it ( 'throws an error and returns a cy-prompt  manager in error state if the signature verification fails' ,  async  ( )  =>  { 
168172    verifySignatureFromFileStub . resolves ( false ) 
169173
170174    crossFetchStub . resolves ( { 
@@ -176,15 +180,17 @@ describe('getStudioBundle', () => {
176180          if  ( header  ===  'x-cypress-signature' )  { 
177181            return  '159' 
178182          } 
183+ 
184+           if  ( header  ===  'x-cypress-manifest-signature' )  { 
185+             return  '160' 
186+           } 
179187        } , 
180188      } , 
181189    } ) 
182190
183191    verifySignatureFromFileStub . resolves ( false ) 
184192
185-     const  projectId  =  '12345' 
186- 
187-     await  expect ( getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  projectId,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) ) . to . be . rejected 
193+     await  expect ( getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) ) . to . be . rejected 
188194
189195    expect ( writeResult ) . to . eq ( 'console.log("studio bundle")' ) 
190196
@@ -209,13 +215,44 @@ describe('getStudioBundle', () => {
209215      statusText : 'OK' , 
210216      body : readStream , 
211217      headers : { 
212-         get : ( )  =>  null , 
218+         get : ( header )  =>  { 
219+           if  ( header  ===  'x-cypress-manifest-signature' )  { 
220+             return  '160' 
221+           } 
222+         } , 
223+       } , 
224+     } ) 
225+ 
226+     await  expect ( getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) ) . to . be . rejectedWith ( 'Unable to get studio signature' ) 
227+ 
228+     expect ( crossFetchStub ) . to . be . calledWith ( 'http://localhost:1234/studio/bundle/abc.tgz' ,  { 
229+       agent : sinon . match . any , 
230+       method : 'GET' , 
231+       headers : { 
232+         'x-route-version' : '1' , 
233+         'x-cypress-signature' : '1' , 
234+         'x-os-name' : 'linux' , 
235+         'x-cypress-version' : '1.2.3' , 
213236      } , 
237+       encrypt : 'signed' , 
214238    } ) 
239+   } ) 
215240
216-     const  projectId  =  '12345' 
241+   it ( 'throws an error if there is no manifest signature in the response headers' ,  async  ( )  =>  { 
242+     crossFetchStub . resolves ( { 
243+       ok : true , 
244+       statusText : 'OK' , 
245+       body : readStream , 
246+       headers : { 
247+         get : ( header )  =>  { 
248+           if  ( header  ===  'x-cypress-signature' )  { 
249+             return  '159' 
250+           } 
251+         } , 
252+       } , 
253+     } ) 
217254
218-     await  expect ( getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  projectId ,   bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) ) . to . be . rejected 
255+     await  expect ( getStudioBundle ( {  studioUrl : 'http://localhost:1234/studio/bundle/abc.tgz' ,  bundlePath : '/tmp/cypress/studio/abc/bundle.tar'  } ) ) . to . be . rejectedWith ( 'Unable to get studio manifest signature' ) 
219256
220257    expect ( crossFetchStub ) . to . be . calledWith ( 'http://localhost:1234/studio/bundle/abc.tgz' ,  { 
221258      agent : sinon . match . any , 
0 commit comments