feat(app,module): fetch basic module

This commit is contained in:
2023-04-02 17:59:33 +02:00
parent d8ce2901d2
commit fbb27d6ea4
17 changed files with 472 additions and 3 deletions

View File

@ -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>

View 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)
})
});
});

View File

@ -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' };
}