OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium 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 "base/strings/stringprintf.h" |
| 6 #include "extensions/browser/api/vpn_provider/vpn_provider_api.h" |
| 7 #include "extensions/browser/api_test_utils.h" |
| 8 #include "extensions/common/extension.h" |
| 9 #include "extensions/common/test_util.h" |
| 10 #include "extensions/shell/test/shell_test.h" |
| 11 |
| 12 using extensions::api_test_utils::RunFunctionAndReturnSingleResult; |
| 13 using extensions::api_test_utils::RunFunctionAndReturnError; |
| 14 |
| 15 namespace extensions { |
| 16 |
| 17 const char* kErrorMessages[] = {"Address CIDR sanity check failed.", |
| 18 "DNS server IP sanity check failed.", |
| 19 "Unauthorized access."}; |
| 20 |
| 21 struct SetParameterTestParams { |
| 22 int err_index; |
| 23 const char* address; |
| 24 const char* dns_server; |
| 25 }; |
| 26 |
| 27 const SetParameterTestParams set_parameter_tests[] = { |
| 28 {0, "1+++", ""}, // + not allowed |
| 29 {0, "1", ""}, // 3 dots and separator missing |
| 30 {0, "1..", ""}, // A dot and separator missing |
| 31 {0, "1...", ""}, // Separator missing |
| 32 {0, "1.../", ""}, // No digit after separator in address |
| 33 {1, "1.../0", ""}, // Address passes sanity check, DNS incorrect |
| 34 {1, "1.../0", "1.../"}, // DNS is not CIDR |
| 35 {2, "1.../0", "1..."}, // Okay |
| 36 {0, ".../", "..."}, // Address has no digits |
| 37 {0, "0.../", "..."}, // Address has no digits post separator |
| 38 {1, "0.../0", "..."}, // Address passes sanity check, DNS incorrect |
| 39 {2, "0.../0", "...0"}, // Okay |
| 40 {0, "1...:::/1279abe", ""}, // : not allowed for ipv4 |
| 41 {0, "1.../1279abcde", ""}, // Hex not allowed after separator |
| 42 {0, "1...abcde/1279", ""}, // Hex not allowed in ipv4 |
| 43 {1, "1.../1279", ""}, // Address passes sanity check, DNS incorrect |
| 44 {2, "1.../1279", "1..."}, // Okay |
| 45 {0, "1--++", ""}, // + and - not supported |
| 46 {0, "1.1.1.1", ""}, // Missing separator |
| 47 {0, "1.1.1.1/", ""}, // No digits after separator in address |
| 48 {1, "1.1.1.1/1", ""}, // Address passes sanity check, DNS incorrect |
| 49 {2, "1.1.1.1/1", "1.1.1.1"}, // Okay |
| 50 {0, "1.1.1./e", "1.1.1."}, // Hex not okay in ipv4 |
| 51 {2, "1.1.1./0", "1.1.1."}, // Okay |
| 52 {1, "1.../1279", "..."}, // No digits in DNS |
| 53 {1, "1.../1279", "e..."}, // Hex not allowed in ipv4 |
| 54 {2, "1.../1279", "4..."}, // Okay |
| 55 }; |
| 56 |
| 57 class VpnProviderApiTest |
| 58 : public AppShellTest, |
| 59 public testing::WithParamInterface<const SetParameterTestParams*> {}; |
| 60 |
| 61 IN_PROC_BROWSER_TEST_P(VpnProviderApiTest, SetParametersFunction) { |
| 62 scoped_refptr<extensions::VpnProviderSetParametersFunction> |
| 63 set_parameter_function( |
| 64 new extensions::VpnProviderSetParametersFunction()); |
| 65 scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); |
| 66 |
| 67 set_parameter_function->set_extension(empty_extension.get()); |
| 68 set_parameter_function->set_has_callback(true); |
| 69 |
| 70 const std::string args = |
| 71 "[" |
| 72 " {" |
| 73 " \"address\": \"%s\"," |
| 74 " \"exclusionList\": []," |
| 75 " \"inclusionList\": []," |
| 76 " \"dnsServers\": [\"%s\"]" |
| 77 " }" |
| 78 "]"; |
| 79 |
| 80 EXPECT_EQ(kErrorMessages[GetParam()->err_index], |
| 81 RunFunctionAndReturnError( |
| 82 set_parameter_function.get(), |
| 83 base::StringPrintf(args.c_str(), GetParam()->address, |
| 84 GetParam()->dns_server), |
| 85 browser_context())); |
| 86 } |
| 87 |
| 88 INSTANTIATE_TEST_CASE_P( |
| 89 SetParameterTestParams, |
| 90 VpnProviderApiTest, |
| 91 testing::Range(&set_parameter_tests[0], |
| 92 &set_parameter_tests[arraysize(set_parameter_tests)])); |
| 93 |
| 94 } // namespace extensions |
OLD | NEW |