-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously lots of unit names like ``` this is a service with spaces in.service ``` were permitted for instance. From systemd.unit > Valid unit names consist of a "name prefix" and a dot and a suffix specifying the unit type. The "unit prefix" must consist of one or more valid characters (ASCII letters, digits, ":", "-", "_", ".", and "\"). The total length of the unit name including the suffix must not exceed 256 characters. The type suffix must be one of ".service", ".socket", ".device", ".mount", ".automount", ".swap", ".target", ".path", ".timer", ".slice", or ".scope". in addition we allow `@` to cover the case of template or template instance.
- Loading branch information
1 parent
673cbc9
commit 9867823
Showing
3 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Systemd::Unit' do | ||
context 'with a permitted unit name' do | ||
[ | ||
'foo.service', | ||
'foo.socket', | ||
'atemplate@.service', | ||
'atemplate@instance.service', | ||
'backward\slash.swap', | ||
'extra.dot.scope', | ||
'a:colon.path', | ||
'an_underscore.device', | ||
'a-dash.slice', | ||
].each do |unit| | ||
it { is_expected.to allow_value(unit.to_s) } | ||
end | ||
end | ||
|
||
context 'with a illegal unit name' do | ||
[ | ||
'a space.service', | ||
'noending', | ||
'wrong.ending', | ||
'forward/slash.unit', | ||
].each do |unit| | ||
it { is_expected.not_to allow_value(unit.to_s) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# @summary custom datatype that validates different filenames for systemd units | ||
type Systemd::Unit = Pattern['^[^/]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$'] | ||
# @summary custom datatype that validates different filenames for systemd units and unit templates | ||
# @see https://www.freedesktop.org/software/systemd/man/systemd.unit.html | ||
type Systemd::Unit = Pattern[/^[[a-z][A-Z][0-9]:\-_.\\@]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/] | ||
|