Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Password Expireable #45

Merged
merged 18 commits into from
Oct 13, 2018

Conversation

olbrich
Copy link
Contributor

@olbrich olbrich commented Jun 23, 2018

Mostly this is a cleanup of the password expireable code that was started in part because of #44. I haven't yet been able to replicate the original issue, but it seemed like a good excuse to clean up some older code.

@olbrich olbrich self-assigned this Jun 23, 2018
return @enabled if defined?(@enabled)
@enabled = expire_password_after.is_a?(1.class) ||
expire_password_after.is_a?(Float) ||
expire_password_after == true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you can use expire_on_demand? here


self.password_changed_at
return unless enabled?
self.password_changed_at = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is a logic change from the original, not just cleaning up CC. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a slightly different implementation. The original would make up a fake time that would cause the record to appear as if it needed to be changed. I didn't particularly care for that because it makes it look like the user changed their password at a time when they really didn't and it makes it impossible to distinguish between an administrative expiration of the password and a real one. Just setting the password_changed_at to nil has the same effect and it's possible to tell that the password was deliberately expired because that is the only way to get a nil in that column.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, we'll just want to make sure do a release that indicates there's a change here.

else
# Expire when password_changed_at is nil or when the last time the
# password was changed is sufficiently old
password_changed_at.nil? || password_changed_at < expire_password_after.seconds.ago
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly extract this line into a private method to address the CC issue? It's borderline to me.

@coveralls
Copy link
Collaborator

coveralls commented Jun 23, 2018

Pull Request Test Coverage Report for Build 149

  • 101 of 101 (100.0%) changed or added relevant lines in 2 files are covered.
  • 5 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+3.4%) to 92.363%

Files with Coverage Reduction New Missed Lines %
test/test_password_expired_controller.rb 1 100.0%
lib/devise-security/controllers/helpers.rb 1 50.94%
test/test_security_question_controller.rb 3 100.0%
Totals Coverage Status
Change from base Build 141: 3.4%
Covered Lines: 895
Relevant Lines: 969

💛 - Coveralls

@bjensen
Copy link

bjensen commented Jul 21, 2018

+1 on someone to review

@olbrich olbrich requested review from natebird and dillonwelch July 21, 2018 18:38
@olbrich olbrich added this to the Next Release milestone Jul 21, 2018
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the switch here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we claim to support 2.2, but rubocop was looking for 2.3 syntax.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```erb
<p><%= captcha_tag %></p>
<p><%= text_field_tag :captcha %></p>
```

## Schema

Note: Unlike Devise, devise-security does not currently support mongoid. Pull requests are welcome!
Note: Unlike Devise, devise-security does not currently support mongoid. Pull requests are welcome!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to remove the Pull requests are welcome! given that we've discussed on an issue recently about that being pretty complicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a reformatting, if we want to remove that line, I suggest a new PR.

alias expire_password need_change_password
alias request_password_change need_change_password

# Set this value to a number of seconds to have passwords expire after a time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is a little confusing because it's not a setter.

# without a time limit.
# @return [Numeric, Boolean]
def expire_password_after
self.class.expire_password_after
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something you can use delegate for?

end
# Enabled if configuration +expire_password_after+ is set to an {Integer}, {Float}, or {true}
def password_expiration_enabled?
expire_password_after.present? &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`` expire_password_after.present?is already part ofexpire_password_on_demand?`

Coveralls.wear!
SimpleCov.start do
add_filter 'gemfiles'
add_filter 'test'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible I like to only restrict certain files vs all of test, because simplecov will catch dead test code.

@olbrich olbrich force-pushed the issue-44-deprecation-warning branch from 36b6e91 to b5bf3e6 Compare September 4, 2018 16:00
@olbrich olbrich requested a review from a team October 9, 2018 01:14
@olbrich
Copy link
Contributor Author

olbrich commented Oct 9, 2018

@devise-security/maintainers how about a new code review?

Copy link
Contributor

@natebird natebird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of formatting changes. Thanks for doing this cleanup to make everything consistent.

.codeclimate.yml Outdated
- "**/tests/"
- "**/vendor/"
- "**/*.d.ts"
- "gemfiles/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOL issue?

.gitignore Outdated
@@ -38,4 +38,5 @@ test/tmp/*
*.gem
Gemfile.lock
*.lock
bin/
bin/*
.yardoc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOL issue?

@olbrich olbrich merged commit 96bfdd8 into devise-security:master Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants