Skip to content

Commit 5ccaee8

Browse files
committed
Scratch.canFetchResource -> Scratch.canFetch
1 parent 795ceb1 commit 5ccaee8

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

src/extension-support/tw-extension-api-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Scratch = {
1111

1212
// Stubs:
1313
/* eslint-disable no-unused-vars */
14-
canFetchResource: url => Promise.resolve(true),
14+
canFetch: url => Promise.resolve(true),
1515
canOpenWindow: url => Promise.resolve(true),
1616
canRedirect: url => Promise.resolve(true)
1717
/* eslint-enable no-unused-vars */

src/extension-support/tw-unsandboxed-extension-runner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const setupUnsandboxedExtensionAPI = vm => new Promise(resolve => {
3636
global.Scratch.vm = vm;
3737
global.Scratch.renderer = vm.runtime.renderer;
3838

39-
global.Scratch.canFetchResource = async url => {
39+
global.Scratch.canFetch = async url => {
4040
const parsed = parseURL(url);
4141
if (!parsed) {
4242
return false;
@@ -45,7 +45,7 @@ const setupUnsandboxedExtensionAPI = vm => new Promise(resolve => {
4545
if (parsed.protocol === 'blob:' || parsed.protocol === 'data:') {
4646
return true;
4747
}
48-
return vm.securityManager.canFetchResource(parsed.href);
48+
return vm.securityManager.canFetch(parsed.href);
4949
};
5050

5151
global.Scratch.canOpenWindow = async url => {

test/integration/tw_security_manager.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,48 +65,48 @@ test('Allow both extensions', async t => {
6565
t.end();
6666
});
6767

68-
test('canFetchResource', async t => {
68+
test('canFetch', async t => {
6969
const vm = new VirtualMachine();
7070
setupUnsandboxedExtensionAPI(vm);
7171
global.location = {
7272
href: 'https://example.com/'
7373
};
7474

7575
// data: and blob: are always allowed, shouldn't call security manager
76-
vm.securityManager.canFetchResource = () => t.fail('security manager should be ignored for these protocols');
77-
t.equal(await global.Scratch.canFetchResource('data:text/html,test'), true);
78-
t.equal(await global.Scratch.canFetchResource('blob:https://example.com/8c071bf8-c0b6-4a48-81d7-6413c2adf3dd'), true);
79-
80-
vm.securityManager.canFetchResource = () => false;
81-
t.equal(await global.Scratch.canFetchResource('file:///etc/hosts'), false);
82-
t.equal(await global.Scratch.canFetchResource('http://example.com/'), false);
83-
t.equal(await global.Scratch.canFetchResource('https://example.com/'), false);
84-
t.equal(await global.Scratch.canFetchResource('special.html'), false);
85-
86-
vm.securityManager.canFetchResource = () => Promise.resolve(false);
87-
t.equal(await global.Scratch.canFetchResource('file:///etc/hosts'), false);
88-
t.equal(await global.Scratch.canFetchResource('http://example.com/'), false);
89-
t.equal(await global.Scratch.canFetchResource('https://example.com/'), false);
90-
t.equal(await global.Scratch.canFetchResource('boring.html'), false);
91-
t.equal(await global.Scratch.canFetchResource('special.html'), false);
92-
93-
vm.securityManager.canFetchResource = () => true;
94-
t.equal(await global.Scratch.canFetchResource('file:///etc/hosts'), true);
95-
t.equal(await global.Scratch.canFetchResource('http://example.com/'), true);
96-
t.equal(await global.Scratch.canFetchResource('https://example.com/'), true);
97-
t.equal(await global.Scratch.canFetchResource('boring.html'), true);
98-
t.equal(await global.Scratch.canFetchResource('special.html'), true);
76+
vm.securityManager.canFetch = () => t.fail('security manager should be ignored for these protocols');
77+
t.equal(await global.Scratch.canFetch('data:text/html,test'), true);
78+
t.equal(await global.Scratch.canFetch('blob:https://example.com/8c071bf8-c0b6-4a48-81d7-6413c2adf3dd'), true);
79+
80+
vm.securityManager.canFetch = () => false;
81+
t.equal(await global.Scratch.canFetch('file:///etc/hosts'), false);
82+
t.equal(await global.Scratch.canFetch('http://example.com/'), false);
83+
t.equal(await global.Scratch.canFetch('https://example.com/'), false);
84+
t.equal(await global.Scratch.canFetch('special.html'), false);
85+
86+
vm.securityManager.canFetch = () => Promise.resolve(false);
87+
t.equal(await global.Scratch.canFetch('file:///etc/hosts'), false);
88+
t.equal(await global.Scratch.canFetch('http://example.com/'), false);
89+
t.equal(await global.Scratch.canFetch('https://example.com/'), false);
90+
t.equal(await global.Scratch.canFetch('boring.html'), false);
91+
t.equal(await global.Scratch.canFetch('special.html'), false);
92+
93+
vm.securityManager.canFetch = () => true;
94+
t.equal(await global.Scratch.canFetch('file:///etc/hosts'), true);
95+
t.equal(await global.Scratch.canFetch('http://example.com/'), true);
96+
t.equal(await global.Scratch.canFetch('https://example.com/'), true);
97+
t.equal(await global.Scratch.canFetch('boring.html'), true);
98+
t.equal(await global.Scratch.canFetch('special.html'), true);
9999

100100
const calledWithURLs = [];
101-
vm.securityManager.canFetchResource = async url => {
101+
vm.securityManager.canFetch = async url => {
102102
calledWithURLs.push(url);
103103
return url === 'https://example.com/special.html';
104104
};
105-
t.equal(await global.Scratch.canFetchResource('file:///etc/hosts'), false);
106-
t.equal(await global.Scratch.canFetchResource('http://example.com/'), false);
107-
t.equal(await global.Scratch.canFetchResource('https://example.com/special.html'), true);
108-
t.equal(await global.Scratch.canFetchResource('boring.html'), false);
109-
t.equal(await global.Scratch.canFetchResource('special.html'), true);
105+
t.equal(await global.Scratch.canFetch('file:///etc/hosts'), false);
106+
t.equal(await global.Scratch.canFetch('http://example.com/'), false);
107+
t.equal(await global.Scratch.canFetch('https://example.com/special.html'), true);
108+
t.equal(await global.Scratch.canFetch('boring.html'), false);
109+
t.equal(await global.Scratch.canFetch('special.html'), true);
110110
t.same(calledWithURLs, [
111111
'file:///etc/hosts',
112112
'http://example.com/',

test/unit/tw_extension_api_common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ test('Cast', t => {
3333
t.end();
3434
});
3535

36-
test('canFetchResource', async t => {
36+
test('canFetch', async t => {
3737
// Default implementation should allow all requuests.
38-
const result = ScratchCommon.canFetchResource('https://example.com/');
38+
const result = ScratchCommon.canFetch('https://example.com/');
3939
t.type(result, Promise);
4040
t.equal(await result, true);
4141
t.end();

test/unit/tw_unsandboxed_extensions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ test('ScratchX', async t => {
165165
t.end();
166166
});
167167

168-
test('canFetchResource', async t => {
168+
test('canFetch', async t => {
169169
// tested thoroughly in tw_security_manager.js
170170
const vm = new VirtualMachine();
171171
UnsandboxedExtensionRunner.setupUnsandboxedExtensionAPI(vm);
172172
global.location = {
173173
href: 'https://turbowarp.org'
174174
};
175-
vm.securityManager.canFetchResource = () => false;
176-
const result = global.Scratch.canFetchResource('https://example.com');
175+
vm.securityManager.canFetch = () => false;
176+
const result = global.Scratch.canFetch('https://example.com');
177177
t.type(result, Promise);
178178
t.end();
179179
});

0 commit comments

Comments
 (0)