diff --git a/packages/astro/test/server-islands.test.js b/packages/astro/test/server-islands.test.js index 1f37333e22dd..96b58354e29a 100644 --- a/packages/astro/test/server-islands.test.js +++ b/packages/astro/test/server-islands.test.js @@ -73,7 +73,9 @@ describe('Server islands', () => { const res = await fixture.fetch('/includeComponentWithProps/'); assert.equal(res.status, 200); const html = await res.text(); - const fetchMatch = html.match(/fetch\('\/_server-islands\/ComponentWithProps\?[^']*p=([^&']*)/s); + const fetchMatch = html.match( + /fetch\('\/_server-islands\/ComponentWithProps\?[^']*p=([^&']*)/s, + ); assert.equal(fetchMatch.length, 2, 'should include props in the query string'); const firstProps = fetchMatch[1]; const secondRes = await fixture.fetch('/includeComponentWithProps/'); @@ -131,6 +133,41 @@ describe('Server islands', () => { const response = await app.render(request); assert.equal(response.headers.get('x-robots-tag'), 'noindex'); }); + it('omits empty props from the query string', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/'); + const response = await app.render(request); + assert.equal(response.status, 200); + const html = await response.text(); + const fetchMatch = html.match(/fetch\('\/_server-islands\/Island\?[^']*p=([^&']*)/s); + assert.equal(fetchMatch.length, 2, 'should include props in the query string'); + assert.equal(fetchMatch[1], '', 'should not include encrypted empty props'); + }); + it('re-encrypts props on each request', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/includeComponentWithProps/'); + const response = await app.render(request); + assert.equal(response.status, 200); + const html = await response.text(); + const fetchMatch = html.match( + /fetch\('\/_server-islands\/ComponentWithProps\?[^']*p=([^&']*)/s, + ); + assert.equal(fetchMatch.length, 2, 'should include props in the query string'); + const firstProps = fetchMatch[1]; + const secondRequest = new Request('http://example.com/includeComponentWithProps/'); + const secondResponse = await app.render(secondRequest); + assert.equal(secondResponse.status, 200); + const secondHtml = await secondResponse.text(); + const secondFetchMatch = secondHtml.match( + /fetch\('\/_server-islands\/ComponentWithProps\?[^']*p=([^&']*)/s, + ); + assert.equal(secondFetchMatch.length, 2, 'should include props in the query string'); + assert.notEqual( + secondFetchMatch[1], + firstProps, + 'should re-encrypt props on each request with a different IV', + ); + }); }); });