groupadd.test 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
  3. # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
  4. [ -f testing.sh ] && . testing.sh
  5. if [ "$(id -u)" -ne 0 ]
  6. then
  7. echo "$SHOWSKIP: groupadd (not root)"
  8. return 2>/dev/null
  9. exit
  10. fi
  11. # 70 characters long string; hereafter, we will use it as per our need.
  12. _s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789"
  13. echo "# usage: addgroup [-g GID] [USER] GROUP
  14. # Add a group or add a user to a group."
  15. # Redirecting all output to /dev/null for grep and delgroup
  16. arg="&>/dev/null"
  17. #testing "name" "command" "result" "infile" "stdin"
  18. testing "group_name (text)" "groupadd toyTestGroup &&
  19. grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
  20. echo 'yes'" "yes\n" "" ""
  21. testing "group_name (alphanumeric)" "groupadd toy1Test2Group3 &&
  22. grep '^toy1Test2Group3:' /etc/group $arg && groupdel toy1Test2Group3 $arg &&
  23. echo 'yes'" "yes\n" "" ""
  24. testing "group_name (numeric)" "groupadd 987654321 &&
  25. grep '^987654321:' /etc/group $arg && groupdel 987654321 $arg &&
  26. echo 'yes'" "yes\n" "" ""
  27. testing "group_name (with ./-)" "groupadd toy.1Test-2Group.3 &&
  28. grep '^toy.1Test-2Group.3:' /etc/group $arg &&
  29. groupdel toy.1Test-2Group.3 $arg && echo 'yes'" "yes\n" "" ""
  30. _s210=`echo $_s70$_s70$_s70`
  31. testing "group_name (long string)" "groupadd $_s210 &&
  32. grep '^$_s210:' /etc/group $arg && groupdel $_s210 $arg && echo 'yes'" \
  33. "yes\n" "" ""
  34. testing "group_name with group_id" "groupadd -g 49999 toyTestGroup &&
  35. grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
  36. echo 'yes'" "yes\n" "" ""
  37. testing "group_name with group_id (system_group)" \
  38. "groupadd -g 49999 -S toyTestGroup && grep '^toyTestGroup:' /etc/group $arg &&
  39. groupdel toyTestGroup $arg && echo 'yes'" "yes\n" "" ""
  40. testing "group_name (system_group)" "groupadd -S toyTestGroup &&
  41. grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
  42. echo 'yes'" "yes\n" "" ""
  43. testing "group_name (add/del user)" "groupadd toyTestGroup &&
  44. grep '^toyTestGroup:' /etc/group $arg && groupadd $USER toyTestGroup &&
  45. grep '^toyTestGroup:.*:.*:.*$USER.*' /etc/group $arg &&
  46. groupdel $USER toyTestGroup $arg || groupdel toyTestGroup &&
  47. grep '^toyTestGroup:' /etc/group $arg || echo 'yes'" "yes\n" "" ""
  48. echo "Testing to add single group multiple times after removing it..."
  49. for each in {01..20}
  50. do
  51. testing "group_name ($each)" "groupadd toyTestGroup &&
  52. grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
  53. echo 'yes'" "yes\n" "" ""
  54. done