xref: /xnu-10002.1.13/tests/nvram_tests/nvram_sys_hid_nonentitled.c (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a)
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 = SystemNVRAMGuidString ":" "testSysReadHidden";
18 
19 	optionsRef = CreateOptionsRef();
20 
21 	TestVarOp(OP_SET, varToTest, DefaultSetVal, KERN_SUCCESS, optionsRef);
22 	TestVarOp(OP_GET, varToTest, NULL, KERN_FAILURE, optionsRef);
23 	TestVarOp(OP_DEL, varToTest, NULL, KERN_SUCCESS, optionsRef);
24 
25 	ReleaseOptionsRef(optionsRef);
26 #else
27 	T_PASS("Test not supported");
28 #endif /* ((TARGET_OS_OSX) && !(__x86_64__)) */
29 }
30