PageRenderTime 63ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/sys-auth/google-authenticator/files/1.08-remove-failing-tests.patch

https://gitlab.com/redcore/portage
Patch | 301 lines | 297 code | 4 blank | 0 comment | 0 complexity | 32c2bacb83a2dc051651a2427ea6c40a MD5 | raw file
  1. From 9e26b1885250cb0b7a710d9ae65542e3fcae684f Mon Sep 17 00:00:00 2001
  2. From: Ronny Gutbrod <gentoo@tastytea.de>
  3. Date: Sat, 11 Apr 2020 21:08:37 +0200
  4. Subject: [PATCH] Remove calls to pam_sm_authenticate().
  5. It tries to change the user id, which is prohibited by the sandbox. See #624588.
  6. ---
  7. tests/pam_google_authenticator_unittest.c | 271 ----------------------
  8. 1 file changed, 271 deletions(-)
  9. diff --git a/tests/pam_google_authenticator_unittest.c b/tests/pam_google_authenticator_unittest.c
  10. index edade47..0661b8b 100644
  11. --- a/tests/pam_google_authenticator_unittest.c
  12. +++ b/tests/pam_google_authenticator_unittest.c
  13. @@ -338,72 +338,6 @@ int main(int argc, char *argv[]) {
  14. // Make sure num_prompts_shown is still 0.
  15. verify_prompts_shown(0);
  16. - // Set the timestamp that this test vector needs
  17. - set_time(10000*30);
  18. -
  19. - response = "123456";
  20. -
  21. - // Check if we can log in when using an invalid verification code
  22. - puts("Testing failed login attempt");
  23. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  24. - verify_prompts_shown(expected_bad_prompts_shown);
  25. -
  26. - // Check required number of digits
  27. - if (conv_mode == TWO_PROMPTS) {
  28. - puts("Testing required number of digits");
  29. - response = "50548";
  30. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  31. - verify_prompts_shown(expected_bad_prompts_shown);
  32. - response = "0050548";
  33. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  34. - verify_prompts_shown(expected_bad_prompts_shown);
  35. - response = "00050548";
  36. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  37. - verify_prompts_shown(expected_bad_prompts_shown);
  38. - }
  39. -
  40. - // Test a blank response
  41. - puts("Testing a blank response");
  42. - response = "";
  43. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  44. - verify_prompts_shown(expected_bad_prompts_shown);
  45. -
  46. - // Set the response that we should send back to the authentication module
  47. - response = "050548";
  48. -
  49. - // Test handling of missing state files
  50. - puts("Test handling of missing state files");
  51. - const char *old_secret = targv[0];
  52. - targv[0] = "secret=/NOSUCHFILE";
  53. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  54. - verify_prompts_shown(password_is_provided_from_external ? 0 : expected_bad_prompts_shown);
  55. - targv[targc++] = "nullok";
  56. - targv[targc] = NULL;
  57. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_IGNORE);
  58. - verify_prompts_shown(0);
  59. - targv[--targc] = NULL;
  60. - targv[0] = old_secret;
  61. -
  62. - // Check if we can log in when using a valid verification code
  63. - puts("Testing successful login");
  64. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_SUCCESS);
  65. - verify_prompts_shown(expected_good_prompts_shown);
  66. -
  67. - // Test the STEP_SIZE option
  68. - puts("Testing STEP_SIZE option");
  69. - assert(!chmod(fn, 0600));
  70. - assert((fd = open(fn, O_APPEND | O_WRONLY)) >= 0);
  71. - assert(write(fd, "\n\" STEP_SIZE 60\n", 16) == 16);
  72. - close(fd);
  73. - for (int *tm = (int []){ 9998, 9999, 10001, 10002, 10000, -1 },
  74. - *res = (int []){ PAM_AUTH_ERR, PAM_SUCCESS, PAM_SUCCESS,
  75. - PAM_AUTH_ERR, PAM_SUCCESS };
  76. - *tm >= 0;) {
  77. - set_time(*tm++ * 60);
  78. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == *res++);
  79. - verify_prompts_shown(expected_good_prompts_shown);
  80. - }
  81. -
  82. // Reset secret file after step size testing.
  83. assert(!chmod(fn, 0600));
  84. assert((fd = open(fn, O_TRUNC | O_WRONLY)) >= 0);
  85. @@ -411,211 +345,6 @@ int main(int argc, char *argv[]) {
  86. assert(write(fd, "\n\" TOTP_AUTH", 12) == 12);
  87. close(fd);
  88. - // Test the WINDOW_SIZE option
  89. - puts("Testing WINDOW_SIZE option");
  90. - for (int *tm = (int []){ 9998, 9999, 10001, 10002, 10000, -1 },
  91. - *res = (int []){ PAM_AUTH_ERR, PAM_SUCCESS, PAM_SUCCESS,
  92. - PAM_AUTH_ERR, PAM_SUCCESS };
  93. - *tm >= 0;) {
  94. - set_time(*tm++ * 30);
  95. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == *res++);
  96. - verify_prompts_shown(expected_good_prompts_shown);
  97. - }
  98. - assert(!chmod(fn, 0600));
  99. - assert((fd = open(fn, O_APPEND | O_WRONLY)) >= 0);
  100. - assert(write(fd, "\n\" WINDOW_SIZE 6\n", 17) == 17);
  101. - close(fd);
  102. - for (int *tm = (int []){ 9996, 9997, 10002, 10003, 10000, -1 },
  103. - *res = (int []){ PAM_AUTH_ERR, PAM_SUCCESS, PAM_SUCCESS,
  104. - PAM_AUTH_ERR, PAM_SUCCESS };
  105. - *tm >= 0;) {
  106. - set_time(*tm++ * 30);
  107. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == *res++);
  108. - verify_prompts_shown(expected_good_prompts_shown);
  109. - }
  110. -
  111. - // Test the DISALLOW_REUSE option
  112. - puts("Testing DISALLOW_REUSE option");
  113. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_SUCCESS);
  114. - verify_prompts_shown(expected_good_prompts_shown);
  115. - assert(!chmod(fn, 0600));
  116. - assert((fd = open(fn, O_APPEND | O_WRONLY)) >= 0);
  117. - assert(write(fd, "\" DISALLOW_REUSE\n", 17) == 17);
  118. - close(fd);
  119. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_SUCCESS);
  120. - verify_prompts_shown(expected_good_prompts_shown);
  121. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  122. - verify_prompts_shown(expected_good_prompts_shown);
  123. -
  124. - // Test that DISALLOW_REUSE expires old entries from the re-use list
  125. - char *old_response = response;
  126. - for (int i = 10001; i < 10008; ++i) {
  127. - set_time(i * 30);
  128. - char buf[7];
  129. - response = buf;
  130. - sprintf(response, "%06d", compute_code(binary_secret,
  131. - binary_secret_len, i));
  132. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_SUCCESS);
  133. - verify_prompts_shown(expected_good_prompts_shown);
  134. - }
  135. - set_time(10000 * 30);
  136. - response = old_response;
  137. - assert((fd = open(fn, O_RDONLY)) >= 0);
  138. - char state_file_buf[4096] = { 0 };
  139. - assert(read(fd, state_file_buf, sizeof(state_file_buf)-1) > 0);
  140. - close(fd);
  141. - const char *disallow = strstr(state_file_buf, "\" DISALLOW_REUSE ");
  142. - assert(disallow);
  143. - assert(!memcmp(disallow + 17,
  144. - "10002 10003 10004 10005 10006 10007\n", 36));
  145. -
  146. - // Test the RATE_LIMIT option
  147. - puts("Testing RATE_LIMIT option");
  148. - assert(!chmod(fn, 0600));
  149. - assert((fd = open(fn, O_APPEND | O_WRONLY)) >= 0);
  150. - assert(write(fd, "\" RATE_LIMIT 4 120\n", 19) == 19);
  151. - close(fd);
  152. - for (int *tm = (int []){ 20000, 20001, 20002, 20003, 20004, 20006, -1 },
  153. - *res = (int []){ PAM_SUCCESS, PAM_SUCCESS, PAM_SUCCESS,
  154. - PAM_SUCCESS, PAM_AUTH_ERR, PAM_SUCCESS, -1 };
  155. - *tm >= 0;) {
  156. - set_time(*tm * 30);
  157. - char buf[7];
  158. - response = buf;
  159. - sprintf(response, "%06d",
  160. - compute_code(binary_secret, binary_secret_len, *tm++));
  161. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == *res);
  162. - verify_prompts_shown(
  163. - *res != PAM_SUCCESS ? 0 : expected_good_prompts_shown);
  164. - ++res;
  165. - }
  166. - set_time(10000 * 30);
  167. - response = old_response;
  168. - assert(!chmod(fn, 0600));
  169. - assert((fd = open(fn, O_RDWR)) >= 0);
  170. - memset(state_file_buf, 0, sizeof(state_file_buf));
  171. - assert(read(fd, state_file_buf, sizeof(state_file_buf)-1) > 0);
  172. - const char *rate_limit = strstr(state_file_buf, "\" RATE_LIMIT ");
  173. - assert(rate_limit);
  174. - assert(!memcmp(rate_limit + 13,
  175. - "4 120 600060 600090 600120 600180\n", 35));
  176. -
  177. - // Test trailing space in RATE_LIMIT. This is considered a file format
  178. - // error.
  179. - char *eol = strchr(rate_limit, '\n');
  180. - *eol = ' ';
  181. - assert(!lseek(fd, 0, SEEK_SET));
  182. - assert(write(fd, state_file_buf, strlen(state_file_buf)) ==
  183. - strlen(state_file_buf));
  184. - close(fd);
  185. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  186. - verify_prompts_shown(0);
  187. - assert(!strncmp(get_error_msg(),
  188. - "Invalid list of timestamps in RATE_LIMIT", 40));
  189. - *eol = '\n';
  190. - assert(!chmod(fn, 0600));
  191. - assert((fd = open(fn, O_WRONLY)) >= 0);
  192. - assert(write(fd, state_file_buf, strlen(state_file_buf)) ==
  193. - strlen(state_file_buf));
  194. - close(fd);
  195. -
  196. - // Test TIME_SKEW option
  197. - puts("Testing TIME_SKEW");
  198. - for (int i = 0; i < 4; ++i) {
  199. - set_time((12000 + i)*30);
  200. - char buf[7];
  201. - response = buf;
  202. - sprintf(response, "%06d",
  203. - compute_code(binary_secret, binary_secret_len, 11000 + i));
  204. - assert(pam_sm_authenticate(NULL, 0, targc, targv) ==
  205. - (i >= 2 ? PAM_SUCCESS : PAM_AUTH_ERR));
  206. - verify_prompts_shown(expected_good_prompts_shown);
  207. - }
  208. -
  209. - puts("Testing TIME_SKEW - noskewadj");
  210. - set_time(12020 * 30);
  211. - char buf[7];
  212. - response = buf;
  213. - sprintf(response, "%06d", compute_code(binary_secret,
  214. - binary_secret_len, 11010));
  215. - targv[targc] = "noskewadj";
  216. - assert(pam_sm_authenticate(NULL, 0, targc+1, targv) == PAM_AUTH_ERR);
  217. - targv[targc] = NULL;
  218. - verify_prompts_shown(expected_bad_prompts_shown);
  219. - set_time(10000*30);
  220. -
  221. - // Test scratch codes
  222. - puts("Testing scratch codes");
  223. - response = "12345678";
  224. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  225. - verify_prompts_shown(expected_bad_prompts_shown);
  226. - assert(!chmod(fn, 0600));
  227. - assert((fd = open(fn, O_APPEND | O_WRONLY)) >= 0);
  228. - assert(write(fd, "12345678\n", 9) == 9);
  229. - close(fd);
  230. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_SUCCESS);
  231. - verify_prompts_shown(expected_good_prompts_shown);
  232. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  233. - verify_prompts_shown(expected_bad_prompts_shown);
  234. -
  235. - // Set up secret file for counter-based codes.
  236. - assert(!chmod(fn, 0600));
  237. - assert((fd = open(fn, O_TRUNC | O_WRONLY)) >= 0);
  238. - assert(write(fd, secret, sizeof(secret)-1) == sizeof(secret)-1);
  239. - assert(write(fd, "\n\" HOTP_COUNTER 1\n", 18) == 18);
  240. - close(fd);
  241. -
  242. - response = "293240";
  243. -
  244. - // Check if we can log in when using a valid verification code
  245. - puts("Testing successful counter-based login");
  246. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_SUCCESS);
  247. - verify_prompts_shown(expected_good_prompts_shown);
  248. -
  249. - // Verify that the hotp counter incremented
  250. - assert((fd = open(fn, O_RDONLY)) >= 0);
  251. - memset(state_file_buf, 0, sizeof(state_file_buf));
  252. - assert(read(fd, state_file_buf, sizeof(state_file_buf)-1) > 0);
  253. - close(fd);
  254. - const char *hotp_counter = strstr(state_file_buf, "\" HOTP_COUNTER ");
  255. - assert(hotp_counter);
  256. - assert(!memcmp(hotp_counter + 15, "2\n", 2));
  257. -
  258. - // Check if we can log in when using an invalid verification code
  259. - // (including the same code a second time)
  260. - puts("Testing failed counter-based login attempt");
  261. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_AUTH_ERR);
  262. - verify_prompts_shown(expected_bad_prompts_shown);
  263. -
  264. - // Verify that the hotp counter incremented
  265. - assert((fd = open(fn, O_RDONLY)) >= 0);
  266. - memset(state_file_buf, 0, sizeof(state_file_buf));
  267. - assert(read(fd, state_file_buf, sizeof(state_file_buf)-1) > 0);
  268. - close(fd);
  269. - hotp_counter = strstr(state_file_buf, "\" HOTP_COUNTER ");
  270. - assert(hotp_counter);
  271. - assert(!memcmp(hotp_counter + 15, "3\n", 2));
  272. -
  273. - response = "932068";
  274. -
  275. - // Check if we can log in using a future valid verification code (using
  276. - // default window_size of 3)
  277. - puts("Testing successful future counter-based login");
  278. - assert(pam_sm_authenticate(NULL, 0, targc, targv) == PAM_SUCCESS);
  279. - verify_prompts_shown(expected_good_prompts_shown);
  280. -
  281. - // Verify that the hotp counter incremented
  282. - assert((fd = open(fn, O_RDONLY)) >= 0);
  283. - memset(state_file_buf, 0, sizeof(state_file_buf));
  284. - assert(read(fd, state_file_buf, sizeof(state_file_buf)-1) > 0);
  285. - close(fd);
  286. - hotp_counter = strstr(state_file_buf, "\" HOTP_COUNTER ");
  287. - assert(hotp_counter);
  288. - assert(!memcmp(hotp_counter + 15, "6\n", 2));
  289. -
  290. - // Remove the temporarily created secret file
  291. - unlink(fn);
  292. -
  293. // Release memory for the test arguments
  294. for (int i = 0; i < targc; ++i) {
  295. free((void *)targv[i]);
  296. --
  297. 2.24.1