summaryrefslogtreecommitdiff
path: root/jni/FuseUtilsTest.cpp
diff options
context:
space:
mode:
authorCorina <corinac@google.com>2020-06-17 21:55:33 +0100
committerCorina <corinac@google.com>2020-06-23 10:18:33 +0100
commit633099b6face730a82eb11cd763b248436af5841 (patch)
tree6a1ccbe85bc30938d7988061b283d9bbaead5149 /jni/FuseUtilsTest.cpp
parentcf035a376f96dcb39a5b1c3936b7e347820b756a (diff)
downloadMediaProvider-633099b6face730a82eb11cd763b248436af5841.tar.gz
Match mounted paths using string comparisons instead of regex.
BUG: 158067533 Test: atest FuseUtilsTest Change-Id: I209c24e553329f77fdf76589bcbf3f502369fba4
Diffstat (limited to 'jni/FuseUtilsTest.cpp')
-rw-r--r--jni/FuseUtilsTest.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/jni/FuseUtilsTest.cpp b/jni/FuseUtilsTest.cpp
new file mode 100644
index 000000000..9d05bc79f
--- /dev/null
+++ b/jni/FuseUtilsTest.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specic language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "FuseUtilsTest"
+
+#include "libfuse_jni/FuseUtils.h"
+
+#include <gtest/gtest.h>
+
+using namespace mediaprovider::fuse;
+
+TEST(FuseUtilsTest, testContainsMount_isTrueForAndroidDataObb) {
+ EXPECT_TRUE(containsMount("/storage/emulated/1234/Android", "1234"));
+ EXPECT_TRUE(containsMount("/storage/emulated/1234/Android/data", "1234"));
+ EXPECT_TRUE(containsMount("/storage/emulated/1234/Android/obb", "1234"));
+}
+
+TEST(FuseUtilsTest, testContainsMount) {
+ EXPECT_FALSE(containsMount("/random/path", "1234"));
+ EXPECT_FALSE(containsMount("/storage/abc-123", "1234"));
+}
+
+TEST(FuseUtilsTest, testContainsMount_isCaseSensitive) {
+ EXPECT_FALSE(containsMount("/storage/emulated/1234/android", "1234"));
+ EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/Data", "1234"));
+ EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/OBB", "1234"));
+}
+
+TEST(FuseUtilsTest, testContainsMount_isFalseForPathWithAdditionalSlash) {
+ EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/", "1234"));
+ EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/data/", "1234"));
+ EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/obb/", "1234"));
+
+ EXPECT_FALSE(containsMount("//storage/emulated/1234/Android", "1234"));
+ EXPECT_FALSE(containsMount("/storage/emulated/1234//Android/data", "1234"));
+}
+
+TEST(FuseUtilsTest, testContainsMount_isFalseForPathWithWrongUserid) {
+ EXPECT_FALSE(containsMount("/storage/emulated/11234/Android", "1234"));
+ EXPECT_FALSE(containsMount("/storage/emulated/0/Android/data", "1234"));
+ EXPECT_FALSE(containsMount("/storage/emulated/12345/Android/obb", "1234"));
+}