Home | History | Annotate | Download | only in supplicant
      1 //
      2 // Copyright (C) 2013 The Android Open Source Project
      3 //
      4 // Licensed under the Apache License, Version 2.0 (the "License");
      5 // you may not use this file except in compliance with the License.
      6 // You may obtain a copy of the License at
      7 //
      8 //      http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unless required by applicable law or agreed to in writing, software
     11 // distributed under the License is distributed on an "AS IS" BASIS,
     12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 // See the License for the specific language governing permissions and
     14 // limitations under the License.
     15 //
     16 
     17 #include "shill/supplicant/wpa_supplicant.h"
     18 
     19 #include <gtest/gtest.h>
     20 
     21 #include "shill/mock_log.h"
     22 
     23 using std::map;
     24 using std::string;
     25 using testing::_;
     26 using testing::EndsWith;
     27 
     28 namespace shill {
     29 
     30 class WPASupplicantTest : public testing::Test {
     31  public:
     32   WPASupplicantTest() {}
     33   virtual ~WPASupplicantTest() {}
     34 
     35  protected:
     36   KeyValueStore property_map_;
     37 };
     38 
     39 TEST_F(WPASupplicantTest, ExtractRemoteCertificationEmpty) {
     40   string subject;
     41   uint32_t depth = 0;
     42   ScopedMockLog log;
     43   EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("no depth parameter.")));
     44   EXPECT_FALSE(WPASupplicant::ExtractRemoteCertification(
     45       property_map_, &subject, &depth));
     46   EXPECT_EQ("", subject);
     47   EXPECT_EQ(0, depth);
     48 }
     49 
     50 TEST_F(WPASupplicantTest, ExtractRemoteCertificationDepthOnly) {
     51   string subject;
     52   const uint32_t kDepthValue = 100;
     53   uint32_t depth = kDepthValue - 1;
     54   property_map_.SetUint(WPASupplicant::kInterfacePropertyDepth, kDepthValue);
     55   ScopedMockLog log;
     56   EXPECT_CALL(log,
     57               Log(logging::LOG_ERROR, _, EndsWith("no subject parameter.")));
     58   EXPECT_FALSE(WPASupplicant::ExtractRemoteCertification(
     59       property_map_, &subject, &depth));
     60   EXPECT_EQ("", subject);
     61   EXPECT_NE(kDepthValue, depth);
     62 }
     63 
     64 TEST_F(WPASupplicantTest, ExtractRemoteCertificationSubjectOnly) {
     65   const char kSubjectName[] = "subject-name";
     66   string subject;
     67   uint32_t depth = 0;
     68   property_map_.SetString(WPASupplicant::kInterfacePropertySubject,
     69                           kSubjectName);
     70   ScopedMockLog log;
     71   EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("no depth parameter.")));
     72   EXPECT_FALSE(WPASupplicant::ExtractRemoteCertification(
     73       property_map_, &subject, &depth));
     74   EXPECT_EQ("", subject);
     75   EXPECT_EQ(0, depth);
     76 }
     77 
     78 TEST_F(WPASupplicantTest, ExtractRemoteCertificationSubjectAndDepth) {
     79   const char kSubjectName[] = "subject-name";
     80   string subject;
     81   const uint32_t kDepthValue = 100;
     82   uint32_t depth = 0;
     83   property_map_.SetString(WPASupplicant::kInterfacePropertySubject,
     84                           kSubjectName);
     85   property_map_.SetUint(WPASupplicant::kInterfacePropertyDepth, kDepthValue);
     86   EXPECT_TRUE(WPASupplicant::ExtractRemoteCertification(
     87       property_map_, &subject, &depth));
     88   EXPECT_EQ(kSubjectName, subject);
     89   EXPECT_EQ(kDepthValue, depth);
     90 }
     91 
     92 }  // namespace shill
     93