shill: Do not change EAP's key_management to an invalid value

If a profile does not include "EAP.KeyMgmt" (which can happen if
fliamflam's default profile is being used), the current code sets
the key_management property of WiFiService to an empty string,
which is not valid.  This change uses a smart default value based
on the WiFi.security tag of the profile.

BUG=chromium-os:26087
TEST=manual.  Connect to an open network using flimflam.  Delete shill's
default profile from /var/cache/shill.  Switch to shill.  Reboot.  Verify
that ChromeOS connects to the open network used by flimflam.
All unit tests pass.

Change-Id: Idf251567214a195f12aa0e121a0deae663de28a2
Reviewed-on: https://gerrit.chromium.org/gerrit/19692
Reviewed-by: Paul Stewart <pstew@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: Gary Morain <gmorain@chromium.org>
Commit-Ready: Gary Morain <gmorain@chromium.org>
diff --git a/wifi_service.cc b/wifi_service.cc
index aa59bf6..831d126 100644
--- a/wifi_service.cc
+++ b/wifi_service.cc
@@ -715,8 +715,14 @@
                                                security.c_str()));
 }
 
-void WiFiService::set_eap(const EapCredentials &eap) {
-  Service::set_eap(eap);
+void WiFiService::set_eap(const EapCredentials &new_eap) {
+  EapCredentials modified_eap = new_eap;
+
+  // An empty key_management field is invalid.  Prevent it, if possible.
+  if (modified_eap.key_management.empty()) {
+    modified_eap.key_management = eap().key_management;
+  }
+  Service::set_eap(modified_eap);
   UpdateConnectable();
 }