shill: WiFiService: Connect to generic form of service

When connecting to a WPA/RSN/PSK service, use the generic form
when instructing wpa_supplicant to connect, so that it will connect
to either "RSN" or "WPA" networks.  There was originally a thought
to restrict this to only the network type specified via the
|security_| field in the service, but since the |security_| field
of WiFi services have historically been created and saved based on
the security mode of the first observed endpoint, this can overly
constrain which APs wpa_supplicant should be allowed to connect to.

While doing this, make sure that connection metrics refer to the
security of the AP that we've connected to instead of the (possibly
generic) version of the security of the service.

BUG=chromium-os:39813
TEST=Unit tests, network_WiFiSecMat

Change-Id: I6c192a247f10f03f88d1ec04856fcdc7bf8e96b6
Reviewed-on: https://gerrit.chromium.org/gerrit/45122
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Ashok Nagarajan <asnagarajan@chromium.org>
Tested-by: Ashok Nagarajan <asnagarajan@chromium.org>
Commit-Queue: Paul Stewart <pstew@chromium.org>
diff --git a/wifi_service_unittest.cc b/wifi_service_unittest.cc
index d5430fd..4eff667 100644
--- a/wifi_service_unittest.cc
+++ b/wifi_service_unittest.cc
@@ -388,8 +388,10 @@
   DBusAdaptor::GetProperties(wifi_service->store(), &properties, NULL);
 }
 
-MATCHER(WPASecurityArgs, "") {
+MATCHER(PSKSecurityArgs, "") {
   return ContainsKey(arg, wpa_supplicant::kPropertySecurityProtocol) &&
+      arg.find(wpa_supplicant::kPropertySecurityProtocol)->second.
+           reader().get_string() == string("WPA RSN") &&
       ContainsKey(arg, wpa_supplicant::kPropertyPreSharedKey);
 }
 
@@ -411,8 +413,7 @@
 
 TEST_F(WiFiServiceTest, ConnectTaskWPA) {
   WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityWpa);
-  EXPECT_CALL(*wifi(),
-              ConnectTo(wifi_service.get(), WPASecurityArgs()));
+  EXPECT_CALL(*wifi(), ConnectTo(wifi_service.get(), PSKSecurityArgs()));
   Error error;
   wifi_service->SetPassphrase("0:mumblemumblem", &error);
   wifi_service->Connect(NULL);
@@ -420,8 +421,7 @@
 
 TEST_F(WiFiServiceTest, ConnectTaskRSN) {
   WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityRsn);
-  EXPECT_CALL(*wifi(),
-              ConnectTo(wifi_service.get(), WPASecurityArgs()));
+  EXPECT_CALL(*wifi(), ConnectTo(wifi_service.get(), PSKSecurityArgs()));
   Error error;
   wifi_service->SetPassphrase("0:mumblemumblem", &error);
   wifi_service->Connect(NULL);
@@ -457,8 +457,7 @@
 
 TEST_F(WiFiServiceTest, ConnectTaskPSK) {
   WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityPsk);
-  EXPECT_CALL(*wifi(),
-              ConnectTo(wifi_service.get(), WPASecurityArgs()));
+  EXPECT_CALL(*wifi(), ConnectTo(wifi_service.get(), PSKSecurityArgs()));
   Error error;
   wifi_service->SetPassphrase("0:mumblemumblem", &error);
   wifi_service->Connect(NULL);