From 1a9a23ce0efe06f983f9a45100aeb688d5221567 Mon Sep 17 00:00:00 2001 From: Muhammad Nuzaihan Date: Sat, 25 Nov 2017 00:49:40 +0800 Subject: [PATCH] #1674 make sure login data is downcased. included tests to check as well --- lib/import/otrs/customer_user.rb | 1 + lib/import/otrs/user.rb | 1 + .../otrs/customer_user/camel_case_login.json | 348 ++++++++++++++++++ .../import/otrs/user/camel_case_login.json | 135 +++++++ spec/lib/import/otrs/customer_user_spec.rb | 38 ++ spec/lib/import/otrs/user_spec.rb | 34 ++ 6 files changed, 557 insertions(+) create mode 100644 spec/fixtures/import/otrs/customer_user/camel_case_login.json create mode 100644 spec/fixtures/import/otrs/user/camel_case_login.json diff --git a/lib/import/otrs/customer_user.rb b/lib/import/otrs/customer_user.rb index 6e12bb4b6..0d42816dd 100644 --- a/lib/import/otrs/customer_user.rb +++ b/lib/import/otrs/customer_user.rb @@ -68,6 +68,7 @@ module Import mapped[:created_at] ||= DateTime.current mapped[:updated_at] ||= DateTime.current mapped[:email].downcase! + mapped[:login].downcase! mapped end diff --git a/lib/import/otrs/user.rb b/lib/import/otrs/user.rb index a9392c890..e6b2f2ecd 100644 --- a/lib/import/otrs/user.rb +++ b/lib/import/otrs/user.rb @@ -68,6 +68,7 @@ module Import def map(user) mapped = map_default(user) mapped[:email].downcase! + mapped[:login].downcase! mapped end diff --git a/spec/fixtures/import/otrs/customer_user/camel_case_login.json b/spec/fixtures/import/otrs/customer_user/camel_case_login.json new file mode 100644 index 000000000..71dc42eca --- /dev/null +++ b/spec/fixtures/import/otrs/customer_user/camel_case_login.json @@ -0,0 +1,348 @@ +{ + "CustomerCompanyCity": "test712259", + "Config": { + "CustomerUserEmailUniqCheck": 1, + "CustomerUserSearchListLimit": 250, + "CustomerCompanySupport": 1, + "CustomerValid": "valid_id", + "CustomerUserSearchFields": [ + "login", + "first_name", + "last_name", + "customer_id" + ], + "CustomerUserSearchPrefix": "*", + "Params": { + "Table": "customer_user", + "CaseSensitive": 0 + }, + "CustomerUserListFields": [ + "first_name", + "last_name", + "email" + ], + "Map": [ + [ + "UserTitle", + "Title", + "title", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserFirstname", + "Firstname", + "first_name", + 1, + 1, + "var", + "", + 0 + ], + [ + "UserLastname", + "Lastname", + "last_name", + 1, + 1, + "var", + "", + 0 + ], + [ + "UserLogin", + "Username", + "login", + 1, + 1, + "var", + "", + 0 + ], + [ + "UserPassword", + "Password", + "pw", + 0, + 0, + "var", + "", + 0 + ], + [ + "UserEmail", + "Email", + "email", + 1, + 1, + "var", + "", + 0 + ], + [ + "UserCustomerID", + "CustomerID", + "customer_id", + 0, + 1, + "var", + "", + 0 + ], + [ + "UserPhone", + "Phone", + "phone", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserFax", + "Fax", + "fax", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserMobile", + "Mobile", + "mobile", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserStreet", + "Street", + "street", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserZip", + "Zip", + "zip", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserCity", + "City", + "city", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserCountry", + "Country", + "country", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserComment", + "Comment", + "comments", + 1, + 0, + "var", + "", + 0 + ], + [ + "ValidID", + "Valid", + "valid_id", + 0, + 1, + "int", + "", + 0 + ] + ], + "CustomerKey": "login", + "CustomerUserSearchSuffix": "*", + "Module": "Kernel::System::CustomerUser::DB", + "CacheTTL": 86400, + "Selections": {}, + "CustomerID": "customer_id", + "Name": "Database Backend", + "CustomerUserPostMasterSearchFields": [ + "email" + ], + "CustomerUserNameFields": [ + "title", + "first_name", + "last_name" + ] + }, + "UserCustomerID": "test712259", + "CustomerCompanyComment": "test712259", + "Source": "CustomerUser", + "UserTitle": "", + "CompanyConfig": { + "CustomerCompanySearchFields": [ + "customer_id", + "name" + ], + "CustomerCompanyListFields": [ + "customer_id", + "name" + ], + "Module": "Kernel::System::CustomerCompany::DB", + "CustomerCompanyKey": "customer_id", + "CustomerCompanySearchSuffix": "*", + "CacheTTL": 86400, + "CustomerCompanySearchListLimit": 250, + "CustomerCompanySearchPrefix": "", + "CustomerCompanyValid": "valid_id", + "Params": { + "Table": "customer_company", + "CaseSensitive": 0 + }, + "Map": [ + [ + "CustomerID", + "CustomerID", + "customer_id", + 0, + 1, + "var", + "", + 0 + ], + [ + "CustomerCompanyName", + "Customer", + "name", + 1, + 1, + "var", + "", + 0 + ], + [ + "CustomerCompanyStreet", + "Street", + "street", + 1, + 0, + "var", + "", + 0 + ], + [ + "CustomerCompanyZIP", + "Zip", + "zip", + 1, + 0, + "var", + "", + 0 + ], + [ + "CustomerCompanyCity", + "City", + "city", + 1, + 0, + "var", + "", + 0 + ], + [ + "CustomerCompanyCountry", + "Country", + "country", + 1, + 0, + "var", + "", + 0 + ], + [ + "CustomerCompanyURL", + "URL", + "url", + 1, + 0, + "var", + "[% Data.CustomerCompanyURL | html %]", + 0 + ], + [ + "CustomerCompanyComment", + "Comment", + "comments", + 1, + 0, + "var", + "", + 0 + ], + [ + "ValidID", + "Valid", + "valid_id", + 0, + 1, + "int", + "", + 0 + ] + ], + "Name": "Database Backend" + }, + "UserZip": null, + "UserLastname": "test669673", + "ChangeBy": "1", + "CreateTime": "2014-06-07 02:31:31", + "UserLogin": "TeSt669673", + "UserPhone": null, + "CustomerID": "test712259", + "CustomerCompanyValidID": "1", + "CustomerCompanyZIP": "test712259", + "UserCountry": null, + "UserPassword": "f8be19af2f25837a31eff9131b0e47a5173290652c04a48b49b86474d48825ee", + "ValidID": "1", + "UserRefreshTime": "0", + "UserEmail": "QA100@t-Online.de", + "UserComment": "", + "UserID": "test669673", + "UserFirstname": "test669673", + "CustomerCompanyCountry": "test712259", + "UserFax": null, + "CreateBy": "1", + "ChangeTime": "2014-06-07 02:31:31", + "UserShowTickets": "25", + "UserStreet": null, + "CustomerCompanyURL": "test712259", + "CustomerCompanyName": "test712259", + "UserMobile": null, + "CustomerCompanyStreet": "test712259", + "UserCity": null +} diff --git a/spec/fixtures/import/otrs/user/camel_case_login.json b/spec/fixtures/import/otrs/user/camel_case_login.json new file mode 100644 index 000000000..49d6d4aeb --- /dev/null +++ b/spec/fixtures/import/otrs/user/camel_case_login.json @@ -0,0 +1,135 @@ +{ + "OutOfOffice": "1", + "OutOfOfficeStartMonth": "9", + "UserStoredFilterColumns-AgentTicketLockedView": "{}", + "UserTicketOverviewSmallPageShown": "35", + "UserCreateWorkOrderNextMask": "AgentITSMWorkOrderZoom", + "OutOfOfficeEndYear": "2014", + "UserDashboardTicketGenericFilter0110-TicketEscalation": "All", + "UserDashboardPref0120-TicketNew-Columns": "{\"Columns\":{\"Changed\":0,\"CustomerID\":0,\"CustomerName\":0,\"CustomerUserID\":0,\"DynamicField_CustomerLocation\":0,\"EscalationResponseTime\":0,\"EscalationSolutionTime\":0,\"EscalationTime\":0,\"EscalationUpdateTime\":0,\"Lock\":0,\"Owner\":0,\"PendingTime\":0,\"Priority\":0,\"Responsible\":0,\"SLA\":0,\"State\":0,\"Type\":0,\"Age\":1,\"Title\":1,\"Queue\":1,\"Service\":1,\"TicketNumber\":1},\"Order\":[\"Age\",\"Title\",\"Queue\",\"Service\",\"TicketNumber\"]}", + "UserLastUsedZoomViewType": "", + "OutOfOfficeStartDay": "10", + "UserStoredFilterColumns-AgentTicketStatusView": "{}", + "UserTitle": null, + "UserLastname": "OTRS", + "UserTicketOverviewMediumPageShown": "20", + "OutOfOfficeEndDay": "12", + "CreateTime": "2014-04-28 10:53:18", + "UserTicketOverviewPreviewPageShown": "15", + "UserLogin": "rOoT@LoCaLhOsT", + "UserFilterColumnsEnabled-AgentTicketEscalationView": "[\"TicketNumber\",\"Age\",\"EscalationTime\",\"EscalationResponseTime\",\"EscalationSolutionTime\",\"EscalationUpdateTime\",\"Title\",\"State\",\"Lock\",\"Queue\",\"Owner\",\"CustomerID\"]", + "UserLanguage": "de", + "UserDashboardPref0110-TicketEscalation-Columns": "{\"Columns\":{\"Changed\":0,\"CustomerID\":0,\"CustomerUserID\":0,\"EscalationResponseTime\":0,\"EscalationSolutionTime\":0,\"EscalationTime\":0,\"EscalationUpdateTime\":0,\"Lock\":0,\"Owner\":0,\"PendingTime\":0,\"Priority\":0,\"Queue\":0,\"Responsible\":0,\"SLA\":0,\"Service\":0,\"State\":0,\"Type\":0,\"Age\":1,\"Title\":1,\"CustomerName\":1,\"TicketNumber\":1},\"Order\":[\"Age\",\"Title\",\"CustomerName\",\"TicketNumber\"]}", + "OutOfOfficeStartYear": "2014", + "UserDashboardPref0120-TicketNew-Shown": "10", + "UserFullname": "Admin OTRS", + "UserLastLoginTimestamp": "2016-08-10 19:37:44", + "UserLastLogin": "1470850664", + "UserMarkTicketUnseenRedirectURL": "Action=AgentTicketZoom;TicketID=###TicketID####1", + "AdminDynamicFieldsOverviewPageShown": "35", + "UserChangeOverviewSmallPageShown": "25", + "RoleIDs": [], + "ValidID": "1", + "UserStoredFilterColumns-AgentTicketQueue": "{}", + "UserEmail": "ROOT@loCalhosT", + "UserRefreshTime": "0", + "UserDashboardPref0130-TicketOpen-Shown": "10", + "UserTicketOverviewAgentTicketQueue": "Small", + "UserID": "1", + "UserDashboardTicketGenericColumnFiltersRealKeys0120-TicketNew": "{\"QueueIDs\":[\"1\"]}", + "wpt22": "1", + "UserMarkTicketSeenRedirectURL": "Action=AgentTicketZoom;TicketID=###TicketID####1", + "UserStoredFilterColumns-AgentTicketEscalationView": "{}", + "UserDashboardTicketGenericFilter0120-TicketNew": "MyQueues", + "UserCreateNextMask": "", + "UserFirstname": "Admin", + "UserPw": "9faaba2ab242a99bbb6992e9424386375f6757c17e6484ae570f39d9cad9f28ea", + "UserDashboardPref0110-TicketEscalation-Shown": "10", + "UserFilterColumnsEnabled-AgentTicketQueue": "[\"TicketNumber\",\"Age\",\"Title\",\"State\",\"Lock\",\"DynamicField_CustomerLocation\",\"Queue\",\"Owner\",\"CustomerID\",\"DynamicField_Hostname\"]", + "OutOfOfficeEndMonth": "9", + "ChangeTime": "2014-04-28 10:53:18", + "UserDashboardPref0130-TicketOpen-Columns": "{\"Columns\":{\"Changed\":0,\"CustomerID\":0,\"CustomerUserID\":0,\"EscalationResponseTime\":0,\"EscalationTime\":0,\"EscalationUpdateTime\":0,\"Lock\":0,\"Owner\":0,\"PendingTime\":0,\"Priority\":0,\"Queue\":0,\"Responsible\":0,\"SLA\":0,\"Service\":0,\"State\":0,\"Type\":0,\"Age\":1,\"DynamicField_CustomerLocation\":1,\"Title\":1,\"CustomerName\":1,\"EscalationSolutionTime\":1,\"TicketNumber\":1},\"Order\":[\"Age\",\"DynamicField_CustomerLocation\",\"Title\",\"CustomerName\",\"EscalationSolutionTime\",\"TicketNumber\"]}", + "UserTicketOverviewAgentTicketSearch": "Small", + "UserTicketOverviewAgentCustomerSearch": "Small", + "UserDashboardTicketGenericColumnFilters0120-TicketNew": "{\"Queue\":\"1\"}", + "GroupIDs": { + "6": [ + "ro", + "move_into", + "create", + "note", + "owner", + "priority", + "rw" + ], + "3": [ + "ro", + "move_into", + "create", + "note", + "owner", + "priority", + "rw" + ], + "7": [ + "ro", + "move_into", + "create", + "note", + "owner", + "priority", + "rw" + ], + "2": [ + "ro", + "move_into", + "create", + "note", + "owner", + "priority", + "rw" + ], + "8": [ + "ro", + "move_into", + "create", + "note", + "owner", + "priority", + "rw" + ], + "1": [ + "ro", + "move_into", + "create", + "note", + "owner", + "priority", + "rw" + ], + "4": [ + "ro", + "move_into", + "create", + "note", + "owner", + "priority", + "rw" + ], + "5": [ + "ro", + "move_into", + "create", + "note", + "owner", + "priority", + "rw" + ] + }, + "UserConfigItemOverviewSmallPageShown": "25", + "UserAuthBackend": "", + "UserTicketOverviewAgentTicketLockedView": "Small", + "UserTicketOverviewAgentTicketEscalationView": "Small", + "UserTicketOverviewAgentTicketStatusView": "Small", + "UserLoginFailed": "0" +} diff --git a/spec/lib/import/otrs/customer_user_spec.rb b/spec/lib/import/otrs/customer_user_spec.rb index 51374dd4b..5f43a51b2 100644 --- a/spec/lib/import/otrs/customer_user_spec.rb +++ b/spec/lib/import/otrs/customer_user_spec.rb @@ -158,4 +158,42 @@ RSpec.describe Import::OTRS::CustomerUser do updates_with(zammad_structure) end end + + context 'regular user with camelcase login' do + + let(:object_structure) { load_customer_json('camel_case_login') } + let(:zammad_structure) do + { + created_by_id: '1', + updated_by_id: '1', + active: true, + source: 'OTRS Import', + organization_id: 1337, + role_ids: [3], + updated_at: '2014-06-07 02:31:31', + created_at: '2014-06-07 02:31:31', + note: '', + email: 'qa100@t-online.de', + firstname: 'test669673', + lastname: 'test669673', + login: 'test669673', + password: 'f8be19af2f25837a31eff9131b0e47a5173290652c04a48b49b86474d48825ee', + phone: nil, + fax: nil, + mobile: nil, + street: nil, + zip: nil, + city: nil, + country: nil + } + end + + it 'creates' do + creates_with(zammad_structure) + end + + it 'updates' do + updates_with(zammad_structure) + end + end end diff --git a/spec/lib/import/otrs/user_spec.rb b/spec/lib/import/otrs/user_spec.rb index 11f08d9bc..fcbbe00e4 100644 --- a/spec/lib/import/otrs/user_spec.rb +++ b/spec/lib/import/otrs/user_spec.rb @@ -166,4 +166,38 @@ RSpec.describe Import::OTRS::User do updates_with(zammad_structure) end end + + context 'regular user with camel case login' do + + let(:object_structure) { load_user_json('camel_case_login') } + let(:zammad_structure) do + { + created_by_id: 1, + updated_by_id: 1, + active: true, + source: 'OTRS Import', + role_ids: [2, 1], + group_ids: ['1'], + password: '{sha2}9faaba2ab242a99bbb6992e9424386375f6757c17e6484ae570f39d9cad9f28ea', + updated_at: '2014-04-28 10:53:18', + created_at: '2014-04-28 10:53:18', + id: '1', + email: 'root@localhost', + firstname: 'Admin', + lastname: 'OTRS', + login: 'root@localhost' + } + end + + it 'creates' do + prepare_expectations + creates_with(zammad_structure) + end + + it 'updates' do + prepare_expectations + updates_with(zammad_structure) + end + end + end