Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add UI validation for RPC port #630

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions app/App/Panel/Local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ class Settings extends React.Component {
if (location.startsWith('https://') || location.startsWith('http://')) return true
return false
}

okPort (location) {
const match = location.match(/^(?:https?|wss?).*:(?<port>\d{4,})/)

if (match) {
const portStr = (match.groups || { port: 0 }).port
const port = parseInt(portStr)
return port >= 0 && port <= 65535
}

return true
}

//
// latticeFocus () {
// if (this.state.latticeEndpoint === this.customMessage) this.setState({ secondaryCustom: '' })
Expand Down Expand Up @@ -137,8 +150,15 @@ class Settings extends React.Component {
const current = connection.current

if (current === 'custom') {
if (layer === 'primary' && this.state.primaryCustom !== '' && this.state.primaryCustom !== this.customMessage && !this.okProtocol(this.state.primaryCustom)) status = 'invalid target'
if (layer === 'secondary' && this.state.secondaryCustom !== '' && this.state.secondaryCustom !== this.customMessage && !this.okProtocol(this.state.secondaryCustom)) status = 'invalid target'
if (layer === 'primary' && this.state.primaryCustom !== '' && this.state.primaryCustom !== this.customMessage) {
if (!this.okProtocol(this.state.primaryCustom)) status = 'invalid target'
else if (!this.okPort(this.state.primaryCustom)) status = 'invalid port'
}

if (layer === 'secondary' && this.state.secondaryCustom !== '' && this.state.secondaryCustom !== this.customMessage) {
if (!this.okProtocol(this.state.secondaryCustom)) status = 'invalid target'
else if (!this.okPort(this.state.secondaryCustom)) status = 'invalid port'
}
}
if (status === 'connected' && !connection.network) status = 'loading'
return (
Expand Down
23 changes: 21 additions & 2 deletions app/App/Panel/Networks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ class _Network extends React.Component {
return false
}

okPort (location) {
const match = location.match(/^(?:https?|wss?).*:(?<port>\d{4,})/)

if (match) {
const portStr = (match.groups || { port: 0 }).port
const port = parseInt(portStr)
return port >= 0 && port <= 65535
}

return true
}

inputPrimaryCustom (e) {
e.preventDefault()
clearTimeout(this.customPrimaryInputTimeout)
Expand Down Expand Up @@ -82,8 +94,15 @@ class _Network extends React.Component {
const current = connection.current

if (current === 'custom') {
if (layer === 'primary' && this.state.primaryCustom !== '' && this.state.primaryCustom !== this.customMessage && !this.okProtocol(this.state.primaryCustom)) status = 'invalid target'
if (layer === 'secondary' && this.state.secondaryCustom !== '' && this.state.secondaryCustom !== this.customMessage && !this.okProtocol(this.state.secondaryCustom)) status = 'invalid target'
if (layer === 'primary' && this.state.primaryCustom !== '' && this.state.primaryCustom !== this.customMessage) {
if (!this.okProtocol(this.state.primaryCustom)) status = 'invalid target'
else if (!this.okPort(this.state.primaryCustom)) status = 'invalid port'
}

if (layer === 'secondary' && this.state.secondaryCustom !== '' && this.state.secondaryCustom !== this.customMessage) {
if (!this.okProtocol(this.state.secondaryCustom)) status = 'invalid target'
else if (!this.okPort(this.state.secondaryCustom)) status = 'invalid port'
}
}
if (status === 'connected' && !connection.network) status = 'loading'
if (!this.store('main.networks', type, id, 'on')) status = 'off'
Expand Down
10 changes: 10 additions & 0 deletions test/main/signers/hot/HotSigner/worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ let worker

// mnemonic: test test test test test test test test test test test junk
const key = Buffer.from('4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356', 'hex')
let errorOutput = console.error

beforeAll(() => {
errorOutput = console.error
console.error = jest.fn()
})

afterAll(() => {
console.error = errorOutput
})

beforeEach(() => {
worker = new HotSignerWorker()
Expand Down