feat(tvix/castore/protos): add more granular validation methods
Similar to cl/9715, this makes the validation checks more granular, introducing a Validate on all *Node. A check for symlink targets is added too. Once merged, it can also be used from tvix/store/protos. Change-Id: I0909a89fadcd74b74ef0c9a8a1f22658fccc83b0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9716 Reviewed-by: Connor Brewster <cbrewster@hey.com> Tested-by: BuildkiteCI
This commit is contained in:
parent
532f414da6
commit
0b18be3b57
2 changed files with 104 additions and 29 deletions
|
|
@ -122,7 +122,7 @@ func TestDirectoryValidate(t *testing.T) {
|
|||
Symlinks: []*castorev1pb.SymlinkNode{},
|
||||
}
|
||||
|
||||
assert.ErrorContains(t, d.Validate(), "invalid name")
|
||||
assert.ErrorContains(t, d.Validate(), "invalid node name")
|
||||
}
|
||||
{
|
||||
d := castorev1pb.Directory{
|
||||
|
|
@ -135,7 +135,7 @@ func TestDirectoryValidate(t *testing.T) {
|
|||
Symlinks: []*castorev1pb.SymlinkNode{},
|
||||
}
|
||||
|
||||
assert.ErrorContains(t, d.Validate(), "invalid name")
|
||||
assert.ErrorContains(t, d.Validate(), "invalid node name")
|
||||
}
|
||||
{
|
||||
d := castorev1pb.Directory{
|
||||
|
|
@ -149,7 +149,7 @@ func TestDirectoryValidate(t *testing.T) {
|
|||
Symlinks: []*castorev1pb.SymlinkNode{},
|
||||
}
|
||||
|
||||
assert.ErrorContains(t, d.Validate(), "invalid name")
|
||||
assert.ErrorContains(t, d.Validate(), "invalid node name")
|
||||
}
|
||||
{
|
||||
d := castorev1pb.Directory{
|
||||
|
|
@ -161,7 +161,7 @@ func TestDirectoryValidate(t *testing.T) {
|
|||
}},
|
||||
}
|
||||
|
||||
assert.ErrorContains(t, d.Validate(), "invalid name")
|
||||
assert.ErrorContains(t, d.Validate(), "invalid node name")
|
||||
}
|
||||
{
|
||||
d := castorev1pb.Directory{
|
||||
|
|
@ -173,7 +173,7 @@ func TestDirectoryValidate(t *testing.T) {
|
|||
}},
|
||||
}
|
||||
|
||||
assert.ErrorContains(t, d.Validate(), "invalid name")
|
||||
assert.ErrorContains(t, d.Validate(), "invalid node name")
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -191,6 +191,33 @@ func TestDirectoryValidate(t *testing.T) {
|
|||
assert.ErrorContains(t, d.Validate(), "invalid digest length")
|
||||
})
|
||||
|
||||
t.Run("invalid symlink targets", func(t *testing.T) {
|
||||
{
|
||||
d := castorev1pb.Directory{
|
||||
Directories: []*castorev1pb.DirectoryNode{},
|
||||
Files: []*castorev1pb.FileNode{},
|
||||
Symlinks: []*castorev1pb.SymlinkNode{{
|
||||
Name: []byte("foo"),
|
||||
Target: []byte{},
|
||||
}},
|
||||
}
|
||||
|
||||
assert.ErrorContains(t, d.Validate(), "invalid symlink target")
|
||||
}
|
||||
{
|
||||
d := castorev1pb.Directory{
|
||||
Directories: []*castorev1pb.DirectoryNode{},
|
||||
Files: []*castorev1pb.FileNode{},
|
||||
Symlinks: []*castorev1pb.SymlinkNode{{
|
||||
Name: []byte("foo"),
|
||||
Target: []byte{0x66, 0x6f, 0x6f, 0},
|
||||
}},
|
||||
}
|
||||
|
||||
assert.ErrorContains(t, d.Validate(), "invalid symlink target")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("sorting", func(t *testing.T) {
|
||||
// "b" comes before "a", bad.
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue