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

Exam markus auth #7072

Merged
merged 8 commits into from
May 10, 2024
Merged

Conversation

pretendWhale
Copy link
Contributor

@pretendWhale pretendWhale commented May 8, 2024

Proposed Changes

(Describe your changes here. Also describe the motivation for your changes: what problem do they solve, or how do they improve the application or codebase? If this pull request fixes an open issue, use a keyword to link this pull request to the issue.)

This PR adds a Settings.remote_validate_file option. If set to a file location, anytime a user logs in with remote auth (e.g. UTORauth), the program at Settings.remote_validate_file will be run. Login will be rejected if the program's exit status is anything other than 0. This was accomplished by modifying the User.authenticate method.

Tested on a staging server with utorauth https://ben.teach.cs.toronto.edu/canvas-test/ (by directly modifying remote_validate_file to exit with a desired code).

Screenshots of your changes (if applicable) image
Associated [documentation repository](https://github.com/MarkUsProject/Wiki) pull request (if applicable) https://github.com/MarkUsProject/Wiki/pull/213

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality) x
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)
I took the approach of modifying User.authenticate, but maybe it would be cleaner as a separate method?

@donny-wong donny-wong added this to the v2.4.10 milestone May 8, 2024
@coveralls
Copy link
Collaborator

coveralls commented May 8, 2024

Pull Request Test Coverage Report for Build 9026043649

Details

  • 47 of 48 (97.92%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.008%) to 91.378%

Changes Missing Coverage Covered Lines Changed/Added Lines %
config/initializers/config.rb 0 1 0.0%
Totals Coverage Status
Change from base Build 8995247780: 0.008%
Covered Lines: 39991
Relevant Lines: 43080

💛 - Coveralls

Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@pretendWhale good work. I left a few comments. Also whenever a new setting is added it should be reflected in the schema in config.rb.

@@ -37,10 +37,12 @@ class User < ApplicationRecord
AUTHENTICATE_ERROR = 'error'.freeze
AUTHENTICATE_BAD_PLATFORM = 'bad_platform'.freeze
AUTHENTICATE_BAD_CHAR = 'bad_char'.freeze
AUTHENTICATE_LOCAL = 'local'.freeze
AUTHENTICATE_REMOTE = 'remote'.freeze

# Authenticates login against its password
# through a script specified by Settings.validate_file
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the function documentation

def validate_login(user_name, password)
if user_name.blank? || password.blank?
def validate_login(user_name, password, auth_type: User::AUTHENTICATE_LOCAL)
if user_name.blank? || (password.blank? && auth_type == User::AUTHENTICATE_LOCAL)
flash_now(:error, get_blank_message(user_name, password))
return false
end

# No validate file means only remote authentication is allowed
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 also needs to be updated

Copy link
Contributor

Choose a reason for hiding this comment

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

@pretendWhale it doesn't seem like you changed this comment. My point here is that the comment is now misleading because the check below isn't just checking for "no validate file".

@@ -4,6 +4,7 @@ en:
cannot_role_switch: You do not have permission to role switch to this account.
cannot_role_switch_to_self: You cannot role switch to your own account.
create_marking_scheme: Create a Marking Scheme to display course summary graph.
external_authentication_bad_ip: Authentication with %{name} was successful, but access to this MarkUs is restricted.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the word "this"

@@ -83,6 +83,31 @@
expect(response).to redirect_to action: 'index', controller: 'courses'
end

context 'when markus is in restricted mode' do
Copy link
Contributor

Choose a reason for hiding this comment

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

always use correct capitalization when referring to "MarkUs"

@pretendWhale
Copy link
Contributor Author

Thanks @david-yz-liu ! Addressed the comments and added remote_validate_file to config.rb.

Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

I left one more comment. By the way, I think the overall approach of changing validate_login was totally fine 👍

def validate_login(user_name, password)
if user_name.blank? || password.blank?
def validate_login(user_name, password, auth_type: User::AUTHENTICATE_LOCAL)
if user_name.blank? || (password.blank? && auth_type == User::AUTHENTICATE_LOCAL)
flash_now(:error, get_blank_message(user_name, password))
return false
end

# No validate file means only remote authentication is allowed
Copy link
Contributor

Choose a reason for hiding this comment

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

@pretendWhale it doesn't seem like you changed this comment. My point here is that the comment is now misleading because the check below isn't just checking for "no validate file".

@david-yz-liu david-yz-liu merged commit 0db831b into MarkUsProject:master May 10, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants