diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8ce7141b6..e03893101 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -278,6 +278,18 @@ test:integration:telegram: - ruby -I test test/integration/telegram_controller_test.rb - rake db:drop +test:integration:idoit: + stage: test + tags: + - core + script: + - export RAILS_ENV=test + - rake db:create + - rake db:migrate + - rake db:seed + - ruby -I test test/integration/idoit_controller_test.rb + - rake db:drop + test:integration:es_mysql: stage: test tags: diff --git a/app/controllers/integration/idoit_controller.rb b/app/controllers/integration/idoit_controller.rb index ee4960c5e..c217de073 100644 --- a/app/controllers/integration/idoit_controller.rb +++ b/app/controllers/integration/idoit_controller.rb @@ -1,8 +1,9 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ class Integration::IdoitController < ApplicationController - prepend_before_action -> { authentication_check(permission: ['agent.integration.idoit', 'admin.integration.idoit']) }, except: [:verify] + prepend_before_action -> { authentication_check(permission: ['agent.integration.idoit', 'admin.integration.idoit']) }, except: [:verify, :query, :update] prepend_before_action -> { authentication_check(permission: ['admin.integration.idoit']) }, only: [:verify] + prepend_before_action -> { authentication_check(permission: ['ticket.agent']) }, only: [:query, :update] def verify response = ::Idoit.verify(params[:api_token], params[:endpoint], params[:client_id]) diff --git a/lib/idoit.rb b/lib/idoit.rb index f1fe7f379..271211bf4 100644 --- a/lib/idoit.rb +++ b/lib/idoit.rb @@ -42,7 +42,7 @@ returns "container": "0", "const": "C__OBJTYPE__SERVICE", "color": "987384", - "image": "https://demo.panic.at/i-doit/images/objecttypes/service.jpg", + "image": "https://demo.example.com/i-doit/images/objecttypes/service.jpg", "icon": "images/icons/silk/application_osx_terminal.png", "cats": "4", "tree_group": "1", @@ -56,7 +56,7 @@ returns "container": "0", "const": "C__OBJTYPE__APPLICATION", "color": "E4B9D7", - "image": "https://demo.panic.at/i-doit/images/objecttypes/application.jpg", + "image": "https://demo.example.com/i-doit/images/objecttypes/application.jpg", "icon": "images/icons/silk/application_xp.png", "cats": "20", "tree_group": "1", @@ -71,7 +71,7 @@ or with filter: "result": [ { "id": "26", - "title": "demo.panic.at", + "title": "demo.example.com", "sysid": "SYSID_1485512390", "type": "59", "created": "2017-01-27 11:19:24", @@ -81,7 +81,7 @@ or with filter: "status": "2", "cmdb_status": "6", "cmdb_status_title": "in operation", - "image": "https://demo.panic.at/i-doit/images/objecttypes/empty.png" + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png" }, ], @@ -135,6 +135,8 @@ or with filter: end def self._url_cleanup(url) + url.gsub!(/^[[:space:]]+/, '') + url.gsub!(/[[:space:]]+$/, '') raise "Invalid endpoint '#{url}', need to start with http:// or https://" if url !~ %r{^http(s|)://}i url = _url_cleanup_baseurl(url) url = "#{url}/src/jsonrpc.php" @@ -142,6 +144,8 @@ or with filter: end def self._url_cleanup_baseurl(url) + url.gsub!(/^[[:space:]]+/, '') + url.gsub!(/[[:space:]]+$/, '') raise "Invalid endpoint '#{url}', need to start with http:// or https://" if url !~ %r{^http(s|)://}i url.gsub!(%r{src/jsonrpc.php}, '') url.gsub(%r{([^:])//+}, '\\1/') diff --git a/lib/service/geo_ip/zammad.rb b/lib/service/geo_ip/zammad.rb index 973879da9..0be67ca54 100644 --- a/lib/service/geo_ip/zammad.rb +++ b/lib/service/geo_ip/zammad.rb @@ -4,6 +4,8 @@ require 'cache' class Service::GeoIp::Zammad def self.location(address) + return {} if address == '127.0.0.1' + return {} if address == '::1' # check cache cache_key = "zammadgeoip::#{address}" diff --git a/test/fixtures/idoit/object_types_filter_response.json b/test/fixtures/idoit/object_types_filter_response.json new file mode 100644 index 000000000..ea22a92b7 --- /dev/null +++ b/test/fixtures/idoit/object_types_filter_response.json @@ -0,0 +1,18 @@ +{ + "jsonrpc": "2.0", + "result": [{ + "id": "26", + "title": "demo.example.com", + "sysid": "SYSID_1485512390", + "type": "59", + "created": "2017-01-27 11:19:24", + "updated": "2017-01-27 11:19:49", + "type_title": "Virtual server", + "type_group_title": "Infrastructure", + "status": "2", + "cmdb_status": "6", + "cmdb_status_title": "in operation", + "image": "https://idoit.example.com/i-doit/images/objecttypes/empty.png" + }], + "id": 1 +} \ No newline at end of file diff --git a/test/fixtures/idoit/object_types_response.json b/test/fixtures/idoit/object_types_response.json new file mode 100644 index 000000000..5910e6ba9 --- /dev/null +++ b/test/fixtures/idoit/object_types_response.json @@ -0,0 +1,945 @@ +{ + "jsonrpc": "2.0", + "result": [{ + "id": "1", + "title": "System service", + "container": "0", + "const": "C__OBJTYPE__SERVICE", + "color": "987384", + "image": "https://demo.example.com/i-doit/images/objecttypes/service.jpg", + "icon": "images/icons/silk/application_osx_terminal.png", + "cats": "4", + "tree_group": "1", + "status": "2", + "type_group": "1", + "type_group_title": "Software" + }, { + "id": "2", + "title": "Application", + "container": "0", + "const": "C__OBJTYPE__APPLICATION", + "color": "E4B9D7", + "image": "https://demo.example.com/i-doit/images/objecttypes/application.jpg", + "icon": "images/icons/silk/application_xp.png", + "cats": "20", + "tree_group": "1", + "status": "2", + "type_group": "1", + "type_group_title": "Software" + }, { + "id": "33", + "title": "Licenses", + "container": "0", + "const": "C__OBJTYPE__LICENCE", + "color": "EADEAC", + "image": "https://demo.example.com/i-doit/images/objecttypes/licence.png", + "icon": "images/icons/silk/key.png", + "cats": "24", + "tree_group": "1", + "status": "2", + "type_group": "1", + "type_group_title": "Software" + }, { + "id": "35", + "title": "Operating System", + "container": "0", + "const": "C__OBJTYPE__OPERATING_SYSTEM", + "color": "838683", + "image": "https://demo.example.com/i-doit/images/objecttypes/application.jpg", + "icon": "images/icons/silk/application_osx.png", + "cats": "20", + "tree_group": "1", + "status": "2", + "type_group": "1", + "type_group_title": "Software" + }, { + "id": "56", + "title": "Cluster services", + "container": "0", + "const": "C__OBJTYPE__CLUSTER_SERVICE", + "color": "B6BFC9", + "image": "https://demo.example.com/i-doit/images/objecttypes/application.jpg", + "icon": "images/icons/silk/application_cascade.png", + "cats": "58", + "tree_group": "1", + "status": "2", + "type_group": "1", + "type_group_title": "Software" + }, { + "id": "61", + "title": "DBMS", + "container": "0", + "const": "C__OBJTYPE__DBMS", + "color": "AAAAAA", + "image": "https://demo.example.com/i-doit/images/objecttypes/san.png", + "icon": "images/icons/silk/database.png", + "cats": "62", + "tree_group": "1", + "status": "2", + "type_group": "1", + "type_group_title": "Software" + }, { + "id": "62", + "title": "Database schema", + "container": "0", + "const": "C__OBJTYPE__DATABASE_SCHEMA", + "color": "B0C4DE", + "image": "https://demo.example.com/i-doit/images/objecttypes/application.jpg", + "icon": "images/icons/silk/database_table.png", + "cats": "60", + "tree_group": "1", + "status": "2", + "type_group": "1", + "type_group_title": "Software" + }, { + "id": "65", + "title": "Database instance", + "container": "0", + "const": "C__OBJTYPE__DATABASE_INSTANCE", + "color": "61C384", + "image": "https://demo.example.com/i-doit/images/objecttypes/service.jpg", + "icon": "images/icons/silk/database_connect.png", + "cats": "63", + "tree_group": "1", + "status": "2", + "type_group": "1", + "type_group_title": "Software" + }, { + "id": "66", + "title": "Middleware", + "container": "0", + "const": "C__OBJTYPE__MIDDLEWARE", + "color": "EEFFDE", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "middleware.png", + "cats": "75", + "tree_group": "1", + "status": "2", + "type_group": "1", + "type_group_title": "Software" + }, { + "id": "3", + "title": "Building", + "container": "1", + "const": "C__OBJTYPE__BUILDING", + "color": "D1695E", + "image": "https://demo.example.com/i-doit/images/objecttypes/building.png", + "icon": "images/icons/silk/building.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "4", + "title": "Rack", + "container": "1", + "const": "C__OBJTYPE__ENCLOSURE", + "color": "D3E3FA", + "image": "https://demo.example.com/i-doit/images/objecttypes/enclosure.png", + "icon": "images/icons/silk/timeline_marker_rotated.png", + "cats": "1", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "5", + "title": "Server", + "container": "0", + "const": "C__OBJTYPE__SERVER", + "color": "A2BCFA", + "image": "https://demo.example.com/i-doit/images/objecttypes/server.png", + "icon": "images/icons/silk/server.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "6", + "title": "Switch", + "container": "0", + "const": "C__OBJTYPE__SWITCH", + "color": "B8BED1", + "image": "https://demo.example.com/i-doit/images/objecttypes/switch.png", + "icon": "images/icons/silk/drive_network.png", + "cats": "5", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "7", + "title": "Router", + "container": "0", + "const": "C__OBJTYPE__ROUTER", + "color": "97D414", + "image": "https://demo.example.com/i-doit/images/objecttypes/router.png", + "icon": "images/icons/silk/drive_web.png", + "cats": "17", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "8", + "title": "FC switch", + "container": "0", + "const": "C__OBJTYPE__FC_SWITCH", + "color": "9FC380", + "image": "https://demo.example.com/i-doit/images/objecttypes/fcswitch.png", + "icon": "images/icons/silk/drive_network.png", + "cats": "16", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "9", + "title": "Storage system", + "container": "0", + "const": "C__OBJTYPE__SAN", + "color": "F0F0E3", + "image": "https://demo.example.com/i-doit/images/objecttypes/san.png", + "icon": "images/icons/silk/drive_cd_empty.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "10", + "title": "Client", + "container": "0", + "const": "C__OBJTYPE__CLIENT", + "color": "B9E1BE", + "image": "https://demo.example.com/i-doit/images/objecttypes/client.png", + "icon": "images/icons/silk/computer.png", + "cats": "15", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "11", + "title": "Printer", + "container": "0", + "const": "C__OBJTYPE__PRINTER", + "color": "4E93BE", + "image": "https://demo.example.com/i-doit/images/objecttypes/printer.png", + "icon": "images/icons/silk/printer.png", + "cats": "18", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "12", + "title": "Air Condition System", + "container": "0", + "const": "C__OBJTYPE__AIR_CONDITION_SYSTEM", + "color": "A88AA7", + "image": "https://demo.example.com/i-doit/images/objecttypes/aircond.png", + "icon": "klima.gif", + "cats": "9", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "19", + "title": "KVM switch", + "container": "0", + "const": "C__OBJTYPE__KVM_SWITCH", + "color": "7EDF8D", + "image": "https://demo.example.com/i-doit/images/objecttypes/router.png", + "icon": "images/icons/silk/image_link.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "22", + "title": "Monitor", + "container": "0", + "const": "C__OBJTYPE__MONITOR", + "color": "DCE0D7", + "image": "https://demo.example.com/i-doit/images/objecttypes/monitor.png", + "icon": "images/icons/silk/monitor.png", + "cats": "14", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "23", + "title": "Appliance", + "container": "0", + "const": "C__OBJTYPE__APPLIANCE", + "color": "6EAEBF", + "image": "https://demo.example.com/i-doit/images/objecttypes/appliances.png", + "icon": "images/icons/silk/drive_disk.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "24", + "title": "Telephone system", + "container": "0", + "const": "C__OBJTYPE__TELEPHONE_SYSTEM", + "color": "DDEFFC", + "image": "https://demo.example.com/i-doit/images/objecttypes/phonesys.png", + "icon": "images/icons/silk/telephone_link.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "25", + "title": "Printbox", + "container": "0", + "const": "C__OBJTYPE__PRINTBOX", + "color": "90AD8B", + "image": "https://demo.example.com/i-doit/images/objecttypes/printerbox.png", + "icon": "images/icons/silk/printer_empty.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "26", + "title": "Room", + "container": "1", + "const": "C__OBJTYPE__ROOM", + "color": "E4FF9E", + "image": "https://demo.example.com/i-doit/images/objecttypes/room.png", + "icon": "room.gif", + "cats": "3", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "27", + "title": "Wireless Access Point", + "container": "0", + "const": "C__OBJTYPE__ACCESS_POINT", + "color": "C5C8B4", + "image": "https://demo.example.com/i-doit/images/objecttypes/wlan.jpg", + "icon": "images/icons/silk/television.png", + "cats": "13", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "38", + "title": "Phone", + "container": "0", + "const": "C__OBJTYPE__PHONE", + "color": "6886B4", + "image": "https://demo.example.com/i-doit/images/objecttypes/phone.png", + "icon": "images/icons/silk/telephone.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "39", + "title": "Host", + "container": "0", + "const": "C__OBJTYPE__HOST", + "color": "DADA5E", + "image": "https://demo.example.com/i-doit/images/objecttypes/server.png", + "icon": "images/icons/silk/server.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "40", + "title": "Cable", + "container": "0", + "const": "C__OBJTYPE__CABLE", + "color": "B39E92", + "image": "https://demo.example.com/i-doit/images/objecttypes/fcswitch.png", + "icon": "kabel.gif", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "41", + "title": "Converter", + "container": "0", + "const": "C__OBJTYPE__CONVERTER", + "color": "CAB97D", + "image": "https://demo.example.com/i-doit/images/objecttypes/fcswitch.png", + "icon": "images/icons/silk/connect.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "42", + "title": "Wiring System", + "container": "0", + "const": "C__OBJTYPE__WIRING_SYSTEM", + "color": "D1695E", + "image": "https://demo.example.com/i-doit/images/objecttypes/fcswitch.png", + "icon": "images/icons/silk/text_letter_omega.png", + "cats": "40", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "43", + "title": "Patch Panel", + "container": "0", + "const": "C__OBJTYPE__PATCH_PANEL", + "color": "BCDCB9", + "image": "https://demo.example.com/i-doit/images/objecttypes/switch.png", + "icon": "images/icons/silk/drive_rename_dotted.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "44", + "title": "Amplifier", + "container": "0", + "const": "C__OBJTYPE__AMPLIFIER", + "color": "AF7FF1", + "image": "https://demo.example.com/i-doit/images/objecttypes/appliances.png", + "icon": "verstaerker.gif", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "46", + "title": "Electric power company", + "container": "0", + "const": "C__OBJTYPE__ESC", + "color": "EB8348", + "image": "https://demo.example.com/i-doit/images/objecttypes/power.jpg", + "icon": "images/icons/silk/lightbulb.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "47", + "title": "Emergency power supply", + "container": "0", + "const": "C__OBJTYPE__EPS", + "color": "E1E79E", + "image": "https://demo.example.com/i-doit/images/objecttypes/power.jpg", + "icon": "nea.gif", + "cats": "43", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "48", + "title": "Distribution box", + "container": "0", + "const": "C__OBJTYPE__DISTRIBUTION_BOX", + "color": "A5EEA0", + "image": "https://demo.example.com/i-doit/images/objecttypes/power.jpg", + "icon": "verteiler.gif", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "49", + "title": "Power distribution unit", + "container": "0", + "const": "C__OBJTYPE__PDU", + "color": "43CBE1", + "image": "https://demo.example.com/i-doit/images/objecttypes/power.jpg", + "icon": "pdu.gif", + "cats": "64", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "50", + "title": "Uninterruptible power supply", + "container": "0", + "const": "C__OBJTYPE__UPS", + "color": "FDD84E", + "image": "https://demo.example.com/i-doit/images/objecttypes/power.jpg", + "icon": "images/icons/silk/lightning.png", + "cats": "42", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "57", + "title": "Virtual client", + "container": "0", + "const": "C__OBJTYPE__VIRTUAL_CLIENT", + "color": "9FAA7C", + "image": "https://demo.example.com/i-doit/images/objecttypes/client.png", + "icon": "images/icons/silk/computer_link.png", + "cats": "15", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "58", + "title": "Virtual host", + "container": "0", + "const": "C__OBJTYPE__VIRTUAL_HOST", + "color": "E6E9DC", + "image": "https://demo.example.com/i-doit/images/objecttypes/server.png", + "icon": "images/icons/silk/server_database.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "59", + "title": "Virtual server", + "container": "0", + "const": "C__OBJTYPE__VIRTUAL_SERVER", + "color": "6D7F92", + "image": "https://demo.example.com/i-doit/images/objecttypes/server.png", + "icon": "images/icons/silk/server_chart.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "64", + "title": "Replication object", + "container": "0", + "const": "C__OBJTYPE__REPLICATION", + "color": "C9BAEF", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/icons/silk/arrow_branch.png", + "cats": "71", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "71", + "title": "Workplace", + "container": "0", + "const": "C__OBJTYPE__WORKSTATION", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/client.png", + "icon": "images/icons/silk/drive_user.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "73", + "title": "Switch chassis", + "container": "1", + "const": "C__OBJTYPE__SWITCH_CHASSIS", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/enclosure.png", + "icon": "images/icons/silk/timeline_marker.png", + "cats": "84", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "74", + "title": "Blade chassis", + "container": "1", + "const": "C__OBJTYPE__BLADE_CHASSIS", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/enclosure.png", + "icon": "images/icons/silk/timeline_marker.png", + "cats": "84", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "75", + "title": "Blade server", + "container": "0", + "const": "C__OBJTYPE__BLADE_SERVER", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/server.png", + "icon": "images/icons/silk/drive.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "76", + "title": "VoIP telephone", + "container": "0", + "const": "C__OBJTYPE__VOIP_PHONE", + "color": "FF8800", + "image": "https://demo.example.com/i-doit/images/objecttypes/phone.png", + "icon": "images/icons/silk/phone_sound.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "84", + "title": "Country", + "container": "1", + "const": "C__OBJTYPE__COUNTRY", + "color": "ACE177", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/icons/silk/map.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "85", + "title": "City", + "container": "1", + "const": "C__OBJTYPE__CITY", + "color": "DFB0E1", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/icons/city.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "88", + "title": "Remote Management Controller", + "container": "0", + "const": "C__OBJTYPE__RM_CONTROLLER", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/", + "icon": "images/icons/silk/bullet_picture.png", + "tree_group": "2", + "status": "2", + "type_group": "2", + "type_group_title": "Infrastructure" + }, { + "id": "13", + "title": "WAN", + "container": "0", + "const": "C__OBJTYPE__WAN", + "color": "BAE1D2", + "image": "https://demo.example.com/i-doit/images/objecttypes/router.png", + "icon": "images/icons/silk/weather_clouds.png", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "14", + "title": "Emergency plan", + "container": "0", + "const": "C__OBJTYPE__EMERGENCY_PLAN", + "color": "C4FFF9", + "image": "https://demo.example.com/i-doit/images/objecttypes/emergency.jpg", + "icon": "images/icons/silk/text_horizontalrule.png", + "cats": "8", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "28", + "title": "Contract", + "container": "0", + "const": "C__OBJTYPE__MAINTENANCE", + "color": "7AD3C6", + "image": "https://demo.example.com/i-doit/images/objecttypes/maintenance.jpg", + "icon": "images/icons/silk/text_signature.png", + "cats": "81", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "29", + "title": "File", + "container": "0", + "const": "C__OBJTYPE__FILE", + "color": "CDFCF6", + "image": "https://demo.example.com/i-doit/images/objecttypes/application.jpg", + "icon": "images/icons/silk/disk.png", + "cats": "19", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "31", + "title": "Layer 3-Net", + "container": "0", + "const": "C__OBJTYPE__LAYER3_NET", + "color": "7EE0EB", + "image": "https://demo.example.com/i-doit/images/objecttypes/wlan.jpg", + "icon": "images/icons/silk/world_link.png", + "cats": "22", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "32", + "title": "Cellular Phone", + "container": "0", + "const": "C__OBJTYPE__CELL_PHONE_CONTRACT", + "color": "F2F3BA", + "image": "https://demo.example.com/i-doit/images/objecttypes/appliances.png", + "icon": "images/icons/silk/phone.png", + "cats": "23", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "36", + "title": "Object group", + "container": "0", + "const": "C__OBJECT_TYPE__GROUP", + "color": "E1B9DC", + "image": "https://demo.example.com/i-doit/images/objecttypes/printerbox.jpg", + "icon": "images/icons/silk/sitemap_color.png", + "cats": "25", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "45", + "title": "Service", + "container": "0", + "const": "C__OBJTYPE__IT_SERVICE", + "color": "C7F464", + "image": "https://demo.example.com/i-doit/images/objecttypes/service.jpg", + "icon": "images/icons/silk/chart_pie.png", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "51", + "title": "SAN Zoning", + "container": "0", + "const": "C__OBJTYPE__SAN_ZONING", + "color": "DDE143", + "image": "https://demo.example.com/i-doit/images/objecttypes/san.png", + "icon": "images/icons/silk/layers.png", + "cats": "44", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "55", + "title": "Cluster", + "container": "0", + "const": "C__OBJTYPE__CLUSTER", + "color": "9FAAB7", + "image": "https://demo.example.com/i-doit/images/objecttypes/server.png", + "icon": "images/icons/silk/application_cascade.png", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "68", + "title": "Crypto card", + "container": "0", + "const": "C__OBJTYPE__KRYPTO_CARD", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/application.jpg", + "icon": "images/icons/silk/page_white_key.png", + "cats": "76", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "69", + "title": "SIM card", + "container": "0", + "const": "C__OBJTYPE__SIM_CARD", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/application.jpg", + "icon": "images/icons/silk/page_white_database.png", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "70", + "title": "Layer 2 Net", + "container": "0", + "const": "C__OBJTYPE__LAYER2_NET", + "color": "7EE0EB", + "image": "https://demo.example.com/i-doit/images/objecttypes/fcswitch.png", + "icon": "images/icons/silk/page_white_gear.png", + "cats": "79", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "77", + "title": "Supernet", + "container": "1", + "const": "C__OBJTYPE__SUPERNET", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/wlan.jpg", + "icon": "images/icons/silk/world.png", + "cats": "22", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "81", + "title": "Vehicle", + "container": "0", + "const": "C__OBJTYPE__VEHICLE", + "color": "83C5E1", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/icons/silk/car.png", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "82", + "title": "Aircraft", + "container": "0", + "const": "C__OBJTYPE__AIRCRAFT", + "color": "479FC4", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/icons/airplane.png", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "83", + "title": "VRRP/HSRP Cluster", + "container": "0", + "const": "C__OBJTYPE__CLUSTER_VRRP_HSRP", + "color": "9FAAB7", + "image": "https://demo.example.com/i-doit/images/objecttypes/server.png", + "icon": "images/icons/silk/application_cascade.png", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "89", + "title": "VRRP", + "container": "0", + "const": "C__OBJTYPE__VRRP", + "color": "ABCDEF", + "image": "https://demo.example.com/i-doit/images/objecttypes/switch.png", + "icon": "images/icons/silk/disconnect.png", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "90", + "title": "Stacking", + "container": "0", + "const": "C__OBJTYPE__STACKING", + "color": "FEDCBA", + "image": "https://demo.example.com/i-doit/images/objecttypes/switch.png", + "icon": "images/icons/silk/drive_stack.png", + "tree_group": "3", + "status": "2", + "type_group": "3", + "type_group_title": "Other" + }, { + "id": "52", + "title": "Organization", + "container": "0", + "const": "C__OBJTYPE__ORGANIZATION", + "color": "82E27E", + "image": "https://demo.example.com/i-doit/images/objecttypes/building.png", + "icon": "images/icons/silk/sitemap.png", + "cats": "45", + "tree_group": "1000", + "status": "2", + "type_group": "1000", + "type_group_title": "Contact" + }, { + "id": "53", + "title": "Persons", + "container": "0", + "const": "C__OBJTYPE__PERSON", + "color": "EFAA43", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/tree/person_intern.gif", + "cats": "48", + "tree_group": "1000", + "status": "2", + "type_group": "1000", + "type_group_title": "Contact" + }, { + "id": "54", + "title": "Person groups", + "container": "0", + "const": "C__OBJTYPE__PERSON_GROUP", + "color": "F3FFEF", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/tree/group.gif", + "cats": "52", + "tree_group": "1000", + "status": "2", + "type_group": "1000", + "type_group_title": "Contact" + }, { + "id": "78", + "title": "Nagios service", + "container": "0", + "const": "C__OBJTYPE__NAGIOS_SERVICE", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/icons/silk/database.png", + "tree_group": "1001", + "status": "2", + "type_group": "1001", + "type_group_title": "Nagios" + }, { + "id": "79", + "title": "Nagios service-template", + "container": "0", + "const": "C__OBJTYPE__NAGIOS_SERVICE_TPL", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/icons/silk/database.png", + "tree_group": "1001", + "status": "2", + "type_group": "1001", + "type_group_title": "Nagios" + }, { + "id": "80", + "title": "Nagios host-template", + "container": "0", + "const": "C__OBJTYPE__NAGIOS_HOST_TPL", + "color": "FFFFFF", + "image": "https://demo.example.com/i-doit/images/objecttypes/empty.png", + "icon": "images/icons/silk/database.png", + "tree_group": "1001", + "status": "2", + "type_group": "1001", + "type_group_title": "Nagios" + }], + "id": 1 +} \ No newline at end of file diff --git a/test/integration/idoit_controller_test.rb b/test/integration/idoit_controller_test.rb new file mode 100644 index 000000000..f7d376066 --- /dev/null +++ b/test/integration/idoit_controller_test.rb @@ -0,0 +1,191 @@ +# encoding: utf-8 +require 'test_helper' +require 'webmock/minitest' + +class IdoitControllerTest < ActionDispatch::IntegrationTest + setup do + + stub_request(:any, 'https://images.zammad.com/api/v1/person/image') + .to_return(status: 404, body: '', headers: {}) + + @token = 'some_token' + @endpoint = 'https://idoit.example.com/i-doit/' + + @headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' } + + Setting.set('idoit_integration', true) + Setting.set('idoit_config', { + api_token: @token, + endpoint: @endpoint, + client_id: '', + }) + groups = Group.where(name: 'Users') + roles = Role.where(name: %w(Agent)) + agent = User.create_or_update( + login: 'idoit-agent@example.com', + firstname: 'E', + lastname: 'S', + email: 'idoit-agent@example.com', + password: 'agentpw', + active: true, + roles: roles, + groups: groups, + updated_by_id: 1, + created_by_id: 1, + ) + roles = Role.where(name: %w(Agent Admin)) + admin = User.create_or_update( + login: 'idoit-admin@example.com', + firstname: 'E', + lastname: 'S', + email: 'idoit-admin@example.com', + password: 'adminpw', + active: true, + roles: roles, + groups: groups, + updated_by_id: 1, + created_by_id: 1, + ) + + customer1 = User.create_or_update( + login: 'ticket-idoit-customer1@example.com', + firstname: 'CallerId', + lastname: 'Customer1', + email: 'ticket-idoit-customer1@example.com', + password: 'customerpw', + active: true, + updated_by_id: 1, + created_by_id: 1, + ) + + end + + test 'unclear urls' do + + agent_credentials = ActionController::HttpAuthentication::Basic.encode_credentials('idoit-agent@example.com', 'agentpw') + params = { + api_token: @token, + endpoint: @endpoint, + client_id: '', + } + post '/api/v1/integration/idoit/verify', params: params.to_json, headers: @headers.merge('Authorization' => agent_credentials) + assert_response(401) + result = JSON.parse(@response.body) + assert_equal(Hash, result.class) + assert_not(result.blank?) + assert_equal('Not authorized (user)!', result['error']) + + stub_request(:post, "#{@endpoint}src/jsonrpc.php") + .with(body: "{\"method\":\"cmdb.object_types\",\"params\":{\"apikey\":\"#{@token}\"},\"version\":\"2.0\"}") + .to_return(status: 200, body: read_messaage('object_types_response'), headers: {}) + + admin_credentials = ActionController::HttpAuthentication::Basic.encode_credentials('idoit-admin@example.com', 'adminpw') + params = { + api_token: @token, + endpoint: @endpoint, + client_id: '', + } + post '/api/v1/integration/idoit/verify', params: params.to_json, headers: @headers.merge('Authorization' => admin_credentials) + assert_response(200) + result = JSON.parse(@response.body) + assert_equal(Hash, result.class) + assert_not(result.blank?) + assert_equal('ok', result['result']) + assert(result['response']) + assert_equal('2.0', result['response']['jsonrpc']) + assert(result['response']['result']) + + params = { + api_token: @token, + endpoint: " #{@endpoint}/", + client_id: '', + } + post '/api/v1/integration/idoit/verify', params: params.to_json, headers: @headers.merge('Authorization' => admin_credentials) + assert_response(200) + result = JSON.parse(@response.body) + assert_equal(Hash, result.class) + assert_not(result.blank?) + assert_equal('ok', result['result']) + assert(result['response']) + assert_equal('2.0', result['response']['jsonrpc']) + assert(result['response']['result']) + + end + + test 'list all object types' do + + stub_request(:post, "#{@endpoint}src/jsonrpc.php") + .with(body: "{\"method\":\"cmdb.object_types\",\"params\":{\"apikey\":\"#{@token}\"},\"version\":\"2.0\"}") + .to_return(status: 200, body: read_messaage('object_types_response'), headers: {}) + + agent_credentials = ActionController::HttpAuthentication::Basic.encode_credentials('idoit-agent@example.com', 'agentpw') + params = { + method: 'cmdb.object_types', + } + post '/api/v1/integration/idoit', params: params.to_json, headers: @headers.merge('Authorization' => agent_credentials) + assert_response(200) + + result = JSON.parse(@response.body) + assert_equal(Hash, result.class) + assert_not(result.blank?) + assert_equal('ok', result['result']) + assert(result['response']) + assert_equal('2.0', result['response']['jsonrpc']) + assert(result['response']['result']) + assert_equal('1', result['response']['result'][0]['id']) + assert_equal('System service', result['response']['result'][0]['title']) + + admin_credentials = ActionController::HttpAuthentication::Basic.encode_credentials('idoit-admin@example.com', 'adminpw') + params = { + method: 'cmdb.object_types', + } + post '/api/v1/integration/idoit', params: params.to_json, headers: @headers.merge('Authorization' => admin_credentials) + assert_response(200) + + result = JSON.parse(@response.body) + assert_equal(Hash, result.class) + assert_not(result.blank?) + assert_equal('ok', result['result']) + assert(result['response']) + assert_equal('2.0', result['response']['jsonrpc']) + assert(result['response']['result']) + assert_equal('1', result['response']['result'][0]['id']) + assert_equal('System service', result['response']['result'][0]['title']) + + end + + test 'query objects' do + + stub_request(:post, "#{@endpoint}src/jsonrpc.php") + .with(body: "{\"method\":\"cmdb.objects\",\"params\":{\"apikey\":\"#{@token}\",\"filter\":{\"ids\":[\"33\"]}},\"version\":\"2.0\"}") + .to_return(status: 200, body: read_messaage('object_types_filter_response'), headers: {}) + + agent_credentials = ActionController::HttpAuthentication::Basic.encode_credentials('idoit-agent@example.com', 'agentpw') + params = { + method: 'cmdb.objects', + filter: { + ids: ['33'] + }, + } + post '/api/v1/integration/idoit', params: params.to_json, headers: @headers.merge('Authorization' => agent_credentials) + assert_response(200) + + result = JSON.parse(@response.body) + assert_equal(Hash, result.class) + assert_not(result.blank?) + assert_equal('ok', result['result']) + assert(result['response']) + assert_equal('2.0', result['response']['jsonrpc']) + assert(result['response']['result']) + assert_equal('26', result['response']['result'][0]['id']) + assert_equal('demo.example.com', result['response']['result'][0]['title']) + assert_equal('Virtual server', result['response']['result'][0]['type_title']) + assert_equal('in operation', result['response']['result'][0]['cmdb_status_title']) + + end + + def read_messaage(file) + File.read("test/fixtures/idoit/#{file}.json") + end + +end