Class: Aikido::Zen::Request::HeuristicRouter::SecretMatcher
- Inherits:
-
Object
- Object
- Aikido::Zen::Request::HeuristicRouter::SecretMatcher
- Defined in:
- lib/aikido/zen/request/heuristic_router.rb
Constant Summary collapse
- MIN_LENGTH =
10
- SECRET_THRESHOLD =
0.75
- LOWER =
/[[:lower:]]/
- UPPER =
/[[:upper:]]/
- DIGIT =
/[[:digit:]]/
- SPECIAL =
/[!#\$%^&*|;:<>]/
- SEPARATORS =
/[[:space:]]|-/
Class Method Summary collapse
-
.===(candidate) ⇒ Boolean
Decides if a given string looks random enough to be a “secret”.
Instance Method Summary collapse
Class Method Details
.===(candidate) ⇒ Boolean
Decides if a given string looks random enough to be a “secret”.
78 79 80 |
# File 'lib/aikido/zen/request/heuristic_router.rb', line 78 def self.===(candidate) new(candidate).matches? end |
Instance Method Details
#matches? ⇒ Boolean
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/aikido/zen/request/heuristic_router.rb', line 86 def matches? return false if @string.size <= MIN_LENGTH return false if SEPARATORS === @string return false unless DIGIT === @string return false if [LOWER, UPPER, SPECIAL].none? { |pattern| pattern === @string } ratios = @string.chars.each_cons(MIN_LENGTH).map do |window| window.to_set.size / MIN_LENGTH.to_f end ratios.sum / ratios.size > SECRET_THRESHOLD end |