Skip to content

Commit

Permalink
Throw an error if all characters have been forbidden.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoglan committed Jun 7, 2012
1 parent b1ac78a commit 043a5bb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chrome/lib/vault.js
Expand Up @@ -112,6 +112,9 @@ Vault.prototype.generate = function(service) {
if (this._required.length > this._length)
throw new Error('Length too small to fit all required characters');

if (this._allowed.length === 0)
throw new Error('No characters available to create a password');

var hex = Vault.createHash(this._phrase, service + Vault.UUID, this.entropy()),
bits = Vault.map(hex.split(''), Vault.toBits).join(''),
result = '',
Expand Down
3 changes: 3 additions & 0 deletions lib/vault.js
Expand Up @@ -112,6 +112,9 @@ Vault.prototype.generate = function(service) {
if (this._required.length > this._length)
throw new Error('Length too small to fit all required characters');

if (this._allowed.length === 0)
throw new Error('No characters available to create a password');

var hex = Vault.createHash(this._phrase, service + Vault.UUID, this.entropy()),
bits = Vault.map(hex.split(''), Vault.toBits).join(''),
result = '',
Expand Down
15 changes: 15 additions & 0 deletions spec/vault_spec.js
Expand Up @@ -95,5 +95,20 @@ JS.ENV.VaultSpec = JS.Test.describe("Vault", function() { with(this) {
assertEqual( "s +8 p -{ R", vault.generate("songkick") )
}})
}})

describe("with no viable characters", function() { with(this) {
define("options", function() {
return {phrase: PHRASE,
alpha: 0,
number: 0,
space: 0,
dash: 0,
symbol: 0}
})

it("throws an error", function() { with(this) {
assertThrows(Error, function() { vault.generate("google") })
}})
}})
}})

0 comments on commit 043a5bb

Please sign in to comment.