Project

General

Profile

Actions

Bug #16657

closed

No validation for Discovery Rule name

Added by Swapnil Abnave over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Category:
Discovery plugin
Difficulty:
trivial
Triaged:
Fixed in Releases:
Found in Releases:

Description

Description of problem:
Discovery Rule with name that is longer than 255 characters should not be created.

Actual results:
Discovery rule is created successfully

Expected results:
Error message ("is too long (maximum is 255 characters)") should be displayed

Actions #1

Updated by Swapnil Abnave over 7 years ago

`discovery_rules` table description from discovery_plugin version 5.0.0.9

                                                          Table "public.discovery_rules" 
    Column    |            Type             |                          Modifiers                           | Storage  | Stats target | Description 
--------------+-----------------------------+--------------------------------------------------------------+----------+--------------+-------------
 id           | integer                     | not null default nextval('discovery_rules_id_seq'::regclass) | plain    |              | 
 name         | character varying(255)      |                                                              | extended |              | 
 search       | character varying(255)      |                                                              | extended |              | 
 hostgroup_id | integer                     | not null                                                     | plain    |              | 
 hostname     | character varying(255)      | default ''::character varying                                | extended |              | 
 max_count    | integer                     | default 0                                                    | plain    |              | 
 priority     | integer                     | default 0                                                    | plain    |              | 
 enabled      | boolean                     | not null default true                                        | plain    |              | 
 created_at   | timestamp without time zone |                                                              | plain    |              | 
 updated_at   | timestamp without time zone |                                                              | plain    |              | 
Indexes:
    "discovery_rules_pkey" PRIMARY KEY, btree (id)
Has OIDs: no

Latest table description for `discovery_rules`

katello=# \d+ discovery_rules
                                                          Table "public.discovery_rules" 
    Column    |            Type             |                          Modifiers                           | Storage  | Stats target | Description 
--------------+-----------------------------+--------------------------------------------------------------+----------+--------------+-------------
 id           | integer                     | not null default nextval('discovery_rules_id_seq'::regclass) | plain    |              | 
 name         | character varying           |                                                              | extended |              | 
 search       | character varying           |                                                              | extended |              | 
 hostgroup_id | integer                     | not null                                                     | plain    |              | 
 hostname     | character varying           | default ''::character varying                                | extended |              | 
 max_count    | integer                     | default 0                                                    | plain    |              | 
 priority     | integer                     | default 0                                                    | plain    |              | 
 enabled      | boolean                     | not null default true                                        | plain    |              | 
 created_at   | timestamp without time zone |                                                              | plain    |              | 
 updated_at   | timestamp without time zone |                                                              | plain    |              | 
Indexes:
    "discovery_rules_pkey" PRIMARY KEY, btree (id)
Has OIDs: no

As you can see the limits for columns name,search, hostname have been dropped in latest version. This is causing [validates_lengths_from_database[https://github.com/theforeman/foreman_discovery/blob/develop/app/models/discovery_rule.rb#L16]] to have no effect on length validation of model `DiscoveryRule`.

I am working on finding the reason the reason. But not able to get it, does anyone have idea about it ?

I searched in foreman, foreman_discovery plugins.. no luck.

Actions #2

Updated by Dominic Cleal over 7 years ago

  • translation missing: en.field_release deleted (189)
Actions #4

Updated by Swapnil Abnave over 7 years ago

Dominic Cleal wrote:

The default string length changed in 1.12: http://projects.theforeman.org/projects/foreman/wiki/Rails_42#String-limits

Ahh... Thanks Dominic. I wasn't knowing that.

To some extent, it makes sense : https://github.com/rails/rails/pull/14579

Do you think that adding limit would take performance hit in this scenario(of discovery_rule).

Actions #6

Updated by The Foreman Bot over 7 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman_discovery/pull/302 added
Actions #7

Updated by Swapnil Abnave over 7 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100
Actions

Also available in: Atom PDF