-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle invalid strings during seed phrase import (#6743)
* Add tests for ImportWithSeedPhrase#parseSeedPhrase * Handle importing whitespace-only seed phrases Fixes #6694 This changeset fixes our parsing of seed phrases during import to handle the case where a user tries to import a seed phrase that consists solely of whitespace. We no longer produce an error and instead treat it as an incorrect seed phrase. * Handle importing more invalid seed phrases
- Loading branch information
Showing
2 changed files
with
93 additions
and
4 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
78 changes: 78 additions & 0 deletions
78
...w/create-password/import-with-seed-phrase/tests/import-with-seed-phrase.component.test.js
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,78 @@ | ||
import React from 'react' | ||
import assert from 'assert' | ||
import { shallow } from 'enzyme' | ||
import sinon from 'sinon' | ||
import ImportWithSeedPhrase from '../import-with-seed-phrase.component' | ||
|
||
function shallowRender (props = {}, context = {}) { | ||
return shallow(<ImportWithSeedPhrase {...props} />, { | ||
context: { | ||
t: str => str + '_t', | ||
metricsEvent: sinon.spy(), | ||
...context, | ||
}, | ||
}) | ||
} | ||
|
||
describe('ImportWithSeedPhrase Component', () => { | ||
it('should render without error', () => { | ||
const root = shallowRender({ | ||
onSubmit: sinon.spy(), | ||
}) | ||
const textareaCount = root.find('.first-time-flow__textarea').length | ||
assert.equal(textareaCount, 1, 'should render 12 seed phrases') | ||
}) | ||
|
||
describe('parseSeedPhrase', () => { | ||
it('should handle a regular seed phrase', () => { | ||
const root = shallowRender({ | ||
onSubmit: sinon.spy(), | ||
}) | ||
|
||
const {parseSeedPhrase} = root.instance() | ||
|
||
assert.deepEqual(parseSeedPhrase('foo bar baz'), 'foo bar baz') | ||
}) | ||
|
||
it('should trim extraneous whitespace from the given seed phrase', () => { | ||
const root = shallowRender({ | ||
onSubmit: sinon.spy(), | ||
}) | ||
|
||
const {parseSeedPhrase} = root.instance() | ||
|
||
assert.deepEqual(parseSeedPhrase(' foo bar baz '), 'foo bar baz') | ||
}) | ||
|
||
it('should return an empty string when given a whitespace-only string', () => { | ||
const root = shallowRender({ | ||
onSubmit: sinon.spy(), | ||
}) | ||
|
||
const {parseSeedPhrase} = root.instance() | ||
|
||
assert.deepEqual(parseSeedPhrase(' '), '') | ||
}) | ||
|
||
it('should return an empty string when given a string with only symbols', () => { | ||
const root = shallowRender({ | ||
onSubmit: sinon.spy(), | ||
}) | ||
|
||
const {parseSeedPhrase} = root.instance() | ||
|
||
assert.deepEqual(parseSeedPhrase('$'), '') | ||
}) | ||
|
||
it('should return an empty string for both null and undefined', () => { | ||
const root = shallowRender({ | ||
onSubmit: sinon.spy(), | ||
}) | ||
|
||
const {parseSeedPhrase} = root.instance() | ||
|
||
assert.deepEqual(parseSeedPhrase(undefined), '') | ||
assert.deepEqual(parseSeedPhrase(null), '') | ||
}) | ||
}) | ||
}) |