Test that vendor AID names begin with vendor_
Now that we're only processing vendor AID names that begin with
vendor_, add an explicit test to fail devices that use AID names
without this prefix.
Bug: 79528966
Test: Pass if no vendor defined AIDs are present
Test: Pass if vendor defined AIDs are present with vendor_ prefix
Test: Fail if vendor defined AIDs are present without vendor_ prefix
Change-Id: I77c559800b4904f58c49fbe339e4daad7d953089
diff --git a/tests/grp_pwd_test.cpp b/tests/grp_pwd_test.cpp
index fa8a662..615f374 100644
--- a/tests/grp_pwd_test.cpp
+++ b/tests/grp_pwd_test.cpp
@@ -29,6 +29,7 @@
#include <set>
#include <vector>
+#include <android-base/file.h>
#include <android-base/strings.h>
#include <private/android_filesystem_config.h>
@@ -36,6 +37,9 @@
#include "generated_android_ids.h"
using android::base::Join;
+using android::base::ReadFileToString;
+using android::base::Split;
+using android::base::StartsWith;
enum uid_type_t {
TYPE_SYSTEM,
@@ -528,3 +532,36 @@
print_no_getgrnam_test_info();
#endif
}
+
+#if defined(__BIONIC__)
+static void TestAidNamePrefix(const std::string& file_path) {
+ std::string file_contents;
+ if (!ReadFileToString(file_path, &file_contents)) {
+ // If we cannot read this file, then there are no vendor defind AID names, in which case this
+ // test passes by default.
+ return;
+ }
+ auto lines = Split(file_contents, "\n");
+ for (const auto& line : lines) {
+ if (line.empty()) continue;
+ auto name = Split(line, ":")[0];
+ EXPECT_TRUE(StartsWith(name, "vendor_"));
+ }
+}
+#endif
+
+TEST(pwd, vendor_prefix_users) {
+#if defined(__BIONIC__)
+ TestAidNamePrefix("/vendor/etc/passwd");
+#else
+ print_no_getpwnam_test_info();
+#endif
+}
+
+TEST(pwd, vendor_prefix_groups) {
+#if defined(__BIONIC__)
+ TestAidNamePrefix("/vendor/etc/group");
+#else
+ print_no_getgrnam_test_info();
+#endif
+}