Skip to content

Commit

Permalink
fix(storage): use securerandom to generate aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Dec 20, 2024
1 parent a108175 commit b12898a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion service/lib/agama/storage/configs/with_alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions service/test/agama/storage/config_solver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b12898a

Please sign in to comment.