Skip to content

Commit 3ec5a14

Browse files
fix: [UEPR-230] change fixture to take into account added sanitization
1 parent ddb3a66 commit 3ec5a14

File tree

9 files changed

+14
-9
lines changed

9 files changed

+14
-9
lines changed
-941 Bytes
Binary file not shown.
-639 Bytes
Binary file not shown.
-961 Bytes
Binary file not shown.
-575 Bytes
Binary file not shown.

packages/scratch-vm/test/integration/offline-custom-assets.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const test = require('tap').test;
1010
const AdmZip = require('adm-zip');
1111
const ScratchStorage = require('scratch-storage').ScratchStorage;
1212
const VirtualMachine = require('../../src/index');
13+
const {sanitizeByteStream} = require('../../../scratch-svg-renderer/src/sanitize-svg');
1314

1415
const projectUri = path.resolve(__dirname, '../fixtures/offline-custom-assets.sb2');
1516
const projectZip = AdmZip(projectUri);
@@ -54,7 +55,7 @@ test('offline-custom-assets', t => {
5455

5556
const storedCostume = customCostume.asset;
5657
t.type(storedCostume, 'object');
57-
t.deepEquals(storedCostume.data, costumeData);
58+
t.same(storedCostume.data, sanitizeByteStream(costumeData));
5859

5960
const sounds = vm.runtime.targets[1].sprite.sounds;
6061
t.equals(sounds.length, 1);

packages/scratch-vm/test/integration/sb2_corrupted_svg.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const FakeBitmapAdapter = require('../fixtures/fake-bitmap-adapter');
1515
const {extractAsset, readFileToBuffer} = require('../fixtures/readProjectFile');
1616
const VirtualMachine = require('../../src/index');
1717
const {serializeCostumes} = require('../../src/serialization/serialize-assets');
18+
const {sanitizeByteStream} = require('../../../scratch-svg-renderer/src/sanitize-svg');
1819

1920
const projectUri = path.resolve(__dirname, '../fixtures/corrupt_svg.sb2');
2021
const project = readFileToBuffer(projectUri);
@@ -23,7 +24,7 @@ const originalCostume = extractAsset(projectUri, costumeFileName);
2324
// We need to get the actual md5 because we hand modified the svg to corrupt it
2425
// after we downloaded the project from Scratch
2526
// Loading the project back into the VM will correct the assetId and md5
26-
const brokenCostumeMd5 = md5(originalCostume);
27+
const brokenCostumeMd5 = md5(sanitizeByteStream(originalCostume));
2728

2829
global.Image = function () {
2930
const image = {
@@ -57,7 +58,7 @@ tap.beforeEach(() => {
5758
// Mock renderer breaking on loading a corrupt costume
5859
FakeRenderer.prototype.createSVGSkin = function (svgString) {
5960
// Look for text added to costume to make it a corrupt svg
60-
if (svgString.includes('<here is some')) {
61+
if (svgString.includes('<rect width="100 height=100 fill=">')) {
6162
throw new Error('mock createSVGSkin broke');
6263
}
6364
return FakeRenderer._nextSkinId++;

packages/scratch-vm/test/integration/sb3_corrupted_svg.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const FakeRenderer = require('../fixtures/fake-renderer');
1414
const {extractAsset, readFileToBuffer} = require('../fixtures/readProjectFile');
1515
const VirtualMachine = require('../../src/index');
1616
const {serializeCostumes} = require('../../src/serialization/serialize-assets');
17+
const {sanitizeByteStream} = require('../../../scratch-svg-renderer/src/sanitize-svg');
1718

1819
const projectUri = path.resolve(__dirname, '../fixtures/corrupt_svg.sb3');
1920
const project = readFileToBuffer(projectUri);
@@ -22,7 +23,7 @@ const originalCostume = extractAsset(projectUri, costumeFileName);
2223
// We need to get the actual md5 because we hand modified the svg to corrupt it
2324
// after we downloaded the project from Scratch
2425
// Loading the project back into the VM will correct the assetId and md5
25-
const brokenCostumeMd5 = md5(originalCostume);
26+
const brokenCostumeMd5 = md5(sanitizeByteStream(originalCostume));
2627

2728
let vm;
2829
let defaultVectorAssetId;
@@ -37,7 +38,7 @@ tap.beforeEach(() => {
3738
// Mock renderer breaking on loading a corrupt costume
3839
FakeRenderer.prototype.createSVGSkin = function (svgString) {
3940
// Look for text added to costume to make it a corrupt svg
40-
if (svgString.includes('<here is some')) {
41+
if (svgString.includes('<rect width="100 height=100 fill=">')) {
4142
throw new Error('mock createSVGSkin broke');
4243
}
4344
return FakeRenderer._nextSkinId++;

packages/scratch-vm/test/integration/sprite2_corrupted_svg.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const FakeBitmapAdapter = require('../fixtures/fake-bitmap-adapter');
1616
const {extractAsset, readFileToBuffer} = require('../fixtures/readProjectFile');
1717
const VirtualMachine = require('../../src/index');
1818
const {serializeCostumes} = require('../../src/serialization/serialize-assets');
19+
const {sanitizeByteStream} = require('../../../scratch-svg-renderer/src/sanitize-svg');
1920

2021
const projectUri = path.resolve(__dirname, '../fixtures/default.sb3');
2122
const project = readFileToBuffer(projectUri);
@@ -28,7 +29,7 @@ const originalCostume = extractAsset(spriteUri, costumeFileName);
2829
// We need to get the actual md5 because we hand modified the svg to corrupt it
2930
// after we downloaded the project from Scratch
3031
// Loading the project back into the VM will correct the assetId and md5
31-
const brokenCostumeMd5 = md5(originalCostume);
32+
const brokenCostumeMd5 = md5(sanitizeByteStream(originalCostume));
3233

3334
global.Image = function () {
3435
const image = {
@@ -61,7 +62,7 @@ tap.beforeEach(() => {
6162
// Mock renderer breaking on loading a corrupt costume
6263
FakeRenderer.prototype.createSVGSkin = function (svgString) {
6364
// Look for text added to costume to make it a corrupt svg
64-
if (svgString.includes('<here is some')) {
65+
if (svgString.includes('<rect width="100 height=100 fill=">')) {
6566
throw new Error('mock createSVGSkin broke');
6667
}
6768
return FakeRenderer.prototype._nextSkinId++;

packages/scratch-vm/test/integration/sprite3_corrupted_svg.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const FakeRenderer = require('../fixtures/fake-renderer');
1515
const {extractAsset, readFileToBuffer} = require('../fixtures/readProjectFile');
1616
const VirtualMachine = require('../../src/index');
1717
const {serializeCostumes} = require('../../src/serialization/serialize-assets');
18+
const {sanitizeByteStream} = require('../../../scratch-svg-renderer/src/sanitize-svg');
1819

1920
const projectUri = path.resolve(__dirname, '../fixtures/default.sb3');
2021
const project = readFileToBuffer(projectUri);
@@ -27,7 +28,7 @@ const originalCostume = extractAsset(spriteUri, costumeFileName);
2728
// We need to get the actual md5 because we hand modified the svg to corrupt it
2829
// after we downloaded the project from Scratch
2930
// Loading the project back into the VM will correct the assetId and md5
30-
const brokenCostumeMd5 = md5(originalCostume);
31+
const brokenCostumeMd5 = md5(sanitizeByteStream(originalCostume));
3132

3233
let vm;
3334
let defaultVectorAssetId;
@@ -42,7 +43,7 @@ tap.beforeEach(() => {
4243
// Mock renderer breaking on loading a corrupt costume
4344
FakeRenderer.prototype.createSVGSkin = function (svgString) {
4445
// Look for text added to costume to make it a corrupt svg
45-
if (svgString.includes('<here is some')) {
46+
if (svgString.includes('<rect width="100 height=100 fill=">')) {
4647
throw new Error('mock createSVGSkin broke');
4748
}
4849
return FakeRenderer.prototype._nextSkinId++;

0 commit comments

Comments
 (0)