From fc43615554306518795e475efc84bfd3f4035f3e Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 25 Apr 2018 14:50:36 +0200 Subject: [PATCH] Fixes #1974 - If fingerprint is an integer background job for verifying will fail. --- app/models/user_device.rb | 2 +- .../user_device_controller_test.rb | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/models/user_device.rb b/app/models/user_device.rb index 1ef721e48..8fccaf44f 100644 --- a/app/models/user_device.rb +++ b/app/models/user_device.rb @@ -236,7 +236,7 @@ check fingerprint string def self.fingerprint_validation(fingerprint) return true if fingerprint.blank? - raise Exceptions::UnprocessableEntity, "fingerprint is #{fingerprint.length} chars but can only be 160 chars!" if fingerprint.length > 160 + raise Exceptions::UnprocessableEntity, "fingerprint is #{fingerprint.to_s.length} chars but can only be 160 chars!" if fingerprint.to_s.length > 160 true end diff --git a/test/integration/user_device_controller_test.rb b/test/integration/user_device_controller_test.rb index 99407dba1..28bf37394 100644 --- a/test/integration/user_device_controller_test.rb +++ b/test/integration/user_device_controller_test.rb @@ -506,7 +506,28 @@ class UserDeviceControllerTest < ActionDispatch::IntegrationTest end - test '12 - login form controller - check no user device logging' do + test '12 - login with integer as fingerprint' do + + assert_equal(0, UserDevice.where(user_id: @admin.id).count) + assert_equal(0, email_notification_count('user_device_new', @admin.email)) + assert_equal(0, email_notification_count('user_device_new_location', @admin.email)) + + params = { fingerprint: 123_456_789, username: 'user-device-admin', password: 'adminpw' } + post '/api/v1/signin', params: params.to_json, headers: @headers + assert_response(201) + result = JSON.parse(@response.body) + assert(123_456_789, controller.session[:user_device_fingerprint]) + + Scheduler.worker(true) + + assert_equal(1, UserDevice.where(user_id: @admin.id).count) + assert_equal(0, email_notification_count('user_device_new', @admin.email)) + assert_equal(0, email_notification_count('user_device_new_location', @admin.email)) + assert_equal(result.class, Hash) + assert_nil(result['error']) + end + + test '13 - login form controller - check no user device logging' do Setting.set('form_ticket_create', true)