Advertisement
nvezz

test-auth.js

May 26th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. var async = require('async');
  2. var auth = require('../auth');
  3. var test = exports;
  4.  
  5. test.authenticate_shadow = function(test) {
  6. // this test assumes:
  7. // user "weak" with password "password"
  8. async.series([
  9. function(callback) {
  10. auth.authenticate_shadow('WEBUI_LOGIN_USER', 'PASSWORD', function(authed_user) {
  11. test.equal(authed_user, 'WEBUI_LOGIN_USER');
  12. callback(!authed_user);
  13. })
  14. },
  15. function(callback) {
  16. auth.authenticate_shadow('WEBUI_LOGIN_USER', 'notthepassword', function(authed_user) {
  17. test.equal(authed_user, false);
  18. callback(authed_user);
  19. })
  20. },
  21. function(callback) {
  22. auth.authenticate_shadow('fake', 'notthepassword', function(authed_user) {
  23. test.equal(authed_user, false);
  24. callback(authed_user);
  25. })
  26. },
  27. function(callback) {
  28. auth.authenticate_shadow('root', 'notthepassword', function(authed_user) {
  29. test.equal(authed_user, false);
  30. callback(authed_user);
  31. })
  32. },
  33. function(callback) {
  34. auth.authenticate_shadow('root', '', function(authed_user) {
  35. test.equal(authed_user, false);
  36. callback(authed_user);
  37. })
  38. },
  39. function(callback) {
  40. auth.authenticate_shadow('root', '!', function(authed_user) {
  41. test.equal(authed_user, false);
  42. callback(authed_user);
  43. })
  44. }
  45. ], function(err, results) {
  46. test.done();
  47. })
  48. }
  49.  
  50. test.test_membership = function(test) {
  51. // this test assumes:
  52. // user 'root' is part of group 'root'
  53. // user 'will' is part of group 'sudo'
  54.  
  55. async.series([
  56. function(callback) {
  57. auth.test_membership('root', 'root', function(is_member) {
  58. test.equal(is_member, true);
  59. callback();
  60. })
  61. },
  62. function(callback) {
  63. auth.test_membership('will', 'root', function(is_member) {
  64. test.equal(is_member, false);
  65. callback();
  66. })
  67. },
  68. function(callback) {
  69. auth.test_membership('will', 'sudo', function(is_member) {
  70. test.equal(is_member, true);
  71. callback();
  72. })
  73. },
  74. function(callback) {
  75. auth.test_membership('will', 'will', function(is_member) {
  76. test.equal(is_member, true);
  77. callback();
  78. })
  79. },
  80. function(callback) {
  81. auth.test_membership('jill', 'will', function(is_member) {
  82. test.equal(is_member, false);
  83. callback();
  84. })
  85. },
  86. function(callback) {
  87. auth.test_membership('jill', 'jill', function(is_member) {
  88. test.equal(is_member, false);
  89. callback();
  90. })
  91. }
  92. ], function(err, results) {
  93. test.done();
  94. })
  95. }
  96.  
  97. test.verify_ids = function(test) {
  98. // this test assumes:
  99. // UID and GID 1000 exist
  100.  
  101. async.series([
  102. async.apply(auth.verify_ids, 1000, 1000),
  103. function(callback) {
  104. auth.verify_ids(9876, 1000, function(err) {
  105. test.equal(err, 'UID 9876 does not exist on this system');
  106. callback();
  107. })
  108. },
  109. function(callback) {
  110. auth.verify_ids(1000, 9876, function(err) {
  111. test.equal(err, 'GID 9876 does not exist on this system');
  112. callback();
  113. })
  114. },
  115. function(callback) {
  116. auth.verify_ids(9876, 9876, function(err) {
  117. test.equal(err, 'UID 9876 does not exist on this system');
  118. callback();
  119. })
  120. }
  121. ], function(err, results) {
  122. test.ifError(err);
  123. test.done();
  124. })
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement