Skip to content

Commit

Permalink
Missing Digest #1541
Browse files Browse the repository at this point in the history
  • Loading branch information
picman committed Aug 29, 2024
1 parent 8d9b06a commit 06d8189
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Rails/SkipsModelValidations:
- db/migrate/20160215125801_approval_workflow_status.rb
- db/migrate/20140519133201_trash_bin.rb
- db/migrate/07_dmsf_1_4_4.rb
- db/migrate/20240829093801_rename_dmsf_digest_token.rb

Rails/ThreeStateBooleanColumn:
Exclude:
Expand Down
2 changes: 2 additions & 0 deletions after_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def dmsf_init
pmap.permission :delete_project_watchers, { watchers: :destroy }
end
end
# DMSF WebDAV digest token
Token.add_action :dmsf_webdav_digest, max_instances: 1, validity_time: nil
end

if Redmine::Plugin.installed?('easy_extensions')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/dmsf_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def reset_digest
raise StandardError, l(:notice_account_wrong_password) unless User.current.check_password?(params[:password])

# We have to create a token first to prevent an autogenerated token's value
token = Token.create!(user_id: User.current.id, action: 'dmsf-webdav-digest')
token = Token.create!(user_id: User.current.id, action: 'dmsf_webdav_digest')
token.value = ActiveSupport::Digest.hexdigest(
"#{User.current.login}:#{RedmineDmsf::Webdav::AUTHENTICATION_REALM}:#{params[:password]}"
)
Expand Down
30 changes: 30 additions & 0 deletions db/migrate/20240829093801_rename_dmsf_digest_token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

# Redmine plugin for Document Management System "Features"
#
# Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Rename DMSF digest token
class RenameDmsfDigestToken < ActiveRecord::Migration[6.1]
def up
Token.where(action: 'dmsf-webdav-digest').update_all action: 'dmsf_webdav_digest'
end

def down
Token.where(action: 'dmsf_webdav_digest').update_all action: 'dmsf-webdav-digest'
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def controller_account_success_authentication_after(context = {})

# Updates user's DMSF WebDAV digest
if controller.params[:password].present?
token = Token.find_by(user_id: user.id, action: 'dmsf-webdav-digest')
token ||= Token.create!(user_id: user.id, action: 'dmsf-webdav-digest')
token = Token.find_by(user_id: user.id, action: 'dmsf_webdav_digest')
token ||= Token.create!(user_id: user.id, action: 'dmsf_webdav_digest')
token.value = ActiveSupport::Digest.hexdigest(
"#{user.login}:#{RedmineDmsf::Webdav::AUTHENTICATION_REALM}:#{controller.params[:password]}"
)
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine_dmsf/webdav/dmsf_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def authenticate
Rails.logger.error l(:notice_account_locked)
raise Unauthorized
end
token = Token.find_by(user_id: user.id, action: 'dmsf-webdav-digest')
token = Token.find_by(user_id: user.id, action: 'dmsf_webdav_digest')
if token.nil? && defined?(EasyExtensions)
if user.easy_digest_token_expired?
Rails.logger.error "Digest authentication: #{user} is locked"
Expand Down
2 changes: 1 addition & 1 deletion test/functional/dmsf_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def test_reset_digest
post '/dmsf/digest', params: { password: 'jsmith' }
assert_response :redirect
assert_redirected_to my_account_path
token = Token.find_by(user_id: @jsmith.id, action: 'dmsf-webdav-digest')
token = Token.find_by(user_id: @jsmith.id, action: 'dmsf_webdav_digest')
assert token
assert_equal ActiveSupport::Digest.hexdigest("jsmith:#{RedmineDmsf::Webdav::AUTHENTICATION_REALM}:jsmith"),
token.value
Expand Down
2 changes: 1 addition & 1 deletion test/integration/webdav/dmsf_webdav_get_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_digest_authentication
digest = ActiveSupport::Digest.hexdigest(
"#{@jsmith_user.login}:#{RedmineDmsf::Webdav::AUTHENTICATION_REALM}:jsmith"
)
token ||= Token.create!(user_id: @jsmith_user.id, action: 'dmsf-webdav-digest')
token ||= Token.create!(user_id: @jsmith_user.id, action: 'dmsf_webdav_digest')
token.value = digest
assert token.save
authorization = encode_credentials(username: 'jsmith', digest: digest, target: '/dmsf/webdav')
Expand Down

0 comments on commit 06d8189

Please sign in to comment.