OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Make LoginToken generation frozen string compatible
Jan Sandbrink54055ffa5b15
diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication/login_token.rb b/modules/two_factor_authentication/app/models/two_factor_authentication/login_token.rbindex 4ce92b14236..2856a6952be 100644--- a/modules/two_factor_authentication/app/models/two_factor_authentication/login_token.rb+++ b/modules/two_factor_authentication/app/models/two_factor_authentication/login_token.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+module TwoFactorAuthenticationclass LoginToken < ::Token::HashedTokeninclude ::Token::ExpirableToken@@ -8,9 +10,7 @@ module TwoFactorAuthenticationdef self.generate_token_valuechars = ("0".."9").to_a- password = ""- 6.times { |_i| password << chars[rand(chars.size - 1)] }- password+ Array.new(6) { chars[SecureRandom.rand(chars.size)] }.joinendendenddiff --git a/modules/two_factor_authentication/spec/models/login_token_spec.rb b/modules/two_factor_authentication/spec/models/login_token_spec.rbindex ad5d37d8744..0993139166b 100644--- a/modules/two_factor_authentication/spec/models/login_token_spec.rb+++ b/modules/two_factor_authentication/spec/models/login_token_spec.rb@@ -25,4 +25,21 @@ RSpec.describe TwoFactorAuthentication::LoginToken, :with_2fa_ee doexpect(described_class.find_by(id: token.id)).to be_nilexpect(described_class.find(new_token.id)).not_to be_nilend++ describe ".generate_token_value" do+ subject { described_class.generate_token_value }++ it "generates tokens consisting of 6 numerical digits" do+ expect(subject).to match(/\A[0-9]{6}\z/)+ end++ it "generates tokens that can contain any digit (regression test)" do+ generated_digits = ""+ 100.times { generated_digits += described_class.generate_token_value }++ (0..9).each do |digit|+ expect(generated_digits).to include(digit.to_s)+ end+ end+ endend