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>
| ... | ... |
@@ -241,3 +241,31 @@ func compareTrees(left, right map[string]node) error {
|
| 241 | 241 |
} |
| 242 | 242 |
return nil |
| 243 | 243 |
} |
| 244 |
+ |
|
| 245 |
+func TestParseSubidFileWithNewlinesAndComments(t *testing.T) {
|
|
| 246 |
+ tmpDir, err := ioutil.TempDir("", "parsesubid")
|
|
| 247 |
+ if err != nil {
|
|
| 248 |
+ t.Fatal(err) |
|
| 249 |
+ } |
|
| 250 |
+ fnamePath := filepath.Join(tmpDir, "testsubuid") |
|
| 251 |
+ fcontent := `tss:100000:65536 |
|
| 252 |
+# empty default subuid/subgid file |
|
| 253 |
+ |
|
| 254 |
+dockremap:231072:65536` |
|
| 255 |
+ if err := ioutil.WriteFile(fnamePath, []byte(fcontent), 0644); err != nil {
|
|
| 256 |
+ t.Fatal(err) |
|
| 257 |
+ } |
|
| 258 |
+ ranges, err := parseSubidFile(fnamePath, "dockremap") |
|
| 259 |
+ if err != nil {
|
|
| 260 |
+ t.Fatal(err) |
|
| 261 |
+ } |
|
| 262 |
+ if len(ranges) != 1 {
|
|
| 263 |
+ t.Fatalf("wanted 1 element in ranges, got %d instead", len(ranges))
|
|
| 264 |
+ } |
|
| 265 |
+ if ranges[0].Start != 231072 {
|
|
| 266 |
+ t.Fatalf("wanted 231072, got %d instead", ranges[0].Start)
|
|
| 267 |
+ } |
|
| 268 |
+ if ranges[0].Length != 65536 {
|
|
| 269 |
+ t.Fatalf("wanted 65536, got %d instead", ranges[0].Length)
|
|
| 270 |
+ } |
|
| 271 |
+} |