crash: Add logged-out GetCrashDirectoryInfo test.
Verify the permissions given for a user crash directory when no one is
logged in.
BUG=chromium:1111146
TEST=cros_workon_make --test --board=eve crash-reporter
Change-Id: Ibaed245b71cc1a49f9df57011af325329f2bef21
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2333346
Tested-by: Miriam Zimmerman <mutexlox@chromium.org>
Commit-Queue: Miriam Zimmerman <mutexlox@chromium.org>
Reviewed-by: Ian Barkley-Yeung <iby@chromium.org>
diff --git a/crash-reporter/crash_collector.h b/crash-reporter/crash_collector.h
index f4c7773..27e8f4a 100644
--- a/crash-reporter/crash_collector.h
+++ b/crash-reporter/crash_collector.h
@@ -185,6 +185,7 @@
CreateDirectoryWithSettings_FixSubdirPermissions);
FRIEND_TEST(CrashCollectorTest, FormatDumpBasename);
FRIEND_TEST(CrashCollectorTest, GetCrashDirectoryInfo);
+ FRIEND_TEST(CrashCollectorTest, GetCrashDirectoryInfoLoggedOut);
FRIEND_TEST(CrashCollectorTest, GetCrashPath);
FRIEND_TEST(CrashCollectorTest, GetLogContents);
FRIEND_TEST(CrashCollectorTest, GetMultipleLogContents);
diff --git a/crash-reporter/crash_collector_test.cc b/crash-reporter/crash_collector_test.cc
index fb507d5..6053ef0 100644
--- a/crash-reporter/crash_collector_test.cc
+++ b/crash-reporter/crash_collector_test.cc
@@ -703,6 +703,39 @@
#endif // !USE_KVM_GUEST
}
+TEST_F(CrashCollectorTest, GetCrashDirectoryInfoLoggedOut) {
+ FilePath path;
+ const int kChronosUid = 1000;
+ const mode_t kExpectedUserMode = 02770;
+
+ mode_t directory_mode;
+ uid_t directory_owner;
+ gid_t directory_group;
+
+ auto* mock = new org::chromium::SessionManagerInterfaceProxyMock;
+ test_util::SetActiveSessions(mock, {});
+ collector_.session_manager_proxy_.reset(mock);
+
+ path = collector_
+ .GetCrashDirectoryInfo(
+ kChronosUid, kChronosUid, /*use_non_chronos_cryptohome=*/false,
+ &directory_mode, &directory_owner, &directory_group)
+ .value();
+ EXPECT_EQ(kExpectedUserMode, directory_mode);
+#if USE_KVM_GUEST
+ // Inside the VM, everything goes to /var/spool/crash.
+ const int kCrashAccessGid = 419;
+ EXPECT_EQ("/var/spool/crash", path.value());
+ EXPECT_EQ(0, directory_owner);
+ EXPECT_EQ(kCrashAccessGid, directory_group);
+#else
+ const int kCrashUserAccessGid = 420;
+ EXPECT_EQ("/home/chronos/crash", path.value());
+ EXPECT_EQ(kChronosUid, directory_owner);
+ EXPECT_EQ(kCrashUserAccessGid, directory_group);
+#endif // USE_KVM_GUEST
+}
+
TEST_F(CrashCollectorTest, FormatDumpBasename) {
struct tm tm = {};
tm.tm_sec = 15;