From 7496653f6d19d8b5ee55614770e9558c90dff297 Mon Sep 17 00:00:00 2001 From: Mitchell Henke Date: Fri, 25 Oct 2024 09:39:53 -0500 Subject: [PATCH 1/2] Remove OpenStruct usage --- lib/zxcvbn.rb | 14 +++++++++++++- spec/zxcvbn_spec.rb | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/zxcvbn.rb b/lib/zxcvbn.rb index ba7a7f7..f142359 100644 --- a/lib/zxcvbn.rb +++ b/lib/zxcvbn.rb @@ -10,6 +10,18 @@ module Zxcvbn class Error < StandardError; end + Result = Struct.new( + :password, + :guesses, + :guesses_log10, + :sequence, + :calc_time, + :crack_times_seconds, + :crack_times_display, + :score, + :feedback, + keyword_init: true, + ) def self.zxcvbn(password, user_inputs = []) start = (Time.now.to_f * 1000).to_i @@ -25,7 +37,7 @@ def self.zxcvbn(password, user_inputs = []) end def self.test(password, user_inputs = []) - OpenStruct.new(Zxcvbn.zxcvbn(password, user_inputs)) # rubocop:disable Style/OpenStructUse + Result.new(Zxcvbn.zxcvbn(password, user_inputs)) end class Tester diff --git a/spec/zxcvbn_spec.rb b/spec/zxcvbn_spec.rb index 97c76b8..6e7746c 100644 --- a/spec/zxcvbn_spec.rb +++ b/spec/zxcvbn_spec.rb @@ -236,9 +236,9 @@ normal_result = Zxcvbn.zxcvbn("@lfred2004", ["alfred"]).reject { |k, _v| ["calc_time"].include? k } result1 = Zxcvbn.test("@lfred2004", ["alfred"]) result2 = Zxcvbn::Tester.new.test("@lfred2004", ["alfred"]) - expect(result1).to be_a(OpenStruct) # rubocop:disable Style/OpenStructUse + expect(result1).to be_a(Zxcvbn::Result) expect(result1.to_h.transform_keys(&:to_s).reject { |k, _v| ["calc_time"].include? k }).to eq(normal_result) - expect(result2).to be_a(OpenStruct) # rubocop:disable Style/OpenStructUse + expect(result2).to be_a(Zxcvbn::Result) expect(result2.to_h.transform_keys(&:to_s).reject { |k, _v| ["calc_time"].include? k }).to eq(normal_result) end end From 6a5159c75af7df29c5f3e4766c7e41f0dfb4730c Mon Sep 17 00:00:00 2001 From: Rafael Santos Date: Tue, 29 Oct 2024 22:24:46 +1300 Subject: [PATCH 2/2] fix rubocop warning --- lib/zxcvbn.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zxcvbn.rb b/lib/zxcvbn.rb index f142359..c2eb8ee 100644 --- a/lib/zxcvbn.rb +++ b/lib/zxcvbn.rb @@ -20,7 +20,7 @@ class Error < StandardError; end :crack_times_display, :score, :feedback, - keyword_init: true, + keyword_init: true ) def self.zxcvbn(password, user_inputs = [])