rapid7 / metasploit-framework

Metasploit Framework
https://www.metasploit.com/
Other
34.23k stars 14k forks source link

Make enum options case normalizing #19660

Open zeroSteiner opened 4 days ago

zeroSteiner commented 4 days ago

This closes #19450 by introducing changes to the #valid? and #normalize methods of the OptEnum class to make it case-insensitive. This should make it slightly easier for users to set opinions by not having to remember the exact casing of opinion values. As a good example, the ldap_query module has an OUTPUT_FORMAT with options of csv and json. Since those words are acronyms and common file extensions, either csv or CSV would make sense in the context. Now users don't need to remember that exact detail. The casing of the option is normalized to what the module author specified though, so the value can still be matched exactly in the module code.

Testing

Demo

Old:

metasploit-framework (S:0 J:0) auxiliary(gather/ldap_query) > set OUTPUT_FORMAT CSV
[-] The following options failed to validate: Value 'CSV' is not valid for option 'OUTPUT_FORMAT'.
OUTPUT_FORMAT => table
metasploit-framework (S:0 J:0) auxiliary(gather/ldap_query) >

New:

metasploit-framework (S:0 J:0) auxiliary(gather/ldap_query) > set OUTPUT_FORMAT CSV
OUTPUT_FORMAT => csv
metasploit-framework (S:0 J:0) auxiliary(gather/ldap_query) >