-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: opt-in for /ipns/webui.ipfs.io
Adds an opt-in toggle (disabled by default) to Preferences which changes the URL of Web UI opened via Browser Action menu from {API}/webui to {API}/ipns/webui.ipfs.io This enables user to load the latest webui via DNSLink. Note that go-ipfs and js-ipfs do not whitelist /ipns/webui.ipfs.io on the API port yet, so there is a fallback in place that detects HTTP 404 and redirects user to {API}/webui. Closes: #736
- Loading branch information
Showing
11 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict' | ||
const { describe, it, beforeEach, before } = require('mocha') | ||
const { expect } = require('chai') | ||
const { initState, offlinePeerCount, buildWebuiURLString } = require('../../../add-on/src/lib/state') | ||
const { optionDefaults } = require('../../../add-on/src/lib/options') | ||
const { URL } = require('url') | ||
|
||
describe('state.js', function () { | ||
describe('initState', function () { | ||
before(function () { | ||
global.URL = URL | ||
}) | ||
it('should copy passed options as-is', () => { | ||
const expectedProps = Object.assign({}, optionDefaults) | ||
delete expectedProps.publicGatewayUrl | ||
delete expectedProps.useCustomGateway | ||
delete expectedProps.ipfsApiUrl | ||
delete expectedProps.customGatewayUrl | ||
const state = initState(optionDefaults) | ||
for (const prop in expectedProps) { | ||
expect(state).to.have.property(prop, optionDefaults[prop]) | ||
} | ||
}) | ||
it('should generate pubGwURL*', () => { | ||
const state = initState(optionDefaults) | ||
expect(state).to.not.have.property('publicGatewayUrl') | ||
expect(state).to.have.property('pubGwURL') | ||
expect(state).to.have.property('pubGwURLString') | ||
}) | ||
it('should generate redirect state', () => { | ||
const state = initState(optionDefaults) | ||
expect(state).to.not.have.property('useCustomGateway') | ||
expect(state).to.have.property('redirect') | ||
}) | ||
it('should generate apiURL*', () => { | ||
const state = initState(optionDefaults) | ||
expect(state).to.not.have.property('ipfsApiUrl') | ||
expect(state).to.have.property('apiURL') | ||
expect(state).to.have.property('apiURLString') | ||
}) | ||
it('should generate gwURL*', () => { | ||
const state = initState(optionDefaults) | ||
expect(state).to.not.have.property('customGatewayUrl') | ||
expect(state).to.have.property('gwURL') | ||
expect(state).to.have.property('gwURLString') | ||
}) | ||
it('should generate webuiURLString', () => { | ||
const state = initState(optionDefaults) | ||
expect(state).to.have.property('webuiURLString') | ||
}) | ||
}) | ||
|
||
describe('offlinePeerCount', function () { | ||
it('should be equal -1', () => { | ||
expect(offlinePeerCount).to.be.equal(-1) | ||
}) | ||
}) | ||
|
||
describe('buildWebuiURLString', function () { | ||
let fakeState | ||
beforeEach(() => { | ||
fakeState = { apiURLString: 'http://127.0.0.1:5001/' } | ||
}) | ||
it('should be throw error on missing apiURLString', () => { | ||
expect(() => buildWebuiURLString({})).to.throw('Missing apiURLString') | ||
}) | ||
it('should return /webui for optionDefaults', () => { | ||
fakeState.webuiFromDNSLink = optionDefaults.webuiFromDNSLink | ||
expect(buildWebuiURLString(fakeState)).to.be.equal(`${fakeState.apiURLString}webui/`) | ||
}) | ||
it('should return /webui when webuiFromDNSLink is falsy', () => { | ||
fakeState.webuiFromDNSLink = undefined | ||
expect(buildWebuiURLString(fakeState)).to.be.equal(`${fakeState.apiURLString}webui/`) | ||
}) | ||
it('should return /ipns/webui.ipfs.io when webuiFromDNSLink is true', () => { | ||
fakeState.webuiFromDNSLink = true | ||
expect(buildWebuiURLString(fakeState)).to.be.equal(`${fakeState.apiURLString}ipns/webui.ipfs.io/`) | ||
}) | ||
}) | ||
}) |