// // Helpers // internal IEnumerable <Bosh.Change> GetDbItemsFromFixture(string name) { return(XDocument.Parse(GetFixture(name, "xml")) .XPathSelectElements("//*[starts-with(local-name(), 'item_')]") .Select(x => new Bosh.Change(x.Attribute("id").Value, Bosh.ParseOperation(x.Attribute("unique_id").Value).Value, x.Attribute("type")?.Value ?? "", x.Attribute("dataInBase64")?.Value ?? ""))); }
public void GetChanges_return_all_changes_from_multiple_requests() { var flow = new RestFlow() .Post(GetFixture("large-vault-response-1", "xml")) .Post(GetFixture("large-vault-response-2", "xml")); // No Connect call here. Skipped as it's irrelevant in testing. var items = new Bosh("http://bosh.test", UserJid, "password", new RestBoshTransport(flow)) .GetChanges("command-name", "4213") .ToArray(); Assert.Equal(72, items.Length); }
public void Connect_and_GetChanges_connect_to_server_and_return_items() { var response1 = "<?xml version='1.0'?>" + "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='14390431958505390437' from='11.ucp-ntfy.kaspersky-labs.com' version='1.0' xml:lang='en'>" + "<stream:features>" + "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>" + "<mechanism>PLAIN</mechanism>" + "</mechanisms>" + "</stream:features>"; var response2 = "<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>"; var response3 = "<?xml version='1.0'?>" + "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='14390431958505390437' from='11.ucp-ntfy.kaspersky-labs.com' version='1.0' xml:lang='en'>" + "<stream:features><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>" + "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>" + "</stream:features>"; var response4 = "<iq id='_bind_auth_2' type='result'>" + "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>" + $"<jid>{UserJid.Full}</jid>" + "</bind>" + "</iq>"; var response5 = "<iq type='result' xmlns='jabber:client' id='_session_auth_2'>" + "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>" + "</iq>"; var response6 = "<message from='*****@*****.**' to='543b964d-6259-489e-9603-3495827e0d1b#browser#[email protected]/portaldxy0y5u7qng' id='kpmgetdatabasecommand-browser-5-1608648668840' ctime='2021-01-04T13:35:09Z' type='normal' cid='266e6c8f-aeb1-4245-8878-0a0f23fb6706' no_offline='true'>" + "<root unique_id='23090566' productVersion='' protocolVersion='' deviceType='0' osType='0' projectVersion='' serverBlob='' MPAuthKeyValueInBase64='' moreChangesAvailable='0' xmlns=''>" + "<changes>" + "<item_0000 unique_id='1203265602' id='2408deddd3cc4519bad9aa33b7e50166' type='Database' dataInBase64='AgAAANwFAAA5tWNHwWyUw2VT/XSnzSyx'/>" + "</changes>" + "</root>" + "<body/>" + "</message>"; var flow = new RestFlow() .Post(response1) .ExpectContent("<stream:stream") .ExpectContent($"to='{UserJid.Host}'") .ExpectContent("xmlns='jabber:client'") .ExpectContent("xmlns:stream='http://etherx.jabber.org/streams'") .ExpectContent("version='1.0'") .Post(response2) .ExpectContent("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>") .ExpectContent("") // TODO: Check auth string is sent .ExpectContent("</auth>") .Post(response3) .ExpectContent("<stream:stream") .ExpectContent($"to='{UserJid.Host}'") .ExpectContent("xmlns='jabber:client'") .ExpectContent("xmlns:stream='http://etherx.jabber.org/streams'") .ExpectContent("version='1.0'") .Post(response4) .ExpectContent("<iq type='set' id='_bind_auth_2' xmlns='jabber:client'>") .ExpectContent("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>") .ExpectContent($"<resource>{UserJid.Resource}</resource>") .ExpectContent("></bind></iq>") .Post(response5) .ExpectContent("<iq type='set' id='_session_auth_2' xmlns='jabber:client'>") .ExpectContent("<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>") .ExpectContent("></iq>") .Post(response6) .ExpectContent("<message ") .ExpectContent("xmlns='jabber:client'") .ExpectContent("id='command-name-browser-5-") .ExpectContent($"to='kpm-sync@{UserJid.Host}'") .ExpectContent($"from='{UserJid.Bare}'") .ExpectContent("<root unique_id='1203265602' productVersion='' protocolVersion='' projectVersion='9.2.0.1' deviceType='0' osType='0'") .ExpectContent("></message>"); var bosh = new Bosh("http://bosh.test", UserJid, "password", new RestBoshTransport(flow)); bosh.Connect(); var items = bosh.GetChanges("command-name", "1203265602").ToArray(); Assert.Single(items); Assert.Equal("Database", items[0].Type); Assert.Equal("AgAAANwFAAA5tWNHwWyUw2VT/XSnzSyx", items[0].Data); }
internal void ParseOperation_returns_null(string operation) { Assert.Null(Bosh.ParseOperation(operation)); }
internal void ParseOperation_returns_operation(string operation, Bosh.Operation?expected) { Assert.Equal(expected, Bosh.ParseOperation(operation)); }