I need to test if Mac root user is enabled or not.
I usually enable/disable it by using dsenableroot.
sudo dscl . -read /Users/root Password
If root is enabled it will output
Password: ********, otherwise it will be just
No such key: Password.
Edit: After Apple's security patch 2017 Nov 29, if root is disabled, it may output
sudo plutil -p /var/db/dslocal/nodes/Default/users/root.plist | grep -A 2 passwd
If the result is:
"passwd" => [ 0 => "********" ]
Then root is enabled. If it's:
"passwd" => [ 0 => "*" ]
then root is disabled.