test/muc/tc_muc_mucclient.rb in xmpp4r-0.3.2 vs test/muc/tc_muc_mucclient.rb in xmpp4r-0.4

- old
+ new

@@ -24,11 +24,11 @@ def test_enter_room state { |pres| assert_kind_of(Presence, pres) assert_equal(JID.new('hag66@shakespeare.lit/pda'), pres.from) assert_equal(JID.new('darkcave@macbeth.shakespeare.lit/thirdwitch'), pres.to) - send("<presence from='darkcave@macbeth.shakespeare.lit' to='hag66@shakespeare.lit/pda' type='error'>" + + send("<presence from='darkcave@macbeth.shakespeare.lit' to='hag66@shakespeare.lit/pda' type='error'>" + "<error code='400' type='modify'>" + "<jid-malformed xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error></presence>") } state { |pres| @@ -50,11 +50,11 @@ m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' assert(!m.active?) assert_nil(m.room) - assert_raises(ErrorException) { + assert_raises(ServerError) { m.join('darkcave@macbeth.shakespeare.lit/thirdwitch') } wait_state assert(!m.active?) assert_nil(m.room) @@ -108,11 +108,11 @@ "</presence>") } m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' - assert_raises(ErrorException) { + assert_raises(ServerError) { m.join('darkcave@macbeth.shakespeare.lit/thirdwitch') } wait_state assert(!m.active?) @@ -129,11 +129,11 @@ "</presence>") } m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' - assert_raises(ErrorException) { + assert_raises(ServerError) { m.join('darkcave@macbeth.shakespeare.lit/thirdwitch') } assert(!m.active?) wait_state @@ -147,11 +147,11 @@ "</presence>") } m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' - assert_raises(ErrorException) { + assert_raises(ServerError) { m.join('darkcave@macbeth.shakespeare.lit/thirdwitch') } assert(!m.active?) wait_state @@ -165,11 +165,11 @@ "</presence>") } m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' - assert_raises(ErrorException) { + assert_raises(ServerError) { m.join('darkcave@macbeth.shakespeare.lit/thirdwitch') } assert(!m.active?) wait_state @@ -183,28 +183,28 @@ "</presence>") } m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' - assert_raises(ErrorException) { + assert_raises(ServerError) { m.join('darkcave@macbeth.shakespeare.lit/thirdwitch') } assert(!m.active?) wait_state end def test_locked_room state { |pres| - send("<presence from='darkcave@macbeth.shakespeare.lit' to='hag66@shakespeare.lit/pda' type='error'>" + + send("<presence from='darkcave@macbeth.shakespeare.lit' to='hag66@shakespeare.lit/pda' type='error'>" + "<error code='404' type='cancel'><item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error>" + "</presence>") } m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' - assert_raises(ErrorException) { + assert_raises(ServerError) { m.join('darkcave@macbeth.shakespeare.lit/thirdwitch') } assert(!m.active?) wait_state end @@ -363,11 +363,11 @@ messages_client = 0 @client.add_message_callback { |msg| messages_client += 1 message_lock.run } - + m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' messages_muc = 0 m.add_message_callback { |msg| messages_muc += 1 @@ -423,11 +423,11 @@ presences_client = 0 @client.add_presence_callback { |pres| presences_client += 1 presence_lock.run - } + } m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' presences_join = 0 m.add_join_callback { |pres| presences_join += 1 @@ -520,11 +520,11 @@ assert(:chat, stanza.type) assert_equal(JID.new('hag66@shakespeare.lit/pda'), stanza.from) assert_equal(JID.new('darkcave@macbeth.shakespeare.lit/firstwitch'), stanza.to) assert_equal('Third message', stanza.body) } - + m = MUC::MUCClient.new(@client) m.my_jid = 'hag66@shakespeare.lit/pda' assert_equal(m, m.join('darkcave@macbeth.shakespeare.lit/thirdwitch')) wait_state @@ -577,18 +577,254 @@ assert_equal(m, m.join('darkcave@macbeth.shakespeare.lit/thirdwitch')) wait_state assert(m.active?) assert_equal('thirdwitch', m.nick) - assert_raises(ErrorException) { + assert_raises(ServerError) { m.nick = 'secondwitch' } wait_state assert(m.active?) assert_equal('thirdwitch', m.nick) m.nick = 'oldhag' wait_state assert(m.active?) assert_equal('oldhag', m.nick) + end + + # JEP-0045: 10.2 Room Configuration + def test_configuration + room = JID.new('darkcave@macbeth.shakespeare.lit/thirdwitch') + jid = JID.new('hag66@shakespeare.lit/pda') + + state { |pres| + send( + "<presence from='darkcave@macbeth.shakespeare.lit/thirdwitch' to='hag66@shakespeare.lit/pda'>" + + "<x xmlns='http://jabber.org/protocol/muc#user'><item affiliation='owner' role='moderator'/></x>" + + "</presence>" + ) + } + + state { |iq| + assert_kind_of(Jabber::Iq,iq) + assert_equal(jid, iq.from) + assert_equal(room.strip, iq.to) + assert_equal(:get, iq.type) + + assert_kind_of(Jabber::MUC::IqQueryMUCOwner, iq.first_element('query')) + + send(muc_config_form.sub("id='config1'","id='#{iq.id}'")) + } + + state { |room_config| + assert_kind_of(Jabber::Iq, room_config) + assert_equal(room.strip, room_config.to) + assert_equal(:set, room_config.type) + + assert_kind_of(Jabber::MUC::IqQueryMUCOwner, room_config.first_element('query')) + + form = room_config.first_element('query/x') + assert_kind_of(Dataforms::XData, form) + assert_equal(:submit, form.type) + assert_equal(1, form.elements.size) + assert_equal('muc#roomconfig_roomname', form.first_element('field').var) + assert_equal(['Dunsinane'], form.first_element('field').values) + + send(muc_config_acknowledgement.sub("id='config1'","id='#{room_config.id}'")) + } + + m = MUC::MUCClient.new(@client) + m.my_jid = jid + m.join(room) + wait_state + assert_equal(true, m.owner?) + + assert_equal(%w{muc#roomconfig_roomname muc#roomconfig_roomdesc + muc#roomconfig_enablelogging muc#roomconfig_changesubject muc#roomconfig_allowinvites + muc#roomconfig_maxusers muc#roomconfig_presencebroadcast muc#roomconfig_getmemberlist + muc#roomconfig_publicroom muc#roomconfig_persistentroom muc#roomconfig_moderatedroom + muc#roomconfig_membersonly muc#roomconfig_passwordprotectedroom muc#roomconfig_roomsecret + muc#roomconfig_whois muc#roomconfig_roomadmins muc#roomconfig_roomowners}, m.get_room_configuration) + wait_state + + m.submit_room_configuration( 'muc#roomconfig_roomname' => 'Dunsinane' ) + wait_state + end + + # example 150 from XEP-0045 + def muc_config_form + "<iq from='darkcave@macbeth.shakespeare.lit' + id='config1' + to='crone1@shakespeare.lit/desktop' + type='result'> + <query xmlns='http://jabber.org/protocol/muc#owner'> + <x xmlns='jabber:x:data' type='form'> + <title>Configuration for \"darkcave\" Room</title> + <instructions> + Complete this form to make changes to + the configuration of your room. + </instructions> + <field + type='hidden' + var='FORM_TYPE'> + <value>http://jabber.org/protocol/muc#roomconfig</value> + </field> + <field + label='Natural-Language Room Name' + type='text-single' + var='muc#roomconfig_roomname'> + <value>A Dark Cave</value> + </field> + <field + label='Short Description of Room' + type='text-single' + var='muc#roomconfig_roomdesc'> + <value>The place for all good witches!</value> + </field> + <field + label='Enable Public Logging?' + type='boolean' + var='muc#roomconfig_enablelogging'> + <value>0</value> + </field> + <field + label='Allow Occupants to Change Subject?' + type='boolean' + var='muc#roomconfig_changesubject'> + <value>0</value> + </field> + <field + label='Allow Occupants to Invite Others?' + type='boolean' + var='muc#roomconfig_allowinvites'> + <value>0</value> + </field> + <field + label='Maximum Number of Occupants' + type='list-single' + var='muc#roomconfig_maxusers'> + <value>10</value> + <option label='10'><value>10</value></option> + <option label='20'><value>20</value></option> + <option label='30'><value>30</value></option> + <option label='50'><value>50</value></option> + <option label='100'><value>100</value></option> + <option label='None'><value>none</value></option> + </field> + <field + label='Roles for which Presence is Broadcast' + type='list-multi' + var='muc#roomconfig_presencebroadcast'> + <value>moderator</value> + <value>participant</value> + <value>visitor</value> + <option label='Moderator'><value>moderator</value></option> + <option label='Participant'><value>participant</value></option> + <option label='Visitor'><value>visitor</value></option> + </field> + <field + label='Roles and Affiliations that May Retrieve Member List' + type='list-multi' + var='muc#roomconfig_getmemberlist'> + <value>moderator</value> + <value>participant</value> + <value>visitor</value> + <option label='Moderator'><value>moderator</value></option> + <option label='Participant'><value>participant</value></option> + <option label='Visitor'><value>visitor</value></option> + </field> + <field + label='Make Room Publicly Searchable?' + type='boolean' + var='muc#roomconfig_publicroom'> + <value>0</value> + </field> + <field + label='Make Room Persistent?' + type='boolean' + var='muc#roomconfig_persistentroom'> + <value>0</value> + </field> + <field + label='Make Room Moderated?' + type='boolean' + var='muc#roomconfig_moderatedroom'> + <value>0</value> + </field> + <field + label='Make Room Members Only?' + type='boolean' + var='muc#roomconfig_membersonly'> + <value>0</value> + </field> + <field + label='Password Required for Entry?' + type='boolean' + var='muc#roomconfig_passwordprotectedroom'> + <value>1</value> + </field> + <field type='fixed'> + <value> + If a password is required to enter this room, + you must specify the password below. + </value> + </field> + <field + label='Password' + type='text-private' + var='muc#roomconfig_roomsecret'> + <value>cauldronburn</value> + </field> + <field + label='Who May Discover Real JIDs?' + type='list-single' + var='muc#roomconfig_whois'> + <value>moderators</value> + <option label='Moderators Only'> + <value>moderators</value> + </option> + <option label='Anyone'> + <value>anyone</value> + </option> + </field> + <field type='fixed'> + <value> + You may specify additional people who have + administrative privileges in the room. Please + provide one Jabber ID per line. + </value> + </field> + <field + label='Room Admins' + type='jid-multi' + var='muc#roomconfig_roomadmins'> + <value>wiccarocks@shakespeare.lit</value> + <value>hecate@shakespeare.lit</value> + </field> + <field type='fixed'> + <value> + You may specify additional owners for this + room. Please provide one Jabber ID per line. + </value> + </field> + <field + label='Room Owners' + type='jid-multi' + var='muc#roomconfig_roomowners'/> + </x> + </query> + </iq>" + end + + def muc_config_acknowledgement + "<iq from='darkcave@macbeth.shakespeare.lit' + id='config1' + to='crone1@shakespeare.lit/desktop'> + <query xmlns='http://jabber.org/protocol/muc#owner'> + <x xmlns='jabber:x:data' type='result'> + <field var='muc#roomconfig_roomname'><value>Dunsinane</value></field> + </x> + </query> + </iq>" end end