3 def assert_not_ipaddr(str)
4 err_msg = "'#{str}' looks like a LAN IP address."
5 assert_raise(IPAddr::InvalidAddressError, err_msg) do
10 def read_and_validate_ssh_config(srv_type)
11 conf = $config[srv_type]
13 required_settings = ['private_key', 'public_key', 'username', 'hostname']
14 required_settings.each do |key|
15 assert(conf.key?(key))
16 assert_not_nil(conf[key])
17 assert(!conf[key].empty?)
21 "Your #{srv_type} config is incorrect or missing from your local " \
22 "configuration file (#{LOCAL_CONFIG_FILE}). " \
23 'See wiki/src/contribute/release_process/test/usage.mdwn for the format.'
29 @ssh_host = conf['hostname']
30 @ssh_port = conf['port'].to_i if conf['port']
31 @ssh_username = conf['username']
32 assert_not_ipaddr(@ssh_host)
34 @sftp_host = conf['hostname']
35 @sftp_port = conf['port'].to_i if conf['port']
36 @sftp_username = conf['username']
37 assert_not_ipaddr(@sftp_host)
41 Given /^I have the SSH key pair for an? (Git|SSH|SFTP) (?:repository|server)( on the LAN)?$/ do |server_type, lan|
42 $vm.execute_successfully("install -m 0700 -d '/home/#{LIVE_USER}/.ssh/'",
44 if server_type == 'Git' || lan
45 secret_key = $config['Unsafe_SSH_private_key']
46 public_key = $config['Unsafe_SSH_public_key']
48 read_and_validate_ssh_config(server_type)
49 secret_key = $config[server_type]['private_key']
50 public_key = $config[server_type]['public_key']
53 $vm.execute_successfully(
54 "echo '#{secret_key}' > '/home/#{LIVE_USER}/.ssh/id_rsa'",
57 $vm.execute_successfully(
58 "echo '#{public_key}' > '/home/#{LIVE_USER}/.ssh/id_rsa.pub'",
61 $vm.execute_successfully("chmod 0600 '/home/#{LIVE_USER}/.ssh/'id*",
65 Given /^I (?:am prompted to )?verify the SSH fingerprint for the (?:Git|SSH) (?:repository|server)$/ do
66 @screen.wait('SSHFingerprint.png', 60)
67 sleep 1 # brief pause to ensure that the following keystrokes do not get lost
68 @screen.type('yes', ['Return'])
72 server = TCPServer.new('127.0.0.1', 0)
78 Given /^an SSH server is running on the LAN$/ do
79 @sshd_server_port = get_free_tcp_port
80 @sshd_server_host = $vmnet.bridge_ip_addr
81 sshd = SSHServer.new(@sshd_server_host, @sshd_server_port)
83 add_extra_allowed_host(@sshd_server_host, @sshd_server_port)
84 add_after_scenario_hook { sshd.stop }
87 When /^I connect to an SSH server on the (Internet|LAN)$/ do |location|
90 read_and_validate_ssh_config('SSH')
92 @ssh_port = @sshd_server_port
93 @ssh_username = 'user'
94 @ssh_host = @sshd_server_host
97 ssh_port_suffix = "-p #{@ssh_port}" if @ssh_port
99 cmd = "ssh #{@ssh_username}@#{@ssh_host} #{ssh_port_suffix}"
101 step 'process "ssh" is not running'
103 recovery_proc = proc do
104 step 'I kill the process "ssh"' if $vm.process_running?('ssh')
105 step 'I run "clear" in GNOME Terminal'
108 retry_tor(recovery_proc) do
109 step "I run \"#{cmd}\" in GNOME Terminal"
110 step 'process "ssh" is running within 10 seconds'
111 step 'I verify the SSH fingerprint for the SSH server'
115 Then /^I have sucessfully logged into the SSH server$/ do
116 @screen.wait('SSHLoggedInPrompt.png', 60)
119 Then /^I connect to an SFTP server on the Internet$/ do
120 read_and_validate_ssh_config 'SFTP'
123 @sftp_port = @sftp_port.to_s
125 recovery_proc = proc do
126 step 'I kill the process "ssh"'
127 step 'I kill the process "nautilus"'
130 retry_tor(recovery_proc) do
131 step 'I start "Nautilus" via GNOME Activities Overview'
132 nautilus = Dogtail::Application.new('org.gnome.Nautilus')
133 nautilus.child(roleName: 'frame')
134 # "Other Locations" has no click action, so Dogtail cannot interact with it.
135 @screen.click('NautilusOtherLocations.png')
136 connect_bar = nautilus.child('Connect to Server', roleName: 'label').parent
138 .child(roleName: 'filler', recursive: false)
139 .child(roleName: 'text', recursive: false)
140 .text = 'sftp://' + @sftp_username + '@' + @sftp_host + ':' + @sftp_port
141 connect_bar.button('Connect', recursive: false).click
142 step 'I verify the SSH fingerprint for the SFTP server'
146 Then /^I verify the SSH fingerprint for the SFTP server$/ do
148 Dogtail::Application.new('gnome-shell').child?('Log In Anyway')
150 # Here we'd like to click on the button using Dogtail, but something
151 # is buggy so let's just use the keyboard.
152 @screen.type(['Tab'], ['Return'])
155 Then /^I successfully connect to the SFTP server$/ do
157 Dogtail::Application.new('org.gnome.Nautilus')
158 .child?("#{@sftp_username} on #{@sftp_host}")