tests/integration/connect.lua

1
local harness = require "harness";
2
 
3
return {
4
	{ "logs in and binds the requested resource", function (t)
5
		t.client("alice", function (c)
6
			assert(c.authenticated, "not authenticated");
7
			assert(c.bound, "resource not bound");
8
			assert(c.jid == "alice@"..harness.domain.."/verse-test", "unexpected jid: "..tostring(c.jid));
9
			t.done();
10
		end);
11
	end };
12
 
13
	{ "negotiates STARTTLS when offered", function (t)
14
		t.client("alice", function (c)
15
			assert(c.secure, "connection is not secure");
16
			t.done();
17
		end);
18
	end };
19
 
20
	{ "authenticates with the mechanism expected for this build", function (t)
21
		-- The default build has Prosody's hashes and strbitop, so SCRAM is usable;
22
		-- the standalone build's pure-Lua fallbacks only support PLAIN.
23
		local expected = os.getenv("VERSE_TEST_FLAVOUR") == "standalone" and "PLAIN" or "SCRAM%-SHA%-1";
24
		local mechanism;
25
		local c = t.client("alice", function ()
26
			assert(mechanism, "no auth stanza seen");
27
			assert(mechanism:match("^"..expected), "unexpected mechanism: "..mechanism);
28
			t.done();
29
		end);
30
		c:hook("stanza-out", function (stanza)
31
			if stanza.name == "auth" then mechanism = stanza.attr.mechanism; end
32
		end);
33
	end };
34
 
35
	{ "reports a wrong password as not-authorized", function (t)
36
		local c = t.client("alice", nil, { password = "wrong", expect_failure = true, expect_disconnect = true });
37
		c:hook("authentication-failure", t.cb(function (err)
38
			assert(err.condition == "not-authorized", "unexpected condition: "..tostring(err.condition));
39
			t.done();
40
		end));
41
	end };
42
 
43
	{ "pings the server", function (t)
44
		t.client("alice", function (c)
45
			c:ping(harness.domain, t.cb(function (time, jid, err)
46
				assert(time, "ping failed: "..tostring(err and err.condition));
47
				assert(jid == harness.domain);
48
				t.done();
49
			end));
50
		end, { plugins = { "ping" } });
51
	end };
52
 
53
	{ "queries the server software version", function (t)
54
		t.client("alice", function (c)
55
			c:query_version(harness.domain, t.cb(function (v)
56
				assert(not v.error, "version query failed: "..tostring(v.condition));
57
				assert(v.name == "Prosody", "unexpected name: "..tostring(v.name));
58
				assert(v.version and #v.version > 0, "missing version");
59
				t.done();
60
			end));
61
		end, { plugins = { "version" } });
62
	end };
63
 
64
	{ "answers a version query from another client", function (t)
65
		local bob;
66
		t.client("alice", function (alice)
67
			alice.version:set{ name = "verse-test", version = "1.0" };
68
			bob = t.client("bob", function ()
69
				bob:query_version(alice.jid, t.cb(function (v)
70
					assert(v.name == "verse-test", "unexpected name: "..tostring(v.name));
71
					assert(v.version == "1.0", "unexpected version: "..tostring(v.version));
72
					t.done();
73
				end));
74
			end, { plugins = { "version" } });
75
		end, { plugins = { "version" } });
76
	end };
77
};