Fixed issue #896 - Passwords of imported users get changed.

This commit is contained in:
Thorsten Eckel 2017-03-27 15:22:07 +02:00
parent 4a1b4af6ae
commit a306078ebb
8 changed files with 50 additions and 9 deletions

View file

@ -980,6 +980,7 @@ raise 'Minimum one user need to have admin permissions'
def ensure_password
return if password_empty?
return if Setting.get('import_mode')
return if PasswordHash.crypted?(password)
self.password = PasswordHash.crypt(password)
end

View file

@ -9,13 +9,16 @@ module Import
raise 'System is not in import mode!'
end
# log
def check_system_init_done
return true if !Setting.get('system_init_done')
raise 'System is already system_init_done!'
end
def log(message)
thread_no = Thread.current[:thread_no] || '-'
Rails.logger.info "thread##{thread_no}: #{message}"
end
# utf8 convert
def utf8_encode(data)
data.each { |key, value|
next if !value

View file

@ -57,6 +57,7 @@ module Import
def checks
check_import_mode
check_system_init_done
connection_test
end

View file

@ -62,6 +62,7 @@ module Import::Zendesk
def checks
check_import_mode
check_system_init_done
connection_test
end
end

View file

@ -4,13 +4,30 @@ require 'lib/import/helper_examples'
RSpec.describe Import::Helper do
it_behaves_like 'Import::Helper'
it 'checks if import_mode is active' do
expect(Setting).to receive(:get).with('import_mode').and_return(true)
expect( described_class.check_import_mode ).to be true
context 'import mode' do
it 'checks if import_mode is active' do
expect(Setting).to receive(:get).with('import_mode').and_return(true)
expect( described_class.check_import_mode ).to be true
end
it 'throws an exception if import_mode is disabled' do
expect(Setting).to receive(:get).with('import_mode').and_return(false)
expect { described_class.check_import_mode }.to raise_error(RuntimeError)
end
end
it 'throws an exception if import_mode is disabled' do
expect(Setting).to receive(:get).with('import_mode').and_return(false)
expect { described_class.check_import_mode }.to raise_error(RuntimeError)
context 'system init' do
it 'checks if system_init_done is active' do
expect(Setting).to receive(:get).with('system_init_done').and_return(false)
expect( described_class.check_system_init_done ).to be true
end
it 'throws an exception if system_init_done is disabled' do
expect(Setting).to receive(:get).with('system_init_done').and_return(true)
expect { described_class.check_system_init_done }.to raise_error(RuntimeError)
end
end
end

View file

@ -104,7 +104,7 @@ RSpec.describe User do
end
end
context '.by_reset_token' do
context '#by_reset_token' do
it 'returns a User instance for existing tokens' do
token = create(:token_password_reset)
@ -133,4 +133,20 @@ RSpec.describe User do
end
end
context 'import' do
it "doesn't change imported passwords" do
# mock settings calls
expect(Setting).to receive(:get).with('import_mode').and_return(true)
allow(Setting).to receive(:get)
user = build(:user, password: '{sha2}dd9c764fa7ea18cd992c8600006d3dc3ac983d1ba22e9ba2d71f6207456be0ba') # zammad
expect {
user.save
}.to_not change {
user.password
}
end
end
end

View file

@ -13,6 +13,7 @@ class OtrsImportTest < ActiveSupport::TestCase
Setting.set('import_otrs_endpoint', ENV['IMPORT_OTRS_ENDPOINT'])
Setting.set('import_otrs_endpoint_key', ENV['IMPORT_OTRS_ENDPOINT_KEY'])
Setting.set('import_mode', true)
Setting.set('system_init_done', false)
Import::OTRS.start
# check settings items

View file

@ -17,6 +17,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
Setting.set('import_zendesk_endpoint_key', ENV['IMPORT_ZENDESK_ENDPOINT_KEY'])
Setting.set('import_zendesk_endpoint_username', ENV['IMPORT_ZENDESK_ENDPOINT_USERNAME'])
Setting.set('import_mode', true)
Setting.set('system_init_done', false)
Import::Zendesk.start
# check statistic count