Commit 587ba99a90f2c2e2d129addd858c858475bac116
1 parent
07f1d9e1
Exists in
master
and in
29 other branches
api: test private token
Showing
3 changed files
with
21 additions
and
4 deletions
Show diff stats
app/models/profile.rb
@@ -937,7 +937,6 @@ private :generate_url, :url_options | @@ -937,7 +937,6 @@ private :generate_url, :url_options | ||
937 | image.public_filename(:icon) if image.present? | 937 | image.public_filename(:icon) if image.present? |
938 | end | 938 | end |
939 | 939 | ||
940 | - #FIXME make this test | ||
941 | def profile_custom_image(size = :icon) | 940 | def profile_custom_image(size = :icon) |
942 | image_path = profile_custom_icon if size == :icon | 941 | image_path = profile_custom_icon if size == :icon |
943 | image_path ||= image.public_filename(size) if image.present? | 942 | image_path ||= image.public_filename(size) if image.present? |
app/models/user.rb
@@ -120,16 +120,15 @@ class User < ActiveRecord::Base | @@ -120,16 +120,15 @@ class User < ActiveRecord::Base | ||
120 | self.update_attribute :last_login_at, Time.now | 120 | self.update_attribute :last_login_at, Time.now |
121 | end | 121 | end |
122 | 122 | ||
123 | - #FIXME make this test | ||
124 | def generate_private_token! | 123 | def generate_private_token! |
125 | self.private_token = SecureRandom.hex | 124 | self.private_token = SecureRandom.hex |
126 | self.private_token_generated_at = DateTime.now | 125 | self.private_token_generated_at = DateTime.now |
127 | save(:validate => false) | 126 | save(:validate => false) |
128 | end | 127 | end |
129 | 128 | ||
130 | - #FIXME make this test | 129 | + TOKEN_VALIDITY = 2.weeks |
131 | def private_token_expired? | 130 | def private_token_expired? |
132 | - self.generate_private_token! if self.private_token.nil? || (self.private_token_generated_at + 2.weeks < DateTime.now) | 131 | + self.private_token.nil? || (self.private_token_generated_at + TOKEN_VALIDITY < DateTime.now) |
133 | end | 132 | end |
134 | 133 | ||
135 | # Activates the user in the database. | 134 | # Activates the user in the database. |
test/unit/user_test.rb
@@ -715,6 +715,25 @@ class UserTest < ActiveSupport::TestCase | @@ -715,6 +715,25 @@ class UserTest < ActiveSupport::TestCase | ||
715 | assert_equal 'quire', user.person.name | 715 | assert_equal 'quire', user.person.name |
716 | end | 716 | end |
717 | 717 | ||
718 | + should 'generate private token' do | ||
719 | + user = User.new | ||
720 | + SecureRandom.stubs(:hex).returns('token') | ||
721 | + user.generate_private_token! | ||
722 | + | ||
723 | + assert user.private_token, 'token' | ||
724 | + end | ||
725 | + | ||
726 | + should 'check for private token validity' do | ||
727 | + user = User.new | ||
728 | + assert user.private_token_expired? | ||
729 | + | ||
730 | + user.generate_private_token! | ||
731 | + assert !user.private_token_expired? | ||
732 | + | ||
733 | + user.private_token_generated_at = DateTime.now - (User::TOKEN_VALIDITY + 1.minute) | ||
734 | + assert user.private_token_expired? | ||
735 | + end | ||
736 | + | ||
718 | protected | 737 | protected |
719 | def new_user(options = {}) | 738 | def new_user(options = {}) |
720 | user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) | 739 | user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) |