@@ -2,9 +2,11 @@ package source
22
33import  (
44	"archive/tar" 
5+ 	"os" 
56	"testing" 
67
78	"github.com/stretchr/testify/assert" 
9+ 	"k8s.io/apimachinery/pkg/util/rand" 
810)
911
1012func  TestContainersImage_applyLayerFilter (t  * testing.T ) {
@@ -116,6 +118,34 @@ func TestContainersImage_applyLayerFilter(t *testing.T) {
116118				assert .NoError (t , err )
117119			},
118120		},
121+ 		{
122+ 			name : "correctly sets permissions, uid/gid, and file attributes" ,
123+ 			srcPaths : []string {"foo" },
124+ 			tarHeaders : []tar.Header {
125+ 				{
126+ 					Name : "foo/bar" ,
127+ 				        Mode : 0000 ,
128+ 				        Uid :  rand .Int (),
129+ 				        Gid :  rand .Int (),
130+ 				        Xattrs : map [string ]string { //nolint:staticcheck 
131+ 				                "foo" : "bar" ,
132+ 				        },
133+ 				        PAXRecords : map [string ]string {
134+ 				                "fizz" : "buzz" ,
135+ 				        },
136+ 				},
137+ 			},
138+ 			assertion : func (tarHeader  * tar.Header , keep  bool , err  error ) {
139+ 				assert .True (t , keep )
140+ 				assert .NoError (t , err )
141+ 				assert .Equal (t , "foo/bar" , tarHeader .Name )
142+ 				assert .Equal (t , int64 (0700 ), tarHeader .Mode )
143+ 				assert .Equal (t , os .Getuid (), tarHeader .Uid )
144+ 				assert .Equal (t , os .Getgid (), tarHeader .Gid )
145+ 				assert .Nil (t , tarHeader .PAXRecords )
146+ 				assert .Nil (t , tarHeader .Xattrs ) //nolint:staticcheck 
147+ 			},
148+ 		},
119149	} {
120150		t .Run (tc .name , func (t  * testing.T ) {
121151			for  _ , srcPath  :=  range  tc .srcPaths  {
0 commit comments