Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/wpa_supplicant.h" |
| 6 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 7 | #include <gtest/gtest.h> |
| 8 | |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 9 | #include "shill/mock_log.h" |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 10 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 11 | using std::map; |
| 12 | using std::string; |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 13 | using testing::_; |
| 14 | using testing::EndsWith; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 15 | |
| 16 | namespace shill { |
| 17 | |
| 18 | class WPASupplicantTest : public testing::Test { |
| 19 | public: |
| 20 | WPASupplicantTest() {} |
| 21 | virtual ~WPASupplicantTest() {} |
| 22 | |
| 23 | protected: |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 24 | typedef map<string, DBus::Variant> PropertyMap; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 25 | |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 26 | PropertyMap property_map_; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 27 | }; |
| 28 | |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 29 | TEST_F(WPASupplicantTest, ExtractRemoteCertificationEmpty) { |
| 30 | string subject; |
| 31 | uint32 depth = 0; |
| 32 | ScopedMockLog log; |
| 33 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("no depth parameter."))); |
| 34 | EXPECT_FALSE(WPASupplicant::ExtractRemoteCertification( |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 35 | property_map_, &subject, &depth)); |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 36 | EXPECT_EQ("", subject); |
| 37 | EXPECT_EQ(0, depth); |
| 38 | } |
| 39 | |
| 40 | TEST_F(WPASupplicantTest, ExtractRemoteCertificationDepthOnly) { |
| 41 | string subject; |
| 42 | const uint32 kDepthValue = 100; |
| 43 | uint32 depth = kDepthValue - 1; |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 44 | property_map_[WPASupplicant::kInterfacePropertyDepth] |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 45 | .writer().append_uint32(kDepthValue); |
| 46 | ScopedMockLog log; |
| 47 | EXPECT_CALL(log, |
| 48 | Log(logging::LOG_ERROR, _, EndsWith("no subject parameter."))); |
| 49 | EXPECT_FALSE(WPASupplicant::ExtractRemoteCertification( |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 50 | property_map_, &subject, &depth)); |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 51 | EXPECT_EQ("", subject); |
| 52 | EXPECT_NE(kDepthValue, depth); |
| 53 | } |
| 54 | |
| 55 | TEST_F(WPASupplicantTest, ExtractRemoteCertificationSubjectOnly) { |
| 56 | const char kSubjectName[] = "subject-name"; |
| 57 | string subject; |
| 58 | uint32 depth = 0; |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 59 | property_map_[WPASupplicant::kInterfacePropertySubject] |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 60 | .writer().append_string(kSubjectName); |
| 61 | ScopedMockLog log; |
| 62 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, EndsWith("no depth parameter."))); |
| 63 | EXPECT_FALSE(WPASupplicant::ExtractRemoteCertification( |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 64 | property_map_, &subject, &depth)); |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 65 | EXPECT_EQ("", subject); |
| 66 | EXPECT_EQ(0, depth); |
| 67 | } |
| 68 | |
| 69 | TEST_F(WPASupplicantTest, ExtractRemoteCertificationSubjectAndDepth) { |
| 70 | const char kSubjectName[] = "subject-name"; |
| 71 | string subject; |
| 72 | const uint32 kDepthValue = 100; |
| 73 | uint32 depth = 0; |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 74 | property_map_[WPASupplicant::kInterfacePropertySubject] |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 75 | .writer().append_string(kSubjectName); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 76 | property_map_[WPASupplicant::kInterfacePropertyDepth] |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 77 | .writer().append_uint32(kDepthValue); |
| 78 | EXPECT_TRUE(WPASupplicant::ExtractRemoteCertification( |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 79 | property_map_, &subject, &depth)); |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 80 | EXPECT_EQ(kSubjectName, subject); |
| 81 | EXPECT_EQ(kDepthValue, depth); |
| 82 | } |
| 83 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 84 | } // namespace shill |