Commit 308869aa authored by louiz’'s avatar louiz’

Do not ignore empty values when receiving a data form

Otherwise, these fields cannot be emptied by the user

fix #3281
parent f125de48
...@@ -399,24 +399,20 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com ...@@ -399,24 +399,20 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com
options.col<Database::VerifyCert>() = val; options.col<Database::VerifyCert>() = val;
} }
else if (field->get_tag("var") == "fingerprint" && value && else if (field->get_tag("var") == "fingerprint" && value)
!value->get_inner().empty())
{ {
options.col<Database::TrustedFingerprint>() = value->get_inner(); options.col<Database::TrustedFingerprint>() = value->get_inner();
} }
#endif // BOTAN_FOUND #endif // BOTAN_FOUND
else if (field->get_tag("var") == "pass" && else if (field->get_tag("var") == "pass" && value)
value && !value->get_inner().empty())
options.col<Database::Pass>() = value->get_inner(); options.col<Database::Pass>() = value->get_inner();
else if (field->get_tag("var") == "after_connect_command" && else if (field->get_tag("var") == "after_connect_command")
value && !value->get_inner().empty())
options.col<Database::AfterConnectionCommand>() = value->get_inner(); options.col<Database::AfterConnectionCommand>() = value->get_inner();
else if (field->get_tag("var") == "username" && else if (field->get_tag("var") == "username" && value)
value && !value->get_inner().empty())
{ {
auto username = value->get_inner(); auto username = value->get_inner();
// The username must not contain spaces // The username must not contain spaces
...@@ -424,16 +420,13 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com ...@@ -424,16 +420,13 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com
options.col<Database::Username>() = username; options.col<Database::Username>() = username;
} }
else if (field->get_tag("var") == "realname" && else if (field->get_tag("var") == "realname" && value)
value && !value->get_inner().empty())
options.col<Database::Realname>() = value->get_inner(); options.col<Database::Realname>() = value->get_inner();
else if (field->get_tag("var") == "encoding_out" && else if (field->get_tag("var") == "encoding_out" && value)
value && !value->get_inner().empty())
options.col<Database::EncodingOut>() = value->get_inner(); options.col<Database::EncodingOut>() = value->get_inner();
else if (field->get_tag("var") == "encoding_in" && else if (field->get_tag("var") == "encoding_in" && value)
value && !value->get_inner().empty())
options.col<Database::EncodingIn>() = value->get_inner(); options.col<Database::EncodingIn>() = value->get_inner();
} }
...@@ -572,16 +565,13 @@ bool handle_irc_channel_configuration_form(XmppComponent& xmpp_component, const ...@@ -572,16 +565,13 @@ bool handle_irc_channel_configuration_form(XmppComponent& xmpp_component, const
{ {
const XmlNode *value = field->get_child("value", "jabber:x:data"); const XmlNode *value = field->get_child("value", "jabber:x:data");
if (field->get_tag("var") == "encoding_out" && if (field->get_tag("var") == "encoding_out" && value)
value && !value->get_inner().empty())
options.col<Database::EncodingOut>() = value->get_inner(); options.col<Database::EncodingOut>() = value->get_inner();
else if (field->get_tag("var") == "encoding_in" && else if (field->get_tag("var") == "encoding_in" && value)
value && !value->get_inner().empty())
options.col<Database::EncodingIn>() = value->get_inner(); options.col<Database::EncodingIn>() = value->get_inner();
else if (field->get_tag("var") == "persistent" && else if (field->get_tag("var") == "persistent" && value)
value)
options.col<Database::Persistent>() = to_bool(value->get_inner()); options.col<Database::Persistent>() = to_bool(value->get_inner());
else if (field->get_tag("var") == "record_history" && else if (field->get_tag("var") == "record_history" &&
value && !value->get_inner().empty()) value && !value->get_inner().empty())
......
...@@ -2551,6 +2551,41 @@ if __name__ == '__main__': ...@@ -2551,6 +2551,41 @@ if __name__ == '__main__':
), ),
partial(send_stanza, "<iq type='set' id='id4' from='{jid_one}/{resource_one}' to='{irc_server_one}'><command xmlns='http://jabber.org/protocol/commands' action='cancel' node='configure' sessionid='{sessionid}' /></iq>"), partial(send_stanza, "<iq type='set' id='id4' from='{jid_one}/{resource_one}' to='{irc_server_one}'><command xmlns='http://jabber.org/protocol/commands' action='cancel' node='configure' sessionid='{sessionid}' /></iq>"),
partial(expect_stanza, "/iq[@type='result']/commands:command[@node='configure'][@status='canceled']"), partial(expect_stanza, "/iq[@type='result']/commands:command[@node='configure'][@status='canceled']"),
# Same thing, but try to empty some values
partial(send_stanza, "<iq type='set' id='id1' from='{jid_one}/{resource_one}' to='{irc_server_one}'><command xmlns='http://jabber.org/protocol/commands' node='configure' action='execute' /></iq>"),
partial(expect_stanza, "/iq[@type='result']",
after = partial(save_value, "sessionid", partial(extract_attribute, "/iq[@type='result']/commands:command[@node='configure']", "sessionid"))
),
partial(send_stanza, "<iq type='set' id='id2' from='{jid_one}/{resource_one}' to='{irc_server_one}'>"
"<command xmlns='http://jabber.org/protocol/commands' node='configure' sessionid='{sessionid}' action='next'>"
"<x xmlns='jabber:x:data' type='submit'>"
"<field var='pass'><value></value></field>"
"<field var='after_connect_command'><value></value></field>"
"<field var='username'><value></value></field>"
"<field var='realname'><value></value></field>"
"<field var='encoding_out'><value></value></field>"
"<field var='encoding_in'><value></value></field>"
"</x></command></iq>"),
partial(expect_stanza, "/iq[@type='result']/commands:command[@node='configure'][@status='completed']/commands:note[@type='info'][text()='Configuration successfully applied.']"),
partial(send_stanza, "<iq type='set' id='id3' from='{jid_one}/{resource_one}' to='{irc_server_one}'><command xmlns='http://jabber.org/protocol/commands' node='configure' action='execute' /></iq>"),
partial(expect_stanza, ("/iq[@type='result']/commands:command[@node='configure'][@sessionid][@status='executing']",
"/iq/commands:command/dataform:x[@type='form']/dataform:title[text()='Configure the IRC server irc.localhost']",
"/iq/commands:command/dataform:x[@type='form']/dataform:instructions[text()='Edit the form, to configure the settings of the IRC server irc.localhost']",
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='pass']/dataform:value",
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='after_connect_command']/dataform:value",
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='username']/dataform:value",
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='realname']/dataform:value",
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='encoding_in']/dataform:value",
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='encoding_out']/dataform:value",
"/iq/commands:command/commands:actions/commands:next",
),
after = partial(save_value, "sessionid", partial(extract_attribute, "/iq[@type='result']/commands:command[@node='configure']", "sessionid"))
),
partial(send_stanza, "<iq type='set' id='id4' from='{jid_one}/{resource_one}' to='{irc_server_one}'><command xmlns='http://jabber.org/protocol/commands' action='cancel' node='configure' sessionid='{sessionid}' /></iq>"),
partial(expect_stanza, "/iq[@type='result']/commands:command[@node='configure'][@status='canceled']"),
]), ]),
Scenario("irc_channel_configure", Scenario("irc_channel_configure",
[ [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment