author | Alberto Bertogli
<albertito@blitiri.com.ar> 2018-06-04 00:20:51 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2018-06-04 00:34:32 UTC |
parent | 36692b52d3e61df17dc9ef050106311f6f30b911 |
cmd/dovecot-auth-cli/test_auth_bad_proto.cmy | +37 | -0 |
cmd/dovecot-auth-cli/test_exists_bad_proto.cmy | +32 | -0 |
cmd/dovecot-auth-cli/test_exists_error.cmy | +15 | -0 |
cmd/dovecot-auth-cli/test_wrong_command.cmy | +4 | -0 |
internal/dovecot/dovecot_test.go | +6 | -0 |
test/util/chamuyero | +10 | -0 |
diff --git a/cmd/dovecot-auth-cli/test_auth_bad_proto.cmy b/cmd/dovecot-auth-cli/test_auth_bad_proto.cmy new file mode 100644 index 0000000..cc3b572 --- /dev/null +++ b/cmd/dovecot-auth-cli/test_auth_bad_proto.cmy @@ -0,0 +1,37 @@ + +# Break the handhake early. +client unix_listen .dovecot-client +c = ./dovecot-auth-cli .dovecot auth username password + +client <- VERSION 1 1 +client <~ CPID + +# We are supposed to send the handshake here. +client close + +c <- no: error receiving handshake: EOF +c wait 0 + + +# Break before sending the final response. +client unix_listen .dovecot-client +c = ./dovecot-auth-cli .dovecot auth username password + +client -> VERSION 1 1 +client -> SPID 12345 +client -> CUID 12345 +client -> COOKIE lovelycookie +client -> MECH PLAIN +client -> MECH LOGIN +client -> DONE + +client <- VERSION 1 1 +client <~ CPID + +client <- AUTH 1 PLAIN service=smtp secured no-penalty nologin resp=dXNlcm5hbWUAdXNlcm5hbWUAcGFzc3dvcmQ= + +# We're supposed to send the OK/FAIL here. +client close + +c <- no: error receiving response: EOF +c wait 0 diff --git a/cmd/dovecot-auth-cli/test_exists_bad_proto.cmy b/cmd/dovecot-auth-cli/test_exists_bad_proto.cmy new file mode 100644 index 0000000..ae84326 --- /dev/null +++ b/cmd/dovecot-auth-cli/test_exists_bad_proto.cmy @@ -0,0 +1,32 @@ + +# Invalid version +userdb unix_listen .dovecot-userdb +c = ./dovecot-auth-cli .dovecot exists username + +userdb -> VERSION 0 +c <~ no: error receiving version +c wait 0 + + +# No SPID (send "NOSPID" instead +userdb unix_listen .dovecot-userdb +c = ./dovecot-auth-cli .dovecot exists username + +userdb -> VERSION 1 1 +userdb -> NOSPID +c <~ no: error receiving SPID: +c wait 0 + +# Break before sending the final response. +userdb unix_listen .dovecot-userdb +c = ./dovecot-auth-cli .dovecot exists username + +userdb -> VERSION 1 1 +userdb -> SPID 12345 +userdb <- VERSION 1 1 +userdb <- USER 1 username service=smtp + +userdb close + +c <- no: error receiving response: EOF +c wait 0 diff --git a/cmd/dovecot-auth-cli/test_exists_error.cmy b/cmd/dovecot-auth-cli/test_exists_error.cmy new file mode 100644 index 0000000..38e8ac3 --- /dev/null +++ b/cmd/dovecot-auth-cli/test_exists_error.cmy @@ -0,0 +1,15 @@ + +userdb unix_listen .dovecot-userdb + +c = ./dovecot-auth-cli .dovecot exists username + +userdb -> VERSION 1 1 +userdb -> SPID 12345 + +userdb <- VERSION 1 1 +userdb <- USER 1 username service=smtp + +userdb -> OTHER + +c <~ no: invalid response: +c wait 0 diff --git a/cmd/dovecot-auth-cli/test_wrong_command.cmy b/cmd/dovecot-auth-cli/test_wrong_command.cmy new file mode 100644 index 0000000..afcd774 --- /dev/null +++ b/cmd/dovecot-auth-cli/test_wrong_command.cmy @@ -0,0 +1,4 @@ + +c = ./dovecot-auth-cli .missingsocket something +c <- unknown subcommand +c wait 0 diff --git a/internal/dovecot/dovecot_test.go b/internal/dovecot/dovecot_test.go index f2fd887..0fc044d 100644 --- a/internal/dovecot/dovecot_test.go +++ b/internal/dovecot/dovecot_test.go @@ -117,3 +117,9 @@ func mustListen(t *testing.T, path string) *net.UnixListener { return l } + +func TestNotASocket(t *testing.T) { + if isUnixSocket("/doesnotexist") { + t.Errorf("isUnixSocket(/doesnotexist) returned true") + } +} diff --git a/test/util/chamuyero b/test/util/chamuyero index 40929ff..0c5bc56 100755 --- a/test/util/chamuyero +++ b/test/util/chamuyero @@ -42,6 +42,8 @@ class Process (object): def wait(self): return self.cmd.wait() + def close(self): + return self.cmd.terminate() class Sock (object): """A (generic) socket. @@ -77,6 +79,10 @@ class Sock (object): self.has_conn.wait() return self.connr.readline() + def close(self): + self.connr.close() + self.connw.close() + self.sock.close() class UnixSock (Sock): def __init__(self, addr): @@ -239,6 +245,10 @@ class Interpreter (object): self.runtime_error("return code did not match:\n" + " expected %s, got %d" % (params, retcode)) + # close Close the process. + elif op == "close": + self.procs[proc].close() + else: self.syntax_error("unknown syntax")