;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ludovic Courtès ;;; Copyright © 2017, 2018 Clément Lassieur ;;; Copyright © 2017 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu tests ssh) #:use-module (gnu tests) #:use-module (gnu system) #:use-module (gnu system vm) #:use-module (gnu services) #:use-module (gnu services ssh) #:use-module (gnu services networking) #:use-module (gnu packages ssh) #:use-module (guix gexp) #:use-module (guix store) #:export (%test-openssh %test-dropbear)) (define* (run-ssh-test name ssh-service pid-file #:key (sftp? #f) (test-getlogin? #t)) "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. When SFTP? is true, run an SFTP server test." (define os (marionette-operating-system (simple-operating-system (service dhcp-client-service-type) ssh-service) #:imported-modules '((gnu services herd) (guix combinators)))) (define vm (virtual-machine (operating-system os) (port-forwardings '((2222 . 22))))) (define test (with-imported-modules '((gnu build marionette)) (with-extensions (list guile-ssh) #~(begin (use-modules (gnu build marionette) (srfi srfi-26) (srfi srfi-64) (ice-9 textual-ports) (ice-9 match) (ssh session) (ssh auth) (ssh channel) (ssh popen) (ssh sftp)) (define marionette ;; Enable TCP forwarding of the guest's port 22. (make-marionette (list #$vm))) (define (make-session-for-test) "Make a session with predefined parameters for a test." (make-session #:user "root" #:port 2222 #:host "localhost" #:log-verbosity 'protocol)) (define (call-with-connected-session proc) "Call the one-argument procedure PROC with a freshly created and connected SSH session object, return the result of the procedure call. The session is disconnected when the PROC is finished." (let ((session (make-session-for-test))) (dynamic-wind (lambda () (let ((result (connect! session))) (unless (equal? result 'ok) (error "Could not connect to a server" session result)))) (lambda () (proc session)) (lambda () (disconnect! session))))) (define (call-with-connected-session/auth proc) "Make an authenticated session. We should be able to connect as root with an empty password." (call-with-connected-session (lambda (session) ;; Try the simple authentication methods. Dropbear requires ;; 'none' when there are no passwords, whereas OpenSSH accepts ;; 'password' with an empty password. (let loop ((methods (list (cut userauth-password! <> "") (cut userauth-none! <>)))) (match methods (() (error "all the authentication methods failed")) ((auth rest ...) (match (pk 'auth (auth session)) ('success (proc session)) ('denied (loop rest))))))))) (mkdir #$2017-01-13etc: Support indentation of whole files....Ludovic Courtès 2017-01-12etc: Add 'indent-package.el' script....Ludovic Courtès 2016-12-29Remove Emacs interface....Alex Kost 2016-12-14doc: Fix typo in Submitting Patches section....Maxim Cournoyer 2016-07-28doc: Discourage software bundling....Ludovic Courtès 2016-07-28doc: Send changes in your patch which are related....ng0 2016-07-28doc: Mention separate branch for packages with many dependents....Ludovic Courtès 2016-07-24doc: Point out preference of message format....ng0 2016-07-24doc: Explain that contributors can use a pseudonym....Ludovic Courtès 2016-07-22doc: Add note on gender-neutral wording....Ludovic Courtès 2016-04-16doc: Mention --localstatedir for when building from Git....Ludovic Courtès 2016-03-11doc: Add footnote about pointing ~/.config/guix/latest at user's checkout...Christopher Allan Webber 2016-02-24doc: Fix minor typos and add missing words....Chris Marusich 2015-12-09doc: rephrase code of conduct....Alex Sassmannshausen 2015-12-09Add "Contributor Covenant"....Ludovic Courtès 2015-12-08guix build: Add '--rounds'....Ludovic Courtès 2015-11-22doc: Mention 'guix environment guix'....Ludovic Courtès 2015-11-21doc: Remove extraneous "See."...Ludovic Courtès 2015-11-21doc: Fix 'geiser-guile-load-path' example....Alex Kost 2015-11-03doc: './pre-inst-env guix pull' won't upgrade local source tree....Alex Vong 2015-10-28