@@ -973,16 +973,14 @@ func TestAgent_SCP(t *testing.T) {
973
973
func TestAgent_FileTransferBlocked (t * testing.T ) {
974
974
t .Parallel ()
975
975
976
- content := "hello world"
977
-
978
- t .Run ("SCP" , func (t * testing.T ) {
976
+ t .Run ("SCP with go-scp package" , func (t * testing.T ) {
979
977
t .Parallel ()
980
978
981
979
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
982
980
defer cancel ()
983
981
984
982
//nolint:dogsled
985
- conn , _ , _ , _ , _ := setupAgent (t , agentsdk.Manifest {}, 0 , func (c * agenttest.Client , o * agent.Options ) {
983
+ conn , _ , _ , _ , _ := setupAgent (t , agentsdk.Manifest {}, 0 , func (_ * agenttest.Client , o * agent.Options ) {
986
984
o .BlockFileTransfer = true
987
985
})
988
986
sshClient , err := conn .SSHClient (ctx )
@@ -992,26 +990,47 @@ func TestAgent_FileTransferBlocked(t *testing.T) {
992
990
require .NoError (t , err )
993
991
defer scpClient .Close ()
994
992
tempFile := filepath .Join (t .TempDir (), "scp" )
995
- err = scpClient .CopyFile (context .Background (), strings .NewReader (content ), tempFile , "0755" )
993
+ err = scpClient .CopyFile (context .Background (), strings .NewReader ("hello world" ), tempFile , "0755" )
996
994
require .Error (t , err )
997
995
require .Contains (t , err .Error (), agentssh .BlockedFileTransferErrorMessage )
998
996
})
999
997
1000
- t .Run ("SFTP " , func (t * testing.T ) {
998
+ t .Run ("Forbidden commands " , func (t * testing.T ) {
1001
999
t .Parallel ()
1002
1000
1003
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1004
- defer cancel ()
1001
+ commands := []string {"nc" , "rsync" , "scp" , "sftp" }
1002
+ for _ , c := range commands {
1003
+ c := c
1004
+ t .Run (c , func (t * testing.T ) {
1005
+ t .Parallel ()
1005
1006
1006
- //nolint:dogsled
1007
- conn , _ , _ , _ , _ := setupAgent (t , agentsdk.Manifest {}, 0 , func (c * agenttest.Client , o * agent.Options ) {
1008
- o .BlockFileTransfer = true
1009
- })
1010
- sshClient , err := conn .SSHClient (ctx )
1011
- require .NoError (t , err )
1012
- defer sshClient .Close ()
1013
- _ , err = sftp .NewClient (sshClient )
1014
- require .NoError (t , err )
1007
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1008
+ defer cancel ()
1009
+
1010
+ //nolint:dogsled
1011
+ conn , _ , _ , _ , _ := setupAgent (t , agentsdk.Manifest {}, 0 , func (_ * agenttest.Client , o * agent.Options ) {
1012
+ o .BlockFileTransfer = true
1013
+ })
1014
+ sshClient , err := conn .SSHClient (ctx )
1015
+ require .NoError (t , err )
1016
+ defer sshClient .Close ()
1017
+
1018
+ session , err := sshClient .NewSession ()
1019
+ require .NoError (t , err )
1020
+ defer session .Close ()
1021
+
1022
+ stdout , err := session .StdoutPipe ()
1023
+ require .NoError (t , err )
1024
+
1025
+ err = session .Start (c )
1026
+ require .NoError (t , err )
1027
+ defer session .Close ()
1028
+
1029
+ errorMessage , err := io .ReadAll (stdout )
1030
+ require .NoError (t , err )
1031
+ require .Contains (t , string (errorMessage ), agentssh .BlockedFileTransferErrorMessage )
1032
+ })
1033
+ }
1015
1034
})
1016
1035
}
1017
1036
0 commit comments