def test_bot_legacy_permissions(configfactory, botfactory, triggerfactory): """ Make sure permissions match after being updated from both RPL_NAMREPLY and RPL_WHOREPLY, #1482 """ mockbot = botfactory(configfactory('default.cfg', TMP_CONFIG)) nick = tools.Identifier("Admin") # RPL_NAMREPLY mockwrapper = triggerfactory.wrapper( mockbot, ":test.example.com 353 Foo = #test :Foo ~@Admin") coretasks.handle_names(mockwrapper, mockwrapper._trigger) assert '#test' in mockbot.channels assert nick in mockbot.channels["#test"].privileges assert '#test' in mockbot.privileges assert nick in mockbot.privileges["#test"] channel_privileges = mockbot.channels["#test"].privileges[nick] privileges = mockbot.privileges["#test"][nick] assert channel_privileges == privileges # RPL_WHOREPLY mockwrapper = triggerfactory.wrapper( mockbot, ":test.example.com 352 Foo #test " "~Admin adminhost test.example.com Admin Hr~ :0 Admin") coretasks.recv_who(mockwrapper, mockwrapper._trigger) channel_privileges = mockbot.channels["#test"].privileges[nick] privileges = mockbot.privileges["#test"][nick] assert channel_privileges == privileges assert mockbot.users.get(nick) is not None
def test_bot_mixed_mode_removal(sopel): """ Ensure mixed mode types like -h+a are handled Sopel 6.6.6 and older did not handle this correctly. #1575 """ # RPL_NAMREPLY to create Users and (zeroed) privs for user in set("Uvoice Uop".split(" ")): pretrigger = PreTrigger( "Foo", ":test.example.com 353 Foo = #test :Foo %s" % user ) trigger = Trigger(sopel.config, pretrigger, None) coretasks.handle_names(MockSopelWrapper(sopel, trigger), trigger) pretrigger = PreTrigger("Foo", "MODE #test +qao Uvoice Uvoice Uvoice") trigger = Trigger(sopel.config, pretrigger, None) coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) pretrigger = PreTrigger( "Foo", "MODE #test -o+o-qa+v Uvoice Uop Uvoice Uvoice Uvoice" ) trigger = Trigger(sopel.config, pretrigger, None) coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) assert sopel.channels["#test"].privileges[Identifier("Uvoice")] == VOICE assert sopel.channels["#test"].privileges[Identifier("Uop")] == OP
def test_bot_legacy_permissions(sopel_bot): """ Make sure permissions match after being updated from both RPL_NAMREPLY and RPL_WHOREPLY, #1482 """ nick = Identifier("Admin") # RPL_NAMREPLY pretrigger = PreTrigger("Foo", ":test.example.com 353 Foo = #test :Foo ~@Admin") trigger = Trigger(sopel_bot.config, pretrigger, None) coretasks.handle_names(sopel_bot, trigger) assert (sopel_bot.channels["#test"].privileges[nick] == sopel_bot.privileges["#test"][nick]) # RPL_WHOREPLY pretrigger = PreTrigger( "Foo", ":test.example.com 352 Foo #test ~Admin adminhost test.example.com Admin Hr~ :0 Admin", ) trigger = Trigger(sopel_bot.config, pretrigger, None) coretasks.recv_who(sopel_bot, trigger) assert (sopel_bot.channels["#test"].privileges[nick] == sopel_bot.privileges["#test"][nick]) assert sopel_bot.users.get(nick) is not None
def test_bot_legacy_permissions(sopel): """ Make sure permissions match after being updated from both RPL_NAMREPLY and RPL_WHOREPLY, #1482 """ nick = Identifier("Admin") # RPL_NAMREPLY pretrigger = PreTrigger("Foo", ":test.example.com 353 Foo = #test :Foo ~@Admin") trigger = Trigger(sopel.config, pretrigger, None) coretasks.handle_names(MockSopelWrapper(sopel, trigger), trigger) assert sopel.channels["#test"].privileges[nick] == sopel.privileges["#test"][nick] # RPL_WHOREPLY pretrigger = PreTrigger( "Foo", ":test.example.com 352 Foo #test ~Admin adminhost test.example.com Admin Hr~ :0 Admin", ) trigger = Trigger(sopel.config, pretrigger, None) coretasks.recv_who(MockSopelWrapper(sopel, trigger), trigger) assert sopel.channels["#test"].privileges[nick] == sopel.privileges["#test"][nick] assert sopel.users.get(nick) is not None
def test_mode_colon(sopel): """ Ensure mode messages with colons are parsed properly """ # RPL_NAMREPLY to create Users and (zeroed) privs for user in set("Uvoice Uadmin".split(" ")): pretrigger = PreTrigger( "Foo", ":test.example.com 353 Foo = #test :Foo %s" % user) trigger = Trigger(sopel.config, pretrigger, None) coretasks.handle_names(MockSopelWrapper(sopel, trigger), trigger) pretrigger = PreTrigger("Foo", "MODE #test +av Uadmin :Uvoice") trigger = Trigger(sopel.config, pretrigger, None) coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) assert sopel.channels["#test"].privileges[Identifier("Uvoice")] == VOICE assert sopel.channels["#test"].privileges[Identifier("Uadmin")] == ADMIN
def test_bot_mixed_mode_types(sopel): """ Ensure mixed argument- and non-argument- modes are handled Sopel 6.6.6 and older did not behave well. #1575 """ # RPL_NAMREPLY to create Users and (zeroed) privs for user in set("Uvoice Uop Uadmin Uvoice2 Uop2 Uadmin2".split(" ")): pretrigger = PreTrigger( "Foo", ":test.example.com 353 Foo = #test :Foo %s" % user) trigger = Trigger(sopel.config, pretrigger, None) coretasks.handle_names(MockSopelWrapper(sopel, trigger), trigger) # Non-attribute-requiring non-permission mode pretrigger = PreTrigger("Foo", "MODE #test +amov Uadmin Uop Uvoice") trigger = Trigger(sopel.config, pretrigger, None) coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) assert sopel.channels["#test"].privileges[Identifier("Uvoice")] == VOICE assert sopel.channels["#test"].privileges[Identifier("Uop")] == OP assert sopel.channels["#test"].privileges[Identifier("Uadmin")] == ADMIN # Attribute-requiring non-permission modes # This results in a _send_who, which isn't supported in MockSopel or this # test, so we just make sure it results in an exception instead of privesc. pretrigger = PreTrigger("Foo", "MODE #test +abov Uadmin2 x!y@z Uop2 Uvoice2") trigger = Trigger(sopel.config, pretrigger, None) try: coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) except AttributeError as e: if e.args[ 0] == "'MockSopel' object has no attribute 'enabled_capabilities'": return assert sopel.channels["#test"].privileges[Identifier("Uvoice2")] == VOICE assert sopel.channels["#test"].privileges[Identifier("Uop2")] == OP assert sopel.channels["#test"].privileges[Identifier("Uadmin2")] == ADMIN
def test_bot_mixed_mode_types(sopel): """ Ensure mixed argument- and non-argument- modes are handled Sopel 6.6.6 and older did not behave well. #1575 """ # RPL_NAMREPLY to create Users and (zeroed) privs for user in set("Uvoice Uop Uadmin Uvoice2 Uop2 Uadmin2".split(" ")): pretrigger = PreTrigger( "Foo", ":test.example.com 353 Foo = #test :Foo %s" % user ) trigger = Trigger(sopel.config, pretrigger, None) coretasks.handle_names(MockSopelWrapper(sopel, trigger), trigger) # Non-attribute-requiring non-permission mode pretrigger = PreTrigger("Foo", "MODE #test +amov Uadmin Uop Uvoice") trigger = Trigger(sopel.config, pretrigger, None) coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) assert sopel.channels["#test"].privileges[Identifier("Uvoice")] == VOICE assert sopel.channels["#test"].privileges[Identifier("Uop")] == OP assert sopel.channels["#test"].privileges[Identifier("Uadmin")] == ADMIN # Attribute-requiring non-permission modes # This results in a _send_who, which isn't supported in MockSopel or this # test, so we just make sure it results in an exception instead of privesc. pretrigger = PreTrigger("Foo", "MODE #test +abov Uadmin2 x!y@z Uop2 Uvoice2") trigger = Trigger(sopel.config, pretrigger, None) try: coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) except AttributeError as e: if e.args[0] == "'MockSopel' object has no attribute 'enabled_capabilities'": return assert sopel.channels["#test"].privileges[Identifier("Uvoice2")] == VOICE assert sopel.channels["#test"].privileges[Identifier("Uop2")] == OP assert sopel.channels["#test"].privileges[Identifier("Uadmin2")] == ADMIN
def test_bot_mixed_modes(sopel): """ Ensure mixed modes like +vha are tracked correctly. Sopel 6.6.6 and older would assign all modes to all users. #1575 """ # RPL_NAMREPLY to create Users and (zeroed) privs for user in set("Unothing Uvoice Uhalfop Uop Uadmin Uowner".split(" ")): pretrigger = PreTrigger( "Foo", ":test.example.com 353 Foo = #test :Foo %s" % user ) trigger = Trigger(sopel.config, pretrigger, None) coretasks.handle_names(MockSopelWrapper(sopel, trigger), trigger) pretrigger = PreTrigger("Foo", "MODE #test +qvhao Uowner Uvoice Uhalfop Uadmin Uop") trigger = Trigger(sopel.config, pretrigger, None) coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) assert sopel.channels["#test"].privileges[Identifier("Unothing")] == 0 assert sopel.channels["#test"].privileges[Identifier("Uvoice")] == VOICE assert sopel.channels["#test"].privileges[Identifier("Uhalfop")] == HALFOP assert sopel.channels["#test"].privileges[Identifier("Uop")] == OP assert sopel.channels["#test"].privileges[Identifier("Uadmin")] == ADMIN assert sopel.channels["#test"].privileges[Identifier("Uowner")] == OWNER
def test_bot_mixed_mode_removal(sopel): """ Ensure mixed mode types like -h+a are handled Sopel 6.6.6 and older did not handle this correctly. #1575 """ # RPL_NAMREPLY to create Users and (zeroed) privs for user in set("Uvoice Uop".split(" ")): pretrigger = PreTrigger( "Foo", ":test.example.com 353 Foo = #test :Foo %s" % user) trigger = Trigger(sopel.config, pretrigger, None) coretasks.handle_names(MockSopelWrapper(sopel, trigger), trigger) pretrigger = PreTrigger("Foo", "MODE #test +qao Uvoice Uvoice Uvoice") trigger = Trigger(sopel.config, pretrigger, None) coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) pretrigger = PreTrigger( "Foo", "MODE #test -o+o-qa+v Uvoice Uop Uvoice Uvoice Uvoice") trigger = Trigger(sopel.config, pretrigger, None) coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) assert sopel.channels["#test"].privileges[Identifier("Uvoice")] == VOICE assert sopel.channels["#test"].privileges[Identifier("Uop")] == OP
def test_bot_mixed_modes(sopel): """ Ensure mixed modes like +vha are tracked correctly. Sopel 6.6.6 and older would assign all modes to all users. #1575 """ # RPL_NAMREPLY to create Users and (zeroed) privs for user in set("Unothing Uvoice Uhalfop Uop Uadmin Uowner".split(" ")): pretrigger = PreTrigger( "Foo", ":test.example.com 353 Foo = #test :Foo %s" % user) trigger = Trigger(sopel.config, pretrigger, None) coretasks.handle_names(MockSopelWrapper(sopel, trigger), trigger) pretrigger = PreTrigger( "Foo", "MODE #test +qvhao Uowner Uvoice Uhalfop Uadmin Uop") trigger = Trigger(sopel.config, pretrigger, None) coretasks.track_modes(MockSopelWrapper(sopel, trigger), trigger) assert sopel.channels["#test"].privileges[Identifier("Unothing")] == 0 assert sopel.channels["#test"].privileges[Identifier("Uvoice")] == VOICE assert sopel.channels["#test"].privileges[Identifier("Uhalfop")] == HALFOP assert sopel.channels["#test"].privileges[Identifier("Uop")] == OP assert sopel.channels["#test"].privileges[Identifier("Uadmin")] == ADMIN assert sopel.channels["#test"].privileges[Identifier("Uowner")] == OWNER