@@ -161,11 +161,13 @@ var allTests = integration.TestFuncs(
161
161
testCopySymlinks ,
162
162
testCopyChown ,
163
163
testCopyChmod ,
164
+ testCopyInvalidChmod ,
164
165
testCopyOverrideFiles ,
165
166
testCopyVarSubstitution ,
166
167
testCopyWildcards ,
167
168
testCopyRelative ,
168
169
testAddURLChmod ,
170
+ testAddInvalidChmod ,
169
171
testTarContext ,
170
172
testTarContextExternalDockerfile ,
171
173
testWorkdirUser ,
@@ -3516,6 +3518,57 @@ COPY --from=base /out /
3516
3518
require .Equal (t , "0000\n " , string (dt ))
3517
3519
}
3518
3520
3521
+ func testCopyInvalidChmod (t * testing.T , sb integration.Sandbox ) {
3522
+ integration .SkipOnPlatform (t , "windows" )
3523
+ f := getFrontend (t , sb )
3524
+
3525
+ dockerfile := []byte (`
3526
+ FROM scratch
3527
+ COPY --chmod=64a foo /
3528
+ ` )
3529
+
3530
+ dir := integration .Tmpdir (
3531
+ t ,
3532
+ fstest .CreateFile ("Dockerfile" , dockerfile , 0600 ),
3533
+ fstest .CreateFile ("foo" , []byte (`foo-contents` ), 0600 ),
3534
+ )
3535
+
3536
+ c , err := client .New (sb .Context (), sb .Address ())
3537
+ require .NoError (t , err )
3538
+ defer c .Close ()
3539
+
3540
+ _ , err = f .Solve (sb .Context (), c , client.SolveOpt {
3541
+ LocalMounts : map [string ]fsutil.FS {
3542
+ dockerui .DefaultLocalNameDockerfile : dir ,
3543
+ dockerui .DefaultLocalNameContext : dir ,
3544
+ },
3545
+ }, nil )
3546
+ require .ErrorContains (t , err , "invalid chmod parameter: '64a'. it should be octal string and between 0 and 07777" )
3547
+
3548
+ dockerfile = []byte (`
3549
+ FROM scratch
3550
+ COPY --chmod=10000 foo /
3551
+ ` )
3552
+
3553
+ dir = integration .Tmpdir (
3554
+ t ,
3555
+ fstest .CreateFile ("Dockerfile" , dockerfile , 0600 ),
3556
+ fstest .CreateFile ("foo" , []byte (`foo-contents` ), 0600 ),
3557
+ )
3558
+
3559
+ c , err = client .New (sb .Context (), sb .Address ())
3560
+ require .NoError (t , err )
3561
+ defer c .Close ()
3562
+
3563
+ _ , err = f .Solve (sb .Context (), c , client.SolveOpt {
3564
+ LocalMounts : map [string ]fsutil.FS {
3565
+ dockerui .DefaultLocalNameDockerfile : dir ,
3566
+ dockerui .DefaultLocalNameContext : dir ,
3567
+ },
3568
+ }, nil )
3569
+ require .ErrorContains (t , err , "invalid chmod parameter: '10000'. it should be octal string and between 0 and 07777" )
3570
+ }
3571
+
3519
3572
func testCopyOverrideFiles (t * testing.T , sb integration.Sandbox ) {
3520
3573
integration .SkipOnPlatform (t , "windows" )
3521
3574
f := getFrontend (t , sb )
@@ -3803,6 +3856,57 @@ COPY --from=build /dest /dest
3803
3856
require .Equal (t , []byte ("0644\n 0755\n 0413\n " ), dt )
3804
3857
}
3805
3858
3859
+ func testAddInvalidChmod (t * testing.T , sb integration.Sandbox ) {
3860
+ integration .SkipOnPlatform (t , "windows" )
3861
+ f := getFrontend (t , sb )
3862
+
3863
+ dockerfile := []byte (`
3864
+ FROM scratch
3865
+ ADD --chmod=64a foo /
3866
+ ` )
3867
+
3868
+ dir := integration .Tmpdir (
3869
+ t ,
3870
+ fstest .CreateFile ("Dockerfile" , dockerfile , 0600 ),
3871
+ fstest .CreateFile ("foo" , []byte (`foo-contents` ), 0600 ),
3872
+ )
3873
+
3874
+ c , err := client .New (sb .Context (), sb .Address ())
3875
+ require .NoError (t , err )
3876
+ defer c .Close ()
3877
+
3878
+ _ , err = f .Solve (sb .Context (), c , client.SolveOpt {
3879
+ LocalMounts : map [string ]fsutil.FS {
3880
+ dockerui .DefaultLocalNameDockerfile : dir ,
3881
+ dockerui .DefaultLocalNameContext : dir ,
3882
+ },
3883
+ }, nil )
3884
+ require .ErrorContains (t , err , "invalid chmod parameter: '64a'. it should be octal string and between 0 and 07777" )
3885
+
3886
+ dockerfile = []byte (`
3887
+ FROM scratch
3888
+ ADD --chmod=10000 foo /
3889
+ ` )
3890
+
3891
+ dir = integration .Tmpdir (
3892
+ t ,
3893
+ fstest .CreateFile ("Dockerfile" , dockerfile , 0600 ),
3894
+ fstest .CreateFile ("foo" , []byte (`foo-contents` ), 0600 ),
3895
+ )
3896
+
3897
+ c , err = client .New (sb .Context (), sb .Address ())
3898
+ require .NoError (t , err )
3899
+ defer c .Close ()
3900
+
3901
+ _ , err = f .Solve (sb .Context (), c , client.SolveOpt {
3902
+ LocalMounts : map [string ]fsutil.FS {
3903
+ dockerui .DefaultLocalNameDockerfile : dir ,
3904
+ dockerui .DefaultLocalNameContext : dir ,
3905
+ },
3906
+ }, nil )
3907
+ require .ErrorContains (t , err , "invalid chmod parameter: '10000'. it should be octal string and between 0 and 07777" )
3908
+ }
3909
+
3806
3910
func testDockerfileFromGit (t * testing.T , sb integration.Sandbox ) {
3807
3911
integration .SkipOnPlatform (t , "windows" )
3808
3912
f := getFrontend (t , sb )
0 commit comments