1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
-- with no monotone keys:
-- * (E) export monotone key
check(mtn("ssh_agent_export"), 1, false, false)
mtn_setup()
tkey = "happy@example.com"
-- with one monotone key:
-- * (ok) mtn ci with ssh-agent not running
addfile("some_file", "test")
check(mtn("ci", "--message", "commit msg"), 0, false, false)
-- * (E) export key with -k that does not exist
check(mtn("--key", "n@n.com", "ssh_agent_export"), 1, false, false)
-- * (ok) export key without -k
check(raw_mtn("--rcfile", test.root .. "/test_hooks.lua", -- "--no-builtin-rcfiles",
"--db=" .. test.root .. "/test.db",
"--keydir", test.root .. "/keys",
"ssh_agent_export"), 0, false, false)
-- * (ok) export key with -k that does exist
check(mtn("--key", "tester@test.net", "ssh_agent_export"), 0, false, false)
-- * (ok) export monotone key with passphrase
check(mtn("ssh_agent_export"), 0, false, false, tkey .. "\n" .. tkey .. "\n")
-- * (ok) export monotone key without passphrase
check(mtn("ssh_agent_export"), 0, false, false)
-- * (ok) export in workspace exports to subdir
mkdir("subdir")
mkdir("subdir/anotherdir")
writefile("subdir/foo", "data data")
writefile("subdir/anotherdir/bar", "more data")
chdir("subdir")
check(mtn("add", "foo"), 0, false, false)
check(mtn("add", "-R", "anotherdir"), 0, false, false)
check(mtn("ssh_agent_export", "id_monotone"), 0, false, false)
check(exists("id_monotone"))
chdir("..")
check(not exists("id_monotone"))
-- * (ok) export to subdirectory named on command line
check(mtn("ssh_agent_export", "subdir/id_monotone2"), 0, false, false)
check(exists("subdir/id_monotone2"))
check(not exists("id_monotone2"))
-- * (ok) export to path containing a nonexistent directory - creates it
check(not exists("nonexistent"))
check(mtn("ssh_agent_export", "nonexistent/id_monotone3"), 0, false, false)
check(exists("nonexistent/id_monotone3"))
check(not exists("id_monotone3"))
-- * (E) export to path that's not writable
-- we don't know how to do this on windows
skip_if(ostype == "Windows") -- chmod doesn't work
skip_if(not existsonpath("chmod"))
mkdir("unwritable")
check({"chmod", "555", "unwritable"}, 0, false, false)
check(mtn("ssh_agent_export", "unwritable/id_monotone4"), 1, false, false)
check(not exists("unwritable/id_monotone3"))
check(not exists("id_monotone3"))
-- set up for tests of the agent itself
-- we don't know how to do this on windows
skip_if(ostype == "Windows")
skip_if(not existsonpath("ssh-agent"))
skip_if(not existsonpath("ssh-add"))
function cleanup()
check({"kill", os.getenv("SSH_AGENT_PID")}, 0, false, false)
end
check({"ssh-agent"}, 0, true, false)
for line in io.lines("stdout") do
for k, v in string.gmatch(line, "([%w_]+)=([%w/%.-_]+)") do
set_env(k, v)
end
end
-- * (ok) mtn ssh_agent_add adds key to agent
check(mtn("ssh_agent_add"), 0, false, false)
check({"ssh-add", "-l"}, 0, true, false)
ok = false
for line in io.lines("stdout") do
for k in string.gmatch(line, "tester@test%.net") do
ok = true
end
end
if not ok then
err("identity was not added to ssh-agent")
end
-- * (ok) mtn ci with ssh-agent running with no keys
check({"ssh-add", "-D"}, 0, false, false)
addfile("some_file2", "test")
check(mtn("ci", "--message", "commit msg"), 0, false, false)
-- key should be auto-added in ssh-agent
check({"ssh-add", "-l"}, 0, true, false)
for line in io.lines("stdout") do
for k in string.gmatch(line, "no identities") do
err("no identity in ssh-agent when there should be one")
end
end
-- * (N) mtn ci with no ssh key with --ssh-sign
check({"ssh-add", "-D"}, 0, false, false) addfile("some_file3", "test")
check(mtn("ci", "--message", "commit msg", "--ssh-sign"), 1, false, false)
-- * (N) mtn ci with no ssh key with --ssh-sign=blah
check({"ssh-add", "-D"}, 0, false, false)
addfile("some_file3", "test")
check(mtn("ci", "--message", "commit msg", "--ssh-sign=blah"), 1, false, false)
-- * (N) mtn ci with no ssh key with --ssh-sign=only
check({"ssh-add", "-D"}, 0, false, false)
addfile("some_file3_b", "test")
check(mtn("ci", "--debug", "--ssh-sign=only", "--message", "commit msg"), 1, false, false)
-- key should not be in ssh-agent with --ssh-sign=only
check({"ssh-add", "-l"}, 1, false, false)
--for line in io.lines("stdout") do
-- if not string.gmatch(line, "no identities") then
-- err("identity in ssh-agent when there should be none")
-- end
--end
-- * (ok) mtn ci with no ssh key with --ssh-sign=yes
check({"ssh-add", "-D"}, 0, false, false)
addfile("some_file4", "test")
check(mtn("ci", "--ssh-sign=yes", "--message", "commit msg"), 0, false, false)
-- key should be auto-added in ssh-agent with --ssh-sign=yes
check({"ssh-add", "-l"}, 0, true, false)
for line in io.lines("stdout") do
for k in string.gmatch(line, "no identities") do
err("no identity in ssh-agent when there should be one")
end
end
-- * (ok) mtn ci with no ssh key with --ssh-sign=no
check({"ssh-add", "-D"}, 0, false, false)
addfile("some_file5", "test")
check(mtn("ci", "--ssh-sign=no", "--message", "commit msg"), 0, false, false)
-- key should not be in ssh-agent with --ssh-sign=no
check({"ssh-add", "-l"}, 1, false, false)
-- * (ok) mtn ci with no ssh key with --ssh-sign=check
check({"ssh-add", "-D"}, 0, false, false)
addfile("some_file6", "test")
check(mtn("ci", "--ssh-sign=check", "--message", "commit msg"), 0, false, false)
-- key should not be auto-added in ssh-agent with --ssh-sign=check
check({"ssh-add", "-l"}, 0, true, false)
for line in io.lines("stdout") do
for k in string.gmatch(line, "no identities") do
err("no identity in ssh-agent when there should be one")
end
end
-- * (ok) mtn ci with ssh-agent running with non-monotone rsa key
check(get("id_rsa"))
check({"chmod", "600", "id_rsa"}, 0, false, false)
check({"ssh-add", "id_rsa"}, 0, false, false)
addfile("some_file7", "test")
check(mtn("ci", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with ssh-agent running with dss key
check({"ssh-add", "-D"}, 0, false, false)
check(get("id_dsa"))
check({"chmod", "600", "id_dsa"}, 0, false, false)
check({"ssh-add", "id_dsa"}, 0, false, false)
addfile("some_file8", "test")
check(mtn("ci", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with ssh-agent running with multiple non-monotone rsa keys
check({"ssh-add", "-D"}, 0, false, false)
check({"ssh-add", "id_rsa"}, 0, false, false)
check(get("id_rsa2"))
check({"chmod", "600", "id_rsa2"}, 0, false, false)
check({"ssh-add", "id_rsa2"}, 0, false, false)
addfile("some_file9", "test")
check(mtn("ci", "--message", "commit msg"), 0, false, false)
-- * (ok) export key with password
check(mtn("ssh_agent_export", "id_monotone_pass"), 0, false, false,
"pass\npass\n")
-- without any password, or the wrong password, ssh-add should not add
-- this key; the DISPLAY/SSH_ASKPASS subterfuge is necessary to get
-- ssh-add to read the password from somewhere other than /dev/tty.
save_env()
set_env("DISPLAY", "not-a-real-display")
set_env("SSH_ASKPASS", test.root .. "/report_pass")
check({"ssh-add", "-D"}, 0, false, false)
-- * (E) no password at all
writefile("report_pass", "#!/bin/sh\nexit 0")
check({"chmod", "700", "report_pass"}, 0, false, false)
check({"ssh-add", "id_monotone_pass"}, 1, false, false)
-- * (E) wrong password (note that ssh-add will retry indefinitely as long
-- as ssh-askpass keeps giving it (success, wrong password))
writefile("report_pass",
"#!/bin/sh\n"..
"if [ -f report_pass_retried ]; then\n"..
" exit 1\n"..
"else\n"..
" echo notpass\n"..
" touch report_pass_retried\n"..
" exit 0\n"..
"fi\n")
check({"chmod", "700", "report_pass"}, 0, false, false)
check({"ssh-add", "id_monotone_pass"}, 1, false, false)
-- * (ok) correct password
writefile("report_pass", "#!/bin/sh\necho pass\nexit 0")
check({"chmod", "700", "report_pass"}, 0, false, false)
check({"ssh-add", "id_monotone_pass"}, 0, false, false)
restore_env()
-- * (E) export key with mismatched passwords
check(mtn("ssh_agent_export", "id_mismatched_pass"), 1, false, false,
"this\nthat\nthis\nthat\nthis\nthat")
check(not exists("id_mismatched_pass"))
-- * (ok) add password-less exported key with ssh-add
check(mtn("ssh_agent_export", "id_monotone"), 0, false, false)
check({"ssh-add", "-D"}, 0, false, false)
check({"ssh-add", "id_monotone"}, 0, false, false)
-- * (ok) mtn ci with ssh key without --ssh-sign
addfile("some_file10", "test")
check(mtn("ci", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with ssh key with --ssh-sign=only
addfile("some_file11", "test")
check(mtn("ci", "--ssh-sign=only", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with ssh key with --ssh-sign=yes
addfile("some_file12", "test")
check(mtn("ci", "--ssh-sign=yes", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with ssh key with --ssh-sign=no
addfile("some_file13", "test")
check(mtn("ci", "--ssh-sign=no", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with ssh key with --ssh-sign=check
addfile("some_file14", "test")
check(mtn("ci", "--ssh-sign=check", "--message", "commit msg"), 0, false, false)
--
-- with multiple monotone keys:
check(mtn("genkey", "test2@tester.net"), 0, false, false)
-- * (N) try to export monotone key without -k
remove("_MTN/options")
check(raw_mtn("--rcfile", test.root .. "/test_hooks.lua", -- "--no-builtin-rcfiles",
"--db=" .. test.root .. "/test.db",
"--keydir", test.root .. "/keys",
"ssh_agent_export"), 1, false, false)
-- * (N) try to add monotone key without -k
remove("_MTN/options")
check(raw_mtn("--rcfile", test.root .. "/test_hooks.lua", -- "--no-builtin-rcfiles",
"--db=" .. test.root .. "/test.db",
"--keydir", test.root .. "/keys",
"ssh_agent_add"), 1, false, false)
-- * (ok) export monotone key with -k
check(mtn("ssh_agent_export", "--key", "test2@tester.net", "id_monotone2"), 0, false, false)
-- * (ok) mtn ssh_agent_add with -k adds key to agent
check({"ssh-add", "-D"}, 0, false, false)
check(mtn("ssh_agent_add", "--key", "test2@tester.net"), 0, false, false)
check({"ssh-add", "-l"}, 0, true, false)
ok = false
for line in io.lines("stdout") do
for k in string.gmatch(line, "test2@tester%.net") do
ok = true
end
end
if not ok then
err("identity was not added to ssh-agent")
end
-- * (ok) mtn ci with -k and with ssh-agent running with no keys
check({"ssh-add", "-D"}, 0, false, false)
addfile("some_file15", "test")
check(mtn("ci", "--key", "tester@test.net", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with -k and with ssh-agent running with one non-monotone rsa key
check({"ssh-add", "-D"}, 0, false, false)
check({"ssh-add", "id_rsa"}, 0, false, false)
addfile("some_file16", "test")
check(mtn("ci", "--key", "tester@test.net", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with -k and with ssh-agent running with same monotone key ex/imported key
check({"ssh-add", "-D"}, 0, false, false)
check({"ssh-add", "id_monotone"}, 0, false, false)
addfile("some_file17", "test")
check(mtn("ci", "--ssh-sign", "only", "--key", "tester@test.net", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with -k and with ssh-agent running with other monotone key ex/imported key
addfile("some_file18", "test")
check(mtn("ci", "--ssh-sign", "only", "--key", "test2@tester.net", "--message", "commit msg"), 1, false, false)
check(mtn("ci", "--key", "test2@tester.net", "--message", "commit msg"), 0, false, false)
-- * (ok) mtn ci with -k and with ssh-agent running with both montone keys ex/imported key
check({"ssh-add", "-D"}, 0, false, false)
check({"ssh-add", "id_monotone"}, 0, false, false)
check({"ssh-add", "id_monotone2"}, 0, false, false)
addfile("some_file19", "test")
check(mtn("ci", "--key", "test2@tester.net", "--message", "commit msg"), 0, false, false)
addfile("some_file20", "test")
check(mtn("ci", "--key", "tester@test.net", "--message", "commit msg"), 0, false, false)
-- * (ok) create passworded key and export it
check({"ssh-add", "-D"}, 0, false, false)
check(mtn("genkey", "test_pass@tester.net"), 0, false, false, "pass\npass\n")
check(mtn("ssh_agent_export", "--key", "test_pass@tester.net"), 0, false, false, "pass\npass2\npass2\n")
-- * (ok) add passworded key
check({"ssh-add", "-D"}, 0, false, false)
check(mtn("ssh_agent_add", "--key", "test_pass@tester.net"), 0, false, false, "pass\n")
check({"ssh-add", "-l"}, 0, true, false)
ok = false
for line in io.lines("stdout") do
for k in string.gmatch(line, "test_pass@tester%.net") do
ok = true
end
end
if not ok then
err("identity was not added to ssh-agent")
end
-- * (ok) commit with passworded key (provide password explicitly, although will be not necessary as SSH-agent is used)
addfile("some_file21", "test")
check(mtn("ci", "--key", "test_pass@tester.net", "--message", "commit msg"), 0, false, false, "pass\n")
-- * (ok) commit with passworded key (provide no password at all, because SSH-agent is used)
addfile("some_file22", "test")
check(mtn("ci", "--key", "test_pass@tester.net", "--message", "commit msg"), 0, false, false)
|