Subject: [PATCH 4/4] tests: ssh: Add a test for SFTP.

From: Clément Lassieur <[email-masked]>
Date: Sun, 19 Mar 2017 17:35:07 +0100

* gnu/tests/ssh.scm (run-ssh-test): Introduce "SFTP file writing and reading".
Make 'sftp' a keyword parameter.

Signed-off-by: Clément Lassieur <[email-masked]>
---
 gnu/tests/ssh.scm | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/gnu/tests/ssh.scm b/gnu/tests/ssh.scm
index fae4dff25..8e656abff 100644
--- a/gnu/tests/ssh.scm
+++ b/gnu/tests/ssh.scm
@@ -55,7 +55,7 @@
     (services (cons service
                     (operating-system-user-services %base-os)))))
 
-(define (run-ssh-test name ssh-service pid-file)
+(define* (run-ssh-test name ssh-service pid-file #:key (sftp #f))
   "Run a test of an OS running SSH-SERVICE, which writes its PID to PID-FILE.
 SSH-SERVICE must be configured to listen on port 22 and to allow for root and
 empty-password logins."
@@ -81,7 +81,8 @@ empty-password logins."
                          (ice-9 match)
                          (ssh session)
                          (ssh auth)
-                         (ssh channel))
+                         (ssh channel)
+                         (ssh sftp))
 
             (define marionette
               ;; Enable TCP forwarding of the guest's port 22.
@@ -184,6 +185,20 @@ root with an empty password."
                    (and (zero? (channel-get-exit-status channel))
                         (wait-for-file "/root/witness"))))))
 
+            ;; Connect to the guest over SFTP.  Make sure we can write and
+            ;; read a file there.
+            (when #$sftp
+              (test-equal "SFTP file writing and reading"
+                'hello
+                (call-with-connected-session/auth
+                 (lambda (session)
+                   (let ((sftp-session (make-sftp-session session))
+                         (witness "/root/sftp-witness"))
+                     (call-with-remote-output-file sftp-session witness
+                                                   (cut display "hello" <>))
+                     (call-with-remote-input-file sftp-session witness
+                                                  read))))))
+
             (test-end)
             (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
 
@@ -200,7 +215,8 @@ root with an empty password."
                                  (openssh-configuration
                                   (permit-root-login #t)
                                   (allow-empty-passwords? #t)))
-                        "/var/run/sshd.pid"))))
+                        "/var/run/sshd.pid"
+                        #:sftp #t))))
 
 (define %test-dropbear
   (system-test
-- 
2.12.0