blob: b8b58ca06eb7c809539759fe4158c9461625d677 [file] [log] [blame]
Peter Qiu326b6cf2015-09-02 11:11:42 -07001//
2// Copyright (C) 2014 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//
Peter Qiuf0731732014-11-11 09:46:41 -080016
17#include "apmanager/config.h"
18
Peter Qiufb39ba42014-11-21 09:09:59 -080019#include <string>
20
Peter Qiuf0731732014-11-11 09:46:41 -080021#include <base/strings/string_util.h>
22#include <base/strings/stringprintf.h>
Peter Qiuf0731732014-11-11 09:46:41 -080023#include <gmock/gmock.h>
24#include <gtest/gtest.h>
25
Peter Qiu7a420d32015-09-22 11:25:15 -070026#if !defined(__ANDROID__)
27#include <chromeos/dbus/service_constants.h>
28#else
29#include "dbus/apmanager/dbus-constants.h"
30#endif
31
Peter Qiufb39ba42014-11-21 09:09:59 -080032#include "apmanager/mock_device.h"
33#include "apmanager/mock_manager.h"
34
Peter Qiu8e785b92014-11-24 10:01:08 -080035using ::testing::_;
Peter Qiufb39ba42014-11-21 09:09:59 -080036using ::testing::Mock;
37using ::testing::Return;
Peter Qiu8e785b92014-11-24 10:01:08 -080038using ::testing::SetArgumentPointee;
Peter Qiuf0731732014-11-11 09:46:41 -080039namespace apmanager {
40
41namespace {
42
43const char kServicePath[] = "/manager/services/0";
44const char kSsid[] = "TestSsid";
45const char kInterface[] = "uap0";
Peter Qiu68303292014-12-10 10:42:13 -080046const char kBridgeInterface[] = "br0";
Peter Qiubfd410e2015-01-09 15:14:20 -080047const char kControlInterfacePath[] = "/var/run/apmanager/hostapd/ctrl_iface";
Peter Qiuf0731732014-11-11 09:46:41 -080048const char kPassphrase[] = "Passphrase";
Peter Qiu8e785b92014-11-24 10:01:08 -080049const char k24GHzHTCapab[] = "[LDPC SMPS-STATIC GF SHORT-GI-20]";
50const char k5GHzHTCapab[] =
51 "[LDPC HT40+ SMPS-STATIC GF SHORT-GI-20 SHORT-GI-40]";
52
Peter Qiuf0731732014-11-11 09:46:41 -080053const uint16_t k24GHzChannel = 6;
54const uint16_t k5GHzChannel = 36;
55
56const char kExpected80211gConfigContent[] = "ssid=TestSsid\n"
57 "channel=6\n"
Peter Qiuf0731732014-11-11 09:46:41 -080058 "interface=uap0\n"
Peter Qiu8e785b92014-11-24 10:01:08 -080059 "hw_mode=g\n"
Peter Qiuf0731732014-11-11 09:46:41 -080060 "driver=nl80211\n"
61 "fragm_threshold=2346\n"
62 "rts_threshold=2347\n";
63
Peter Qiu68303292014-12-10 10:42:13 -080064const char kExpected80211gBridgeConfigContent[] = "ssid=TestSsid\n"
65 "bridge=br0\n"
66 "channel=6\n"
67 "interface=uap0\n"
68 "hw_mode=g\n"
69 "driver=nl80211\n"
70 "fragm_threshold=2346\n"
71 "rts_threshold=2347\n";
72
Peter Qiubfd410e2015-01-09 15:14:20 -080073const char kExpected80211gCtrlIfaceConfigContent[] =
74 "ssid=TestSsid\n"
75 "channel=6\n"
76 "interface=uap0\n"
77 "hw_mode=g\n"
78 "ctrl_interface=/var/run/apmanager/hostapd/ctrl_iface\n"
Peter Qiu015a4992015-10-06 13:30:32 -070079#if !defined(__ANDROID__)
Peter Qiubfd410e2015-01-09 15:14:20 -080080 "ctrl_interface_group=apmanager\n"
Peter Qiu015a4992015-10-06 13:30:32 -070081#else
82 "ctrl_interface_group=system\n"
83#endif // __ANDROID__
Peter Qiubfd410e2015-01-09 15:14:20 -080084 "driver=nl80211\n"
85 "fragm_threshold=2346\n"
86 "rts_threshold=2347\n";
87
Peter Qiu8e785b92014-11-24 10:01:08 -080088const char kExpected80211n5GHzConfigContent[] =
89 "ssid=TestSsid\n"
90 "channel=36\n"
91 "interface=uap0\n"
92 "ieee80211n=1\n"
93 "ht_capab=[LDPC HT40+ SMPS-STATIC GF SHORT-GI-20 SHORT-GI-40]\n"
94 "hw_mode=a\n"
95 "driver=nl80211\n"
96 "fragm_threshold=2346\n"
97 "rts_threshold=2347\n";
Peter Qiuf0731732014-11-11 09:46:41 -080098
Peter Qiu8e785b92014-11-24 10:01:08 -080099const char kExpected80211n24GHzConfigContent[] =
100 "ssid=TestSsid\n"
101 "channel=6\n"
102 "interface=uap0\n"
103 "ieee80211n=1\n"
104 "ht_capab=[LDPC SMPS-STATIC GF SHORT-GI-20]\n"
105 "hw_mode=g\n"
106 "driver=nl80211\n"
107 "fragm_threshold=2346\n"
108 "rts_threshold=2347\n";
Peter Qiuf0731732014-11-11 09:46:41 -0800109
110const char kExpectedRsnConfigContent[] = "ssid=TestSsid\n"
111 "channel=6\n"
Peter Qiuf0731732014-11-11 09:46:41 -0800112 "interface=uap0\n"
Peter Qiu8e785b92014-11-24 10:01:08 -0800113 "hw_mode=g\n"
Peter Qiuf0731732014-11-11 09:46:41 -0800114 "wpa=2\n"
115 "rsn_pairwise=CCMP\n"
116 "wpa_key_mgmt=WPA-PSK\n"
117 "wpa_passphrase=Passphrase\n"
118 "driver=nl80211\n"
119 "fragm_threshold=2346\n"
120 "rts_threshold=2347\n";
121
122} // namespace
123
124class ConfigTest : public testing::Test {
125 public:
Peter Qiufb39ba42014-11-21 09:09:59 -0800126 ConfigTest() : config_(&manager_, kServicePath) {}
127
128 void SetupDevice(const std::string& interface) {
129 // Setup mock device.
Peter Qiu8e785b92014-11-24 10:01:08 -0800130 device_ = new MockDevice();
131 device_->SetPreferredApInterface(interface);
Peter Qiufb39ba42014-11-21 09:09:59 -0800132 EXPECT_CALL(manager_, GetDeviceFromInterfaceName(interface))
Peter Qiu8e785b92014-11-24 10:01:08 -0800133 .WillRepeatedly(Return(device_));
Peter Qiufb39ba42014-11-21 09:09:59 -0800134 }
Peter Qiuf0731732014-11-11 09:46:41 -0800135
136 protected:
137 Config config_;
Peter Qiufb39ba42014-11-21 09:09:59 -0800138 MockManager manager_;
Peter Qiu8e785b92014-11-24 10:01:08 -0800139 scoped_refptr<MockDevice> device_;
Peter Qiuf0731732014-11-11 09:46:41 -0800140};
141
Peter Qiu376e4042014-11-13 09:40:28 -0800142MATCHER_P(IsConfigErrorStartingWith, message, "") {
Peter Qiuf0731732014-11-11 09:46:41 -0800143 return arg != nullptr &&
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700144 arg->GetDomain() == brillo::errors::dbus::kDomain &&
Alex Vakulenkoe8f58982015-06-15 12:53:22 -0700145 arg->GetCode() == kConfigError &&
146 base::StartsWithASCII(arg->GetMessage(), message, false);
Peter Qiuf0731732014-11-11 09:46:41 -0800147}
148
Peter Qiu8e785b92014-11-24 10:01:08 -0800149TEST_F(ConfigTest, GetFrequencyFromChannel) {
150 uint32_t frequency;
151 // Invalid channel.
152 EXPECT_FALSE(Config::GetFrequencyFromChannel(0, &frequency));
153 EXPECT_FALSE(Config::GetFrequencyFromChannel(166, &frequency));
154 EXPECT_FALSE(Config::GetFrequencyFromChannel(14, &frequency));
155 EXPECT_FALSE(Config::GetFrequencyFromChannel(33, &frequency));
156
157 // Valid channel.
158 const uint32_t kChannel1Frequency = 2412;
159 const uint32_t kChannel13Frequency = 2472;
160 const uint32_t kChannel34Frequency = 5170;
161 const uint32_t kChannel165Frequency = 5825;
162 EXPECT_TRUE(Config::GetFrequencyFromChannel(1, &frequency));
163 EXPECT_EQ(kChannel1Frequency, frequency);
164 EXPECT_TRUE(Config::GetFrequencyFromChannel(13, &frequency));
165 EXPECT_EQ(kChannel13Frequency, frequency);
166 EXPECT_TRUE(Config::GetFrequencyFromChannel(34, &frequency));
167 EXPECT_EQ(kChannel34Frequency, frequency);
168 EXPECT_TRUE(Config::GetFrequencyFromChannel(165, &frequency));
169 EXPECT_EQ(kChannel165Frequency, frequency);
170}
171
Peter Qiu68303292014-12-10 10:42:13 -0800172TEST_F(ConfigTest, ValidateSsid) {
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700173 brillo::ErrorPtr error;
Peter Qiu68303292014-12-10 10:42:13 -0800174 // SSID must contain between 1 and 32 characters.
175 EXPECT_TRUE(config_.ValidateSsid(&error, "s"));
176 EXPECT_TRUE(config_.ValidateSsid(&error, std::string(32, 'c')));
177 EXPECT_FALSE(config_.ValidateSsid(&error, ""));
178 EXPECT_FALSE(config_.ValidateSsid(&error, std::string(33, 'c')));
179}
180
181TEST_F(ConfigTest, ValidateSecurityMode) {
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700182 brillo::ErrorPtr error;
Peter Qiu68303292014-12-10 10:42:13 -0800183 EXPECT_TRUE(config_.ValidateSecurityMode(&error, kSecurityModeNone));
184 EXPECT_TRUE(config_.ValidateSecurityMode(&error, kSecurityModeRSN));
185 EXPECT_FALSE(config_.ValidateSecurityMode(&error, "InvalidSecurityMode"));
186}
187
188TEST_F(ConfigTest, ValidatePassphrase) {
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700189 brillo::ErrorPtr error;
Peter Qiu68303292014-12-10 10:42:13 -0800190 // Passpharse must contain between 8 and 63 characters.
191 EXPECT_TRUE(config_.ValidatePassphrase(&error, std::string(8, 'c')));
192 EXPECT_TRUE(config_.ValidatePassphrase(&error, std::string(63, 'c')));
193 EXPECT_FALSE(config_.ValidatePassphrase(&error, std::string(7, 'c')));
194 EXPECT_FALSE(config_.ValidatePassphrase(&error, std::string(64, 'c')));
195}
196
197TEST_F(ConfigTest, ValidateHwMode) {
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700198 brillo::ErrorPtr error;
Peter Qiu68303292014-12-10 10:42:13 -0800199 EXPECT_TRUE(config_.ValidateHwMode(&error, kHwMode80211a));
200 EXPECT_TRUE(config_.ValidateHwMode(&error, kHwMode80211b));
201 EXPECT_TRUE(config_.ValidateHwMode(&error, kHwMode80211g));
202 EXPECT_TRUE(config_.ValidateHwMode(&error, kHwMode80211n));
203 EXPECT_TRUE(config_.ValidateHwMode(&error, kHwMode80211ac));
204 EXPECT_FALSE(config_.ValidateSecurityMode(&error, "InvalidHwMode"));
205}
206
207TEST_F(ConfigTest, ValidateOperationMode) {
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700208 brillo::ErrorPtr error;
Peter Qiu68303292014-12-10 10:42:13 -0800209 EXPECT_TRUE(config_.ValidateOperationMode(&error, kOperationModeServer));
210 EXPECT_TRUE(config_.ValidateOperationMode(&error, kOperationModeBridge));
211 EXPECT_FALSE(config_.ValidateOperationMode(&error, "InvalidMode"));
212}
213
214TEST_F(ConfigTest, ValidateChannel) {
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700215 brillo::ErrorPtr error;
Peter Qiu68303292014-12-10 10:42:13 -0800216 EXPECT_TRUE(config_.ValidateChannel(&error, 1));
217 EXPECT_TRUE(config_.ValidateChannel(&error, 13));
218 EXPECT_TRUE(config_.ValidateChannel(&error, 34));
219 EXPECT_TRUE(config_.ValidateChannel(&error, 165));
220 EXPECT_FALSE(config_.ValidateChannel(&error, 0));
221 EXPECT_FALSE(config_.ValidateChannel(&error, 14));
222 EXPECT_FALSE(config_.ValidateChannel(&error, 33));
223 EXPECT_FALSE(config_.ValidateChannel(&error, 166));
224}
225
Peter Qiuf0731732014-11-11 09:46:41 -0800226TEST_F(ConfigTest, NoSsid) {
227 config_.SetChannel(k24GHzChannel);
228 config_.SetHwMode(kHwMode80211g);
229 config_.SetInterfaceName(kInterface);
230
231 std::string config_content;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700232 brillo::ErrorPtr error;
Peter Qiuf0731732014-11-11 09:46:41 -0800233 EXPECT_FALSE(config_.GenerateConfigFile(&error, &config_content));
Peter Qiu376e4042014-11-13 09:40:28 -0800234 EXPECT_THAT(error, IsConfigErrorStartingWith("SSID not specified"));
Peter Qiuf0731732014-11-11 09:46:41 -0800235}
236
Peter Qiufb39ba42014-11-21 09:09:59 -0800237TEST_F(ConfigTest, NoInterface) {
238 // Basic 80211.g configuration.
239 config_.SetSsid(kSsid);
240 config_.SetChannel(k24GHzChannel);
241 config_.SetHwMode(kHwMode80211g);
242
243 // No device available, fail to generate config file.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700244 brillo::ErrorPtr error;
Peter Qiufb39ba42014-11-21 09:09:59 -0800245 std::string config_content;
246 EXPECT_CALL(manager_, GetAvailableDevice()).WillOnce(Return(nullptr));
247 EXPECT_FALSE(config_.GenerateConfigFile(&error, &config_content));
248 EXPECT_THAT(error, IsConfigErrorStartingWith("No device available"));
249 Mock::VerifyAndClearExpectations(&manager_);
250
251 // Device available, config file should be generated without any problem.
252 scoped_refptr<MockDevice> device = new MockDevice();
253 device->SetPreferredApInterface(kInterface);
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700254 brillo::ErrorPtr error1;
Peter Qiufb39ba42014-11-21 09:09:59 -0800255 EXPECT_CALL(manager_, GetAvailableDevice()).WillOnce(Return(device));
256 EXPECT_TRUE(config_.GenerateConfigFile(&error1, &config_content));
257 EXPECT_NE(std::string::npos, config_content.find(
258 kExpected80211gConfigContent))
259 << "Expected to find the following config...\n"
260 << kExpected80211gConfigContent << "..within content...\n"
261 << config_content;
262 EXPECT_EQ(nullptr, error1.get());
263 Mock::VerifyAndClearExpectations(&manager_);
264}
265
Peter Qiu68303292014-12-10 10:42:13 -0800266TEST_F(ConfigTest, InvalidInterface) {
267 // Basic 80211.g configuration.
268 config_.SetSsid(kSsid);
269 config_.SetChannel(k24GHzChannel);
270 config_.SetHwMode(kHwMode80211g);
271 config_.SetInterfaceName(kInterface);
272
273 // No device available, fail to generate config file.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700274 brillo::ErrorPtr error;
Peter Qiu68303292014-12-10 10:42:13 -0800275 std::string config_content;
276 EXPECT_CALL(manager_, GetDeviceFromInterfaceName(kInterface))
277 .WillOnce(Return(nullptr));
278 EXPECT_FALSE(config_.GenerateConfigFile(&error, &config_content));
279 EXPECT_THAT(error,
280 IsConfigErrorStartingWith(
281 "Unable to find device for the specified interface"));
282 Mock::VerifyAndClearExpectations(&manager_);
283}
284
285TEST_F(ConfigTest, BridgeMode) {
286 config_.SetSsid(kSsid);
287 config_.SetChannel(k24GHzChannel);
288 config_.SetHwMode(kHwMode80211g);
289 config_.SetInterfaceName(kInterface);
290 config_.SetOperationMode(kOperationModeBridge);
291
292 // Bridge interface required for bridge mode.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700293 brillo::ErrorPtr error;
Peter Qiu68303292014-12-10 10:42:13 -0800294 std::string config_content;
295 EXPECT_FALSE(config_.GenerateConfigFile(&error, &config_content));
296 EXPECT_THAT(error,
297 IsConfigErrorStartingWith("Bridge interface not specified"));
298
299 // Set bridge interface, config file should be generated without error.
300 config_.SetBridgeInterface(kBridgeInterface);
301 // Setup mock device.
302 SetupDevice(kInterface);
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700303 brillo::ErrorPtr error1;
Peter Qiu68303292014-12-10 10:42:13 -0800304 std::string config_content1;
305 EXPECT_TRUE(config_.GenerateConfigFile(&error1, &config_content1));
306 EXPECT_NE(std::string::npos, config_content1.find(
307 kExpected80211gBridgeConfigContent))
308 << "Expected to find the following config...\n"
309 << kExpected80211gBridgeConfigContent << "..within content...\n"
310 << config_content1;
311 EXPECT_EQ(nullptr, error1.get());
312}
313
Peter Qiuf0731732014-11-11 09:46:41 -0800314TEST_F(ConfigTest, 80211gConfig) {
315 config_.SetSsid(kSsid);
316 config_.SetChannel(k24GHzChannel);
317 config_.SetHwMode(kHwMode80211g);
318 config_.SetInterfaceName(kInterface);
319
Peter Qiufb39ba42014-11-21 09:09:59 -0800320 // Setup mock device.
321 SetupDevice(kInterface);
322
Peter Qiuf0731732014-11-11 09:46:41 -0800323 std::string config_content;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700324 brillo::ErrorPtr error;
Peter Qiuf0731732014-11-11 09:46:41 -0800325 EXPECT_TRUE(config_.GenerateConfigFile(&error, &config_content));
326 EXPECT_NE(std::string::npos, config_content.find(
327 kExpected80211gConfigContent))
328 << "Expected to find the following config...\n"
329 << kExpected80211gConfigContent << "..within content...\n"
330 << config_content;
331 EXPECT_EQ(nullptr, error.get());
332}
333
Peter Qiubfd410e2015-01-09 15:14:20 -0800334TEST_F(ConfigTest, 80211gConfigWithControlInterface) {
335 config_.SetSsid(kSsid);
336 config_.SetChannel(k24GHzChannel);
337 config_.SetHwMode(kHwMode80211g);
338 config_.SetInterfaceName(kInterface);
339 config_.set_control_interface(kControlInterfacePath);
340
341 // Setup mock device.
342 SetupDevice(kInterface);
343
344 std::string config_content;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700345 brillo::ErrorPtr error;
Peter Qiubfd410e2015-01-09 15:14:20 -0800346 EXPECT_TRUE(config_.GenerateConfigFile(&error, &config_content));
347 EXPECT_NE(std::string::npos, config_content.find(
348 kExpected80211gCtrlIfaceConfigContent))
349 << "Expected to find the following config...\n"
350 << kExpected80211gCtrlIfaceConfigContent << "..within content...\n"
351 << config_content;
352 EXPECT_EQ(nullptr, error.get());
353}
354
Peter Qiuf0731732014-11-11 09:46:41 -0800355TEST_F(ConfigTest, 80211nConfig) {
356 config_.SetSsid(kSsid);
357 config_.SetHwMode(kHwMode80211n);
358 config_.SetInterfaceName(kInterface);
359
Peter Qiufb39ba42014-11-21 09:09:59 -0800360 // Setup mock device.
361 SetupDevice(kInterface);
362
Peter Qiuf0731732014-11-11 09:46:41 -0800363 // 5GHz channel.
364 config_.SetChannel(k5GHzChannel);
365 std::string ghz5_config_content;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700366 brillo::ErrorPtr error;
Peter Qiu8e785b92014-11-24 10:01:08 -0800367 std::string ht_capab_5ghz(k5GHzHTCapab);
368 EXPECT_CALL(*device_.get(), GetHTCapability(k5GHzChannel, _))
369 .WillOnce(DoAll(SetArgumentPointee<1>(ht_capab_5ghz), Return(true)));
Peter Qiuf0731732014-11-11 09:46:41 -0800370 EXPECT_TRUE(config_.GenerateConfigFile(&error, &ghz5_config_content));
371 EXPECT_NE(std::string::npos, ghz5_config_content.find(
372 kExpected80211n5GHzConfigContent))
373 << "Expected to find the following config...\n"
374 << kExpected80211n5GHzConfigContent << "..within content...\n"
375 << ghz5_config_content;
376 EXPECT_EQ(nullptr, error.get());
Peter Qiu8e785b92014-11-24 10:01:08 -0800377 Mock::VerifyAndClearExpectations(device_.get());
Peter Qiuf0731732014-11-11 09:46:41 -0800378
379 // 2.4GHz channel.
380 config_.SetChannel(k24GHzChannel);
381 std::string ghz24_config_content;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700382 brillo::ErrorPtr error1;
Peter Qiu8e785b92014-11-24 10:01:08 -0800383 std::string ht_capab_24ghz(k24GHzHTCapab);
384 EXPECT_CALL(*device_.get(), GetHTCapability(k24GHzChannel, _))
385 .WillOnce(DoAll(SetArgumentPointee<1>(ht_capab_24ghz), Return(true)));
Peter Qiuf0731732014-11-11 09:46:41 -0800386 EXPECT_TRUE(config_.GenerateConfigFile(&error1, &ghz24_config_content));
387 EXPECT_NE(std::string::npos, ghz24_config_content.find(
388 kExpected80211n24GHzConfigContent))
389 << "Expected to find the following config...\n"
390 << kExpected80211n24GHzConfigContent << "..within content...\n"
391 << ghz24_config_content;
392 EXPECT_EQ(nullptr, error.get());
Peter Qiu8e785b92014-11-24 10:01:08 -0800393 Mock::VerifyAndClearExpectations(device_.get());
Peter Qiuf0731732014-11-11 09:46:41 -0800394}
395
396TEST_F(ConfigTest, RsnConfig) {
397 config_.SetSsid(kSsid);
398 config_.SetChannel(k24GHzChannel);
399 config_.SetHwMode(kHwMode80211g);
400 config_.SetInterfaceName(kInterface);
401 config_.SetSecurityMode(kSecurityModeRSN);
402
Peter Qiufb39ba42014-11-21 09:09:59 -0800403 // Setup mock device.
404 SetupDevice(kInterface);
405
Peter Qiuf0731732014-11-11 09:46:41 -0800406 // Failed due to no passphrase specified.
407 std::string config_content;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700408 brillo::ErrorPtr error;
Peter Qiuf0731732014-11-11 09:46:41 -0800409 EXPECT_FALSE(config_.GenerateConfigFile(&error, &config_content));
Peter Qiu376e4042014-11-13 09:40:28 -0800410 EXPECT_THAT(error, IsConfigErrorStartingWith(
Peter Qiuf0731732014-11-11 09:46:41 -0800411 base::StringPrintf("Passphrase not set for security mode: %s",
412 kSecurityModeRSN)));
413
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700414 brillo::ErrorPtr error1;
Peter Qiuf0731732014-11-11 09:46:41 -0800415 config_.SetPassphrase(kPassphrase);
416 EXPECT_TRUE(config_.GenerateConfigFile(&error1, &config_content));
417 EXPECT_NE(std::string::npos, config_content.find(
418 kExpectedRsnConfigContent))
419 << "Expected to find the following config...\n"
420 << kExpectedRsnConfigContent << "..within content...\n"
421 << config_content;
422 EXPECT_EQ(nullptr, error1.get());
423}
424
425} // namespace apmanager