| 1 | #! /usr/bin/env php |
|---|
| 2 | <?php |
|---|
| 3 | |
|---|
| 4 | require_once(dirname($argv[0]) . "/utilities.php"); |
|---|
| 5 | require_once(IA_ROOT_DIR . "www/utilities.php"); |
|---|
| 6 | |
|---|
| 7 | test_cleanup(); |
|---|
| 8 | test_prepare(); |
|---|
| 9 | |
|---|
| 10 | log_print("Anon looks at new account page"); |
|---|
| 11 | $res = curl_test(array( |
|---|
| 12 | 'url' => url_register(), |
|---|
| 13 | )); |
|---|
| 14 | log_assert_equal($res['url'], url_absolute(url_register())); |
|---|
| 15 | |
|---|
| 16 | log_print("Admin looks at new account page, allowed"); |
|---|
| 17 | $res = curl_test(array( |
|---|
| 18 | 'url' => url_register(), |
|---|
| 19 | 'user' => 'test_admin', |
|---|
| 20 | )); |
|---|
| 21 | log_assert_equal($res['url'], url_absolute(url_register())); |
|---|
| 22 | |
|---|
| 23 | $test_username = "test_".mt_rand(); |
|---|
| 24 | $test_password = "pwd".mt_rand(); |
|---|
| 25 | log_print("Creating $test_username"); |
|---|
| 26 | $res = curl_test(array( |
|---|
| 27 | 'url' => url_register(), |
|---|
| 28 | 'post' => array( |
|---|
| 29 | 'username' => $test_username, |
|---|
| 30 | 'password' => $test_password, |
|---|
| 31 | 'password2' => $test_password, |
|---|
| 32 | 'full_name' => "xzx-FULL-NAME-xzx", |
|---|
| 33 | 'email' => "$test_username@gmail.com", |
|---|
| 34 | 'tnc' => 1, |
|---|
| 35 | ), |
|---|
| 36 | )); |
|---|
| 37 | log_assert_equal($res['url'], url_absolute(url_login())); |
|---|
| 38 | |
|---|
| 39 | log_print("Looking at the new user's page"); |
|---|
| 40 | $res = curl_test(array( |
|---|
| 41 | 'url' => url_user_profile($test_username), |
|---|
| 42 | 'user' => $test_username, |
|---|
| 43 | 'pwd' => $test_password, |
|---|
| 44 | )); |
|---|
| 45 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 46 | |
|---|
| 47 | log_print("Looking at the new user's page stats"); |
|---|
| 48 | $res = curl_test(array( |
|---|
| 49 | 'url' => url_user_stats($test_username), |
|---|
| 50 | 'user' => $test_username, |
|---|
| 51 | 'pwd' => $test_password, |
|---|
| 52 | )); |
|---|
| 53 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 54 | log_assert(strstr($res['content'], 'xzx-FULL-NAME-xzx')); |
|---|
| 55 | |
|---|
| 56 | log_print("Looking at the new user's rating page"); |
|---|
| 57 | $res = curl_test(array( |
|---|
| 58 | 'url' => url_user_rating($test_username), |
|---|
| 59 | )); |
|---|
| 60 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 61 | log_assert(strstr($res['content'], 'normal')); |
|---|
| 62 | |
|---|
| 63 | log_print("Looking at the new user's stats page"); |
|---|
| 64 | $res = curl_test(array( |
|---|
| 65 | 'url' => url_user_profile($test_username), |
|---|
| 66 | )); |
|---|
| 67 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 68 | log_assert(strstr($res['content'], 'xzx-FULL-NAME-xzx')); |
|---|
| 69 | |
|---|
| 70 | $test_newpassword = "newpwd".mt_rand(); |
|---|
| 71 | log_print("User changes his password but is wrong"); |
|---|
| 72 | $res = curl_test(array( |
|---|
| 73 | 'url' => url_account(), |
|---|
| 74 | 'user' => $test_username, |
|---|
| 75 | 'pwd' => $test_password, |
|---|
| 76 | 'post' => array ( |
|---|
| 77 | 'oldpassword' => $test_password, |
|---|
| 78 | 'password' => $test_newpassword, |
|---|
| 79 | 'password2' => $test_newpassword + 1, |
|---|
| 80 | ))); |
|---|
| 81 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 82 | log_assert(strstr($res['content'], 'xzx-FULL-NAME-xzx')); |
|---|
| 83 | |
|---|
| 84 | $test_newpassword = "newpwd".mt_rand(); |
|---|
| 85 | log_print("User changes his password correctly"); |
|---|
| 86 | $res = curl_test(array( |
|---|
| 87 | 'url' => url_account(), |
|---|
| 88 | 'user' => $test_username, |
|---|
| 89 | 'pwd' => $test_password, |
|---|
| 90 | 'post' => array ( |
|---|
| 91 | 'passwordold' => $test_password, |
|---|
| 92 | 'password' => $test_newpassword, |
|---|
| 93 | 'password2' => $test_newpassword, |
|---|
| 94 | ))); |
|---|
| 95 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 96 | log_assert(strstr($res['content'], 'xzx-FULL-NAME-xzx')); |
|---|
| 97 | log_assert(!strstr($res['content'], 'fieldError')); |
|---|
| 98 | |
|---|
| 99 | log_print("User changes his name"); |
|---|
| 100 | $res = curl_test(array( |
|---|
| 101 | 'url' => url_account(), |
|---|
| 102 | 'user' => $test_username, |
|---|
| 103 | 'pwd' => $test_newpassword, |
|---|
| 104 | 'post' => array ( |
|---|
| 105 | 'full_name' => 'xzx-NEW-FULL-NAME-xzx', |
|---|
| 106 | ))); |
|---|
| 107 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 108 | log_assert(strstr($res['content'], 'xzx-NEW-FULL-NAME-xzx')); |
|---|
| 109 | |
|---|
| 110 | log_print("Admin looks at user account page"); |
|---|
| 111 | $res = curl_test(array( |
|---|
| 112 | 'url' => url_account($test_username), |
|---|
| 113 | 'user' => 'test_admin' |
|---|
| 114 | )); |
|---|
| 115 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 116 | log_assert(strstr($res['content'], 'xzx-NEW-FULL-NAME-xzx')); |
|---|
| 117 | |
|---|
| 118 | log_print("Admin makes new user into a helper."); |
|---|
| 119 | $res = curl_test(array( |
|---|
| 120 | 'url' => url_account($test_username), |
|---|
| 121 | 'user' => 'test_admin', |
|---|
| 122 | 'post' => array( |
|---|
| 123 | 'security_level' => 'helper', |
|---|
| 124 | ))); |
|---|
| 125 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 126 | log_assert(strstr($res['content'], 'xzx-NEW-FULL-NAME-xzx')); |
|---|
| 127 | log_assert(!strstr($res['content'], 'fieldError')); |
|---|
| 128 | |
|---|
| 129 | log_print("User can now see new-task page. Awesome"); |
|---|
| 130 | $res = curl_test(array( |
|---|
| 131 | 'url' => url_task_create(), |
|---|
| 132 | 'user' => $test_username, |
|---|
| 133 | 'pwd' => $test_newpassword, |
|---|
| 134 | )); |
|---|
| 135 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 136 | |
|---|
| 137 | log_print("User tries to hack himself into an admin"); |
|---|
| 138 | $res = curl_test(array( |
|---|
| 139 | 'url' => url_account(), |
|---|
| 140 | 'user' => $test_username, |
|---|
| 141 | 'pwd' => $test_newpassword, |
|---|
| 142 | 'post' => array( |
|---|
| 143 | 'security_level' => 'admin', |
|---|
| 144 | ))); |
|---|
| 145 | log_assert_equal($res['redirect_count'], 1); |
|---|
| 146 | |
|---|
| 147 | log_print("User can't even see security level switched"); |
|---|
| 148 | $res = curl_test(array( |
|---|
| 149 | 'url' => url_account(), |
|---|
| 150 | 'user' => $test_username, |
|---|
| 151 | 'pwd' => $test_newpassword, |
|---|
| 152 | )); |
|---|
| 153 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 154 | log_assert(!stristr($res['content'], 'security_level')); |
|---|
| 155 | |
|---|
| 156 | log_print("Looking at the user page, still a helper"); |
|---|
| 157 | $res = curl_test(array( |
|---|
| 158 | 'url' => url_user_profile($test_username), |
|---|
| 159 | 'user' => $test_username, |
|---|
| 160 | 'pwd' => $test_password, |
|---|
| 161 | )); |
|---|
| 162 | log_assert_equal($res['redirect_count'], 0); |
|---|
| 163 | log_assert(stristr($res['content'], 'helper')); |
|---|
| 164 | |
|---|
| 165 | test_cleanup(); |
|---|