pkg: idtools: fix subid files parsing
Since Docker is already skipping newlines in /etc/sub{uid,gid}, this patch skips commented out lines - otherwise Docker fails to start. Add unit test also. Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
366b774b47
commit
7e132eee02
2 changed files with 29 additions and 1 deletions
|
@ -171,7 +171,7 @@ func parseSubidFile(path, username string) (ranges, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
text := strings.TrimSpace(s.Text())
|
text := strings.TrimSpace(s.Text())
|
||||||
if text == "" {
|
if text == "" || strings.HasPrefix(text, "#") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
parts := strings.Split(text, ":")
|
parts := strings.Split(text, ":")
|
||||||
|
|
|
@ -241,3 +241,31 @@ func compareTrees(left, right map[string]node) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseSubidFileWithNewlinesAndComments(t *testing.T) {
|
||||||
|
tmpDir, err := ioutil.TempDir("", "parsesubid")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
fnamePath := filepath.Join(tmpDir, "testsubuid")
|
||||||
|
fcontent := `tss:100000:65536
|
||||||
|
# empty default subuid/subgid file
|
||||||
|
|
||||||
|
dockremap:231072:65536`
|
||||||
|
if err := ioutil.WriteFile(fnamePath, []byte(fcontent), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ranges, err := parseSubidFile(fnamePath, "dockremap")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(ranges) != 1 {
|
||||||
|
t.Fatalf("wanted 1 element in ranges, got %d instead", len(ranges))
|
||||||
|
}
|
||||||
|
if ranges[0].Start != 231072 {
|
||||||
|
t.Fatalf("wanted 231072, got %d instead", ranges[0].Start)
|
||||||
|
}
|
||||||
|
if ranges[0].Length != 65536 {
|
||||||
|
t.Fatalf("wanted 65536, got %d instead", ranges[0].Length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue