Permalink
Browse files

Added password strength to register command

Change-Id: Ifd17840d22f29eefc6c8c0889122dc8e4a7142a7
  • Loading branch information...
1 parent 2c6ab79 commit 820f85f3fd2f461ed2ebc6df734569f5debfe3d8 @vito vito committed Dec 18, 2012
@@ -18,12 +18,21 @@ def register
fail "Passwords do not match."
end
- with_progress("Creating user") do
- client.register(email, password)
- end
+ pw_strength = client.base.uaa.password_score(password)
+ msg = "Your password strength is: #{pw_strength}"
+
+ if pw_strength == :weak
+ fail msg
+ else
+ line msg
+
+ with_progress("Creating user") do
+ client.register(email, password)
+ end
- if input[:login]
- invoke :login, :username => email, :password => password
+ if input[:login]
+ invoke :login, :username => email, :password => password
+ end
end
end
File renamed without changes.
@@ -6,7 +6,7 @@
let(:username) { ENV['VMC_TEST_USER'] }
let(:password) { ENV['VMC_TEST_PASSWORD'] }
let(:output) { StringIO.new }
- let(:out) { output.string.gsub(/\. \x08([\x08\. ]+)/, "... ") } # trim animated dots
+ let(:out) { output.string.strip_progress_dots }
let(:app) {
fuzz =
View
@@ -19,6 +19,10 @@ def strip_heredoc
indent = min ? min.size : 0
gsub(/^[ \t]{#{indent}}/, '')
end
+
+ def strip_progress_dots
+ gsub(/\. \x08([\x08\. ]+)/, "... ")
+ end
end
def with_output_to(output = StringIO.new)
@@ -1,19 +1,15 @@
def vmc_ok(argv)
with_output_to do |out|
code = VMC::CLI.start(argv + ["--no-script"])
- yield strip_progress_dots(out.string) if block_given?
+ yield out.string.strip_progress_dots if block_given?
expect(code).to eq 0
end
end
def vmc_fail(argv)
with_output_to do |out|
code = VMC::CLI.start(argv + ["--no-script"])
- yield strip_progress_dots(out.string) if block_given?
+ yield out.string.strip_progress_dots if block_given?
expect(code).to eq 1
end
end
-
-def strip_progress_dots(str)
- str.gsub(/\. \x08([\x08\. ]+)/, "... ")
-end
@@ -0,0 +1,153 @@
+require 'spec_helper'
+
+describe VMC::Start::Register do
+ describe 'metadata' do
+ let(:command) { Mothership.commands[:register] }
+
+ describe 'command' do
+ subject { command }
+ its(:description) { should eq "Create a user and log in" }
+ it { expect(Mothership::Help.group(:start)).to include(subject) }
+ end
+
+ describe 'inputs' do
+ subject { command.inputs }
+
+ it "is not missing any descriptions" do
+ subject.each do |_, attrs|
+ expect(attrs[:description]).to be
+ expect(attrs[:description].strip).to_not be_empty
+ end
+ end
+ end
+
+ describe 'arguments' do
+ subject { command.arguments }
+ it 'have the correct commands' do
+ should eq [
+ {:type => :optional, :value => nil, :name => :email}
+ ]
+ end
+ end
+ end
+
+ describe '#register' do
+ let(:client) { FactoryGirl.build(:client) }
+ let(:output) { StringIO.new }
+ let(:out) { output.string }
+ let(:email) { "a@b.com" }
+ let(:password) { "password" }
+ let(:verify_password) { password }
+ let(:force) { false }
+ let(:login) { false }
+ let(:score) { :strong }
+
+ before do
+ stub(VMC::CLI).exit { |code| code }
+ any_instance_of(VMC::CLI) do |cli|
+ stub(cli).client { client }
+ stub(cli).precondition { nil }
+ end
+ stub(client).register
+ stub(client).base.stub!.uaa.stub!.password_score(password) { score }
+ end
+
+ subject do
+ with_output_to output do
+ VMC::CLI.start %W(register #{email} --password #{password} --verify #{verify_password} #{login ? '--login' : '--no-login'} #{force ? '--force' : '--no-force'} --debug)
+ end
+ end
+
+ context 'when the passwords dont match' do
+ let(:verify_password) { "other_password" }
+
+ it { should eq 1 }
+
+ it 'fails' do
+ subject
+ expect(out).to include "Passwords do not match."
+ end
+
+ it "doesn't print out the score" do
+ subject
+ expect(out).not_to include "score"
+ end
+
+ it "doesn't log in or register" do
+ dont_allow(client).register
+ any_instance_of VMC::Start::Register do |register|
+ dont_allow(register).invoke
+ end
+ subject
+ end
+
+ context 'and the force flag is passed' do
+ let(:force) { true }
+
+ it "doesn't verify the password" do
+ mock(client).register(email, password)
+ subject
+ expect(out).not_to include "Passwords do not match."
+ end
+ end
+ end
+
+ context 'when the password is good or strong' do
+ it { should eq 0 }
+
+ it 'prints out the password score' do
+ subject
+ expect(out).to include "Your password strength is: strong"
+ end
+
+ it 'registers the user' do
+ mock(client).register(email, password)
+ subject
+ end
+
+ context 'and the login flag is true' do
+ let(:login) { true }
+
+ it 'logs in' do
+ any_instance_of VMC::Start::Register do |register|
+ mock(register).invoke(:login, :username => email, :password => password)
+ end
+ subject
+ end
+ end
+
+ context 'and the login flag is false' do
+ it "doesn't log in" do
+ any_instance_of VMC::Start::Register do |register|
+ dont_allow(register).invoke(:login, :username => email, :password => password)
+ end
+ subject
+ end
+ end
+ end
+
+ context 'when the password is weak' do
+ let(:score) { :weak }
+ let(:login) { true }
+
+ it { should eq 1 }
+
+ it 'prints out the password score' do
+ subject
+ expect(out).to include "Your password strength is: weak"
+ end
+
+ it "doesn't register" do
+ dont_allow(client).register(email, password)
+ subject
+ end
+
+ it "doesn't log in" do
+ any_instance_of VMC::Start::Register do |register|
+ dont_allow(register).invoke(:login, :username => email, :password => password)
+ end
+ subject
+ end
+ end
+ end
+end
View
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.name = "vmc"
s.version = VMC::VERSION.dup
s.authors = ["Alex Suraci"]
- s.email = ["asuraci@vmware.com"]
+ s.email = %w(asuraci@vmware.com)
s.homepage = "http://cloudfoundry.com/"
s.summary = %q{
Friendly command-line interface for Cloud Foundry.
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
s.rubyforge_project = "vmc"
- s.files = %w{LICENSE Rakefile} + Dir.glob("lib/**/*")
- s.test_files = Dir.glob("spec/**/*")
- s.require_paths = ["lib"]
+ s.files = %w(LICENSE Rakefile) + Dir["lib/**/*"]
+ s.test_files = Dir["spec/**/*"]
+ s.require_paths = %w(lib)
s.add_runtime_dependency "json_pure", "~> 1.6"
s.add_runtime_dependency "multi_json", "~> 1.3"

0 comments on commit 820f85f

Please sign in to comment.