cfoundry 0.4.15 → 0.4.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,6 +57,21 @@ module CFoundry
57
57
  :content => :json)
58
58
  end
59
59
 
60
+ def password_score(password)
61
+ response = post(
62
+ { :password => password },
63
+ "password", "score",
64
+ :content => :form,
65
+ :accept => :json
66
+ )
67
+ required_score = response[:requiredScore] || 0
68
+ case (response[:score] || 0)
69
+ when 10 then :strong
70
+ when required_score..9 then :good
71
+ else :weak
72
+ end
73
+ end
74
+
60
75
  private
61
76
 
62
77
  def handle_response(response, accept)
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.4.15".freeze
3
+ VERSION = "0.4.16".freeze
4
4
  end
@@ -129,4 +129,61 @@ EOF
129
129
  expect(req).to have_been_requested
130
130
  end
131
131
  end
132
+
133
+ describe '#password_score' do
134
+ let(:password) { "password" }
135
+ let(:response) { MultiJson.encode({}) }
136
+
137
+ subject { uaa.password_score(password) }
138
+
139
+ before do
140
+ @request = stub_request(:post, "#{target}/password/score").with(
141
+ :body => {:password => password, },
142
+ :headers => { "Accept" => "application/json" }
143
+ ).to_return(
144
+ :status => 200,
145
+ :body => response
146
+ )
147
+ end
148
+
149
+ it 'sends a password change request' do
150
+ subject
151
+ expect(@request).to have_been_requested
152
+ end
153
+
154
+ context 'when the score is 0 and the required is 0' do
155
+ let(:response) { MultiJson.encode "score" => 0, "requiredScore" => 0 }
156
+ it { should == :good }
157
+ end
158
+
159
+ context 'when the score is less than the required core' do
160
+ let(:response) { MultiJson.encode "score" => 1, "requiredScore" => 5 }
161
+ it { should == :weak }
162
+ end
163
+
164
+ context 'and the score is equal to the required score' do
165
+ let(:response) { MultiJson.encode "score" => 5, "requiredScore" => 5 }
166
+ it { should == :good }
167
+ end
168
+
169
+ context 'and the score is greater than the required score' do
170
+ let(:response) { MultiJson.encode "score" => 6, "requiredScore" => 5 }
171
+ it { should == :good }
172
+ end
173
+
174
+ context 'and the score is 10' do
175
+ let(:response) { MultiJson.encode "score" => 10, "requiredScore" => 5 }
176
+ it { should == :strong }
177
+ end
178
+
179
+ context 'and the score is 10' do
180
+ let(:response) { MultiJson.encode "score" => 10, "requiredScore" => 10 }
181
+ it { should == :strong }
182
+ end
183
+
184
+ context 'and the score is invalid' do
185
+ let(:response) { MultiJson.encode "score" => 11, "requiredScore" => 5 }
186
+ it { should == :weak }
187
+ end
188
+ end
132
189
  end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :user, :class => CFoundry::V2::User do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ admin false
5
+
6
+ initialize_with do
7
+ CFoundry::V2::User.new(nil, nil)
8
+ end
9
+ end
10
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 47
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 15
10
- version: 0.4.15
9
+ - 16
10
+ version: 0.4.16
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-17 00:00:00 Z
18
+ date: 2012-12-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: multipart-post
@@ -203,6 +203,7 @@ files:
203
203
  - spec/factories/service_instance_factory.rb
204
204
  - spec/factories/service_plan_factory.rb
205
205
  - spec/factories/space_factory.rb
206
+ - spec/factories/user_factory.rb
206
207
  - spec/spec_helper.rb
207
208
  homepage: http://cloudfoundry.com/
208
209
  licenses: []
@@ -254,4 +255,5 @@ test_files:
254
255
  - spec/factories/service_instance_factory.rb
255
256
  - spec/factories/service_plan_factory.rb
256
257
  - spec/factories/space_factory.rb
258
+ - spec/factories/user_factory.rb
257
259
  - spec/spec_helper.rb