Skip to content

Commit

Permalink
tests: add bb test for symlink resolution
Browse files Browse the repository at this point in the history
Verify that the last element of fs entries' paths is not followed when
resolving paths.

Test that we dont overwrite dead links when overwrite is false.
  • Loading branch information
Andrew Jeddeloh committed Dec 6, 2018
1 parent 54e3c04 commit 91bab0c
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/negative/files/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
func init() {
register.Register(register.NegativeTest, WriteThroughRelativeSymlink())
register.Register(register.NegativeTest, WriteThroughAbsoluteSymlink())
register.Register(register.NegativeTest, WriteOverBrokenSymlink())
}
func WriteThroughRelativeSymlink() types.Test {
name := "Write Through Relative Symlink off the Root Filesystem"
Expand Down Expand Up @@ -114,3 +115,38 @@ func WriteThroughAbsoluteSymlink() types.Test {
ConfigMinVersion: configMinVersion,
}
}

func WriteOverBrokenSymlink() types.Test {
name := "Write Over Broken Symlink at end of path"
in := types.GetBaseDisk()
out := types.GetBaseDisk()
config := `{
"ignition": { "version": "$version" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/file",
"overwrite": false,
"mode": 420
}]
}
}`
in[0].Partitions.AddLinks("ROOT", []types.Link{
{
Node: types.Node{
Name: "file",
Directory: "etc",
},
Target: "/usr/rofile",
},
})
configMinVersion := "2.2.0"

return types.Test{
Name: name,
In: in,
Out: out,
Config: config,
ConfigMinVersion: configMinVersion,
}
}
112 changes: 112 additions & 0 deletions tests/positive/files/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func init() {
register.Register(register.PositiveTest, WriteThroughAbsoluteSymlink())
register.Register(register.PositiveTest, ForceLinkCreation())
register.Register(register.PositiveTest, ForceHardLinkCreation())
register.Register(register.PositiveTest, WriteOverSymlink())
register.Register(register.PositiveTest, WriteOverBrokenSymlink())
}

func CreateHardLinkOnRoot() types.Test {
Expand Down Expand Up @@ -396,3 +398,113 @@ func ForceHardLinkCreation() types.Test {
ConfigMinVersion: configMinVersion,
}
}

func WriteOverSymlink() types.Test {
name := "Write Over Symlink at end of path"
in := types.GetBaseDisk()
out := types.GetBaseDisk()
// note this abuses the order in which ignition writes links and will break with 3.0.0
// Also tests that Ignition does not try to resolve symlink targets
config := `{
"ignition": { "version": "$version" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/file",
"mode": 420
}]
}
}`
in[0].Partitions.AddLinks("ROOT", []types.Link{
{
Node: types.Node{
Name: "file",
Directory: "etc",
},
Target: "/usr/rofile",
},
})
in[0].Partitions.AddFiles("ROOT", []types.File{
{
Node: types.Node{
Name: "rofile",
Directory: "usr",
},
Contents: "",
Mode: 420,
},
})
out[0].Partitions.AddFiles("ROOT", []types.File{
{
Node: types.Node{
Name: "rofile",
Directory: "usr",
},
Contents: "",
Mode: 420,
},
{
Node: types.Node{
Name: "file",
Directory: "etc",
},
Contents: "",
Mode: 420,
},
})
configMinVersion := "2.1.0"

return types.Test{
Name: name,
In: in,
Out: out,
Config: config,
ConfigMinVersion: configMinVersion,
}
}

func WriteOverBrokenSymlink() types.Test {
name := "Write Over Broken Symlink at end of path"
in := types.GetBaseDisk()
out := types.GetBaseDisk()
// note this abuses the order in which ignition writes links and will break with 3.0.0
// Also tests that Ignition does not try to resolve symlink targets
config := `{
"ignition": { "version": "$version" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/file",
"mode": 420
}]
}
}`
in[0].Partitions.AddLinks("ROOT", []types.Link{
{
Node: types.Node{
Name: "file",
Directory: "etc",
},
Target: "/usr/rofile",
},
})
out[0].Partitions.AddFiles("ROOT", []types.File{
{
Node: types.Node{
Name: "file",
Directory: "etc",
},
Contents: "",
Mode: 420,
},
})
configMinVersion := "2.1.0"

return types.Test{
Name: name,
In: in,
Out: out,
Config: config,
ConfigMinVersion: configMinVersion,
}
}

0 comments on commit 91bab0c

Please sign in to comment.