xref: /xnu-8796.121.2/tests/nvram_tests/nvram_sys_hid_nonentitled.c (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1 #include <darwintest.h>
2 #include "nvram_helper.h"
3 
4 T_GLOBAL_META(T_META_NAMESPACE("xnu.nvram"),
5     T_META_RADAR_COMPONENT_NAME("xnu"),
6     T_META_RADAR_COMPONENT_VERSION("nvram"));
7 
8 static io_registry_entry_t optionsRef = IO_OBJECT_NULL;
9 
10 // xcrun -sdk macosx.internal make -C tests nvram_sys_hid_nonentitled && sudo ./tests/build/sym/nvram_sys_hid_nonentitled
11 
12 // Test that reading of variables with SystemReadHidden bit set without entitlement should fail
13 // NOTE: Test wasn't added to nvram_nonentitled.c as it requires system entitlement to set the variable
14 T_DECL(TestSysReadHid, "Test variable with SystemReadHidden bit set")
15 {
16 #if ((TARGET_OS_OSX) && !(__x86_64__))
17 	const char * varToTest = "40A0DDD2-77F8-4392-B4A3-1E7304206516:testSysReadHidden";
18 
19 	optionsRef = GetOptions();
20 
21 	T_ASSERT_EQ(SetVariable(varToTest, "1234", optionsRef), KERN_SUCCESS, "Set variable %s successfully\n", varToTest);
22 	T_ASSERT_NE(GetVariable(varToTest, optionsRef), KERN_SUCCESS, "Read variable %s failed as expected\n", varToTest);
23 
24 	ReleaseOptions(optionsRef);
25 #else
26 	T_PASS("Test not supported");
27 #endif /* ((TARGET_OS_OSX) && !(__x86_64__)) */
28 }
29