feat(app,module): fetch basic module
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
<script src="/test/rpc-module.js"></script>
|
||||
<script src="/test/file-module.js"></script>
|
||||
<script src="/test/app-module.js"></script>
|
||||
<script src="/test/fetch-module.js"></script>
|
||||
<script class="mocha-exec">
|
||||
mocha.run();
|
||||
</script>
|
||||
|
33
misc/client-sdk-testsuite/src/public/test/fetch-module.js
Normal file
33
misc/client-sdk-testsuite/src/public/test/fetch-module.js
Normal file
@ -0,0 +1,33 @@
|
||||
describe('Fetch Module', function () {
|
||||
|
||||
before(() => {
|
||||
return Edge.connect();
|
||||
});
|
||||
|
||||
after(() => {
|
||||
Edge.disconnect();
|
||||
});
|
||||
|
||||
it('should fetch an authorized external url', function () {
|
||||
var externalUrl = Edge.externalUrl("http://example.com");
|
||||
|
||||
return fetch(externalUrl)
|
||||
.then(res => {
|
||||
chai.assert.equal(res.status, 200)
|
||||
return res.text()
|
||||
})
|
||||
.then(content => {
|
||||
chai.assert.include(content, '<h1>Example Domain</h1>')
|
||||
})
|
||||
});
|
||||
|
||||
it('should not fetch an unauthorized external url', function () {
|
||||
var externalUrl = Edge.externalUrl("https://google.com");
|
||||
|
||||
return fetch(externalUrl)
|
||||
.then(res => {
|
||||
chai.assert.equal(res.status, 403)
|
||||
})
|
||||
});
|
||||
|
||||
});
|
@ -97,4 +97,8 @@ function getApp(ctx, params) {
|
||||
function getAppUrl(ctx, params) {
|
||||
var appId = params.appId;
|
||||
return app.getUrl(ctx, appId);
|
||||
}
|
||||
|
||||
function onClientFetch(ctx, url, remoteAddr) {
|
||||
return { allow: url === 'http://example.com' };
|
||||
}
|
Reference in New Issue
Block a user