1 /* 2 * Copyright (C) 2020 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 "../VoldNativeServiceValidation.h" 18 19 #include <gtest/gtest.h> 20 21 #include <string_view> 22 23 using namespace std::literals; 24 25 namespace android::vold { 26 27 class VoldNativeServiceValidationTest : public testing::Test {}; 28 TEST_F(VoldNativeServiceValidationTest,CheckArgumentPathTest)29TEST_F(VoldNativeServiceValidationTest, CheckArgumentPathTest) { 30 EXPECT_TRUE(CheckArgumentPath("/").isOk()); 31 EXPECT_TRUE(CheckArgumentPath("/1/2").isOk()); 32 EXPECT_TRUE(CheckArgumentPath("/1/2/").isOk()); 33 EXPECT_TRUE(CheckArgumentPath("/1/2/./3").isOk()); 34 EXPECT_TRUE(CheckArgumentPath("/1/2/./3/.").isOk()); 35 EXPECT_TRUE(CheckArgumentPath( 36 "/very long path with some/ spaces and quite/ uncommon names /in\1 it/") 37 .isOk()); 38 39 EXPECT_FALSE(CheckArgumentPath("").isOk()); 40 EXPECT_FALSE(CheckArgumentPath("relative/path").isOk()); 41 EXPECT_FALSE(CheckArgumentPath("../data/..").isOk()); 42 EXPECT_FALSE(CheckArgumentPath("/../data/..").isOk()); 43 EXPECT_FALSE(CheckArgumentPath("/data/../system").isOk()); 44 EXPECT_FALSE(CheckArgumentPath("/data/..trick/../system").isOk()); 45 EXPECT_FALSE(CheckArgumentPath("/data/..").isOk()); 46 EXPECT_FALSE(CheckArgumentPath("/data/././../apex").isOk()); 47 EXPECT_FALSE(CheckArgumentPath(std::string("/data/strange\0one"sv)).isOk()); 48 EXPECT_FALSE(CheckArgumentPath(std::string("/data/strange\ntwo"sv)).isOk()); 49 } 50 51 } // namespace android::vold 52