blob: d0b0cb55ee8b248fb5f09fbb7660c6bca0946c70 [file] [log] [blame]
Paul Stewart0654ece2013-03-26 15:21:26 -07001// 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 Stewart0654ece2013-03-26 15:21:26 -07007#include <gtest/gtest.h>
8
Paul Stewart735eab52013-03-29 09:19:23 -07009#include "shill/mock_log.h"
Paul Stewart0654ece2013-03-26 15:21:26 -070010
Paul Stewart0654ece2013-03-26 15:21:26 -070011using std::map;
12using std::string;
Paul Stewart735eab52013-03-29 09:19:23 -070013using testing::_;
14using testing::EndsWith;
Paul Stewart0654ece2013-03-26 15:21:26 -070015
16namespace shill {
17
18class WPASupplicantTest : public testing::Test {
19 public:
20 WPASupplicantTest() {}
21 virtual ~WPASupplicantTest() {}
22
23 protected:
Paul Stewartc43cbbe2013-04-11 06:29:30 -070024 typedef map<string, DBus::Variant> PropertyMap;
Paul Stewart0654ece2013-03-26 15:21:26 -070025
Paul Stewartc43cbbe2013-04-11 06:29:30 -070026 PropertyMap property_map_;
Paul Stewart0654ece2013-03-26 15:21:26 -070027};
28
Paul Stewart735eab52013-03-29 09:19:23 -070029TEST_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 Stewartc43cbbe2013-04-11 06:29:30 -070035 property_map_, &subject, &depth));
Paul Stewart735eab52013-03-29 09:19:23 -070036 EXPECT_EQ("", subject);
37 EXPECT_EQ(0, depth);
38}
39
40TEST_F(WPASupplicantTest, ExtractRemoteCertificationDepthOnly) {
41 string subject;
42 const uint32 kDepthValue = 100;
43 uint32 depth = kDepthValue - 1;
Paul Stewartc43cbbe2013-04-11 06:29:30 -070044 property_map_[WPASupplicant::kInterfacePropertyDepth]
Paul Stewart735eab52013-03-29 09:19:23 -070045 .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 Stewartc43cbbe2013-04-11 06:29:30 -070050 property_map_, &subject, &depth));
Paul Stewart735eab52013-03-29 09:19:23 -070051 EXPECT_EQ("", subject);
52 EXPECT_NE(kDepthValue, depth);
53}
54
55TEST_F(WPASupplicantTest, ExtractRemoteCertificationSubjectOnly) {
56 const char kSubjectName[] = "subject-name";
57 string subject;
58 uint32 depth = 0;
Paul Stewartc43cbbe2013-04-11 06:29:30 -070059 property_map_[WPASupplicant::kInterfacePropertySubject]
Paul Stewart735eab52013-03-29 09:19:23 -070060 .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 Stewartc43cbbe2013-04-11 06:29:30 -070064 property_map_, &subject, &depth));
Paul Stewart735eab52013-03-29 09:19:23 -070065 EXPECT_EQ("", subject);
66 EXPECT_EQ(0, depth);
67}
68
69TEST_F(WPASupplicantTest, ExtractRemoteCertificationSubjectAndDepth) {
70 const char kSubjectName[] = "subject-name";
71 string subject;
72 const uint32 kDepthValue = 100;
73 uint32 depth = 0;
Paul Stewartc43cbbe2013-04-11 06:29:30 -070074 property_map_[WPASupplicant::kInterfacePropertySubject]
Paul Stewart735eab52013-03-29 09:19:23 -070075 .writer().append_string(kSubjectName);
Paul Stewartc43cbbe2013-04-11 06:29:30 -070076 property_map_[WPASupplicant::kInterfacePropertyDepth]
Paul Stewart735eab52013-03-29 09:19:23 -070077 .writer().append_uint32(kDepthValue);
78 EXPECT_TRUE(WPASupplicant::ExtractRemoteCertification(
Paul Stewartc43cbbe2013-04-11 06:29:30 -070079 property_map_, &subject, &depth));
Paul Stewart735eab52013-03-29 09:19:23 -070080 EXPECT_EQ(kSubjectName, subject);
81 EXPECT_EQ(kDepthValue, depth);
82}
83
Paul Stewart0654ece2013-03-26 15:21:26 -070084} // namespace shill