From b12898aec87d722e01471b6deff03a2958f38c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 20 Dec 2024 09:35:41 +0000 Subject: [PATCH] fix(storage): use securerandom to generate aliases --- service/lib/agama/storage/configs/with_alias.rb | 4 +++- service/test/agama/storage/config_solver_test.rb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/service/lib/agama/storage/configs/with_alias.rb b/service/lib/agama/storage/configs/with_alias.rb index dba901e495..250d8d93e0 100644 --- a/service/lib/agama/storage/configs/with_alias.rb +++ b/service/lib/agama/storage/configs/with_alias.rb @@ -19,6 +19,8 @@ # To contact SUSE LLC about this file by physical or electronic mail, you may # find current contact information at www.suse.com. +require "securerandom" + module Agama module Storage module Configs @@ -36,7 +38,7 @@ def alias?(value) # Ensures the config has a value for alias. def ensure_alias - self.alias ||= "device#{rand(10**9)}" + self.alias ||= SecureRandom.alphanumeric(10) end end end diff --git a/service/test/agama/storage/config_solver_test.rb b/service/test/agama/storage/config_solver_test.rb index 84cda9055f..3592f57e61 100644 --- a/service/test/agama/storage/config_solver_test.rb +++ b/service/test/agama/storage/config_solver_test.rb @@ -149,7 +149,7 @@ it "sets an alias to the root drive" do subject.solve(config) drive = config.drives.first - expect(drive.alias).to match(/device\d*/) + expect(drive.alias).to_not be_nil end it "sets the alias of root drive as boot device alias" do @@ -200,7 +200,7 @@ it "sets an alias to the drive" do subject.solve(config) drive = config.drives.find { |d| d.search.name == "/dev/vda" } - expect(drive.alias).to match(/device\d*/) + expect(drive.alias).to_not be_nil end it "sets the alias of the drive as boot device alias" do