| @@ 162-181 (lines=20) @@ | ||
| 159 | ); |
|
| 160 | } |
|
| 161 | ||
| 162 | public function testVerifyOtp() |
|
| 163 | { |
|
| 164 | $otp = new Otp(); |
|
| 165 | $totpSecret = 'CN2XAL23SIFTDFXZ'; |
|
| 166 | $totpKey = $otp->totp(Encoding::base32DecodeUpper($totpSecret)); |
|
| 167 | ||
| 168 | $this->assertTrue( |
|
| 169 | $this->makeRequest( |
|
| 170 | ['vpn-server-node', 'aabbcc'], |
|
| 171 | 'POST', |
|
| 172 | 'verify_two_factor', |
|
| 173 | [], |
|
| 174 | [ |
|
| 175 | 'common_name' => '12345678901234567890123456789012', |
|
| 176 | 'two_factor_type' => 'totp', |
|
| 177 | 'two_factor_value' => $totpKey, |
|
| 178 | ] |
|
| 179 | ) |
|
| 180 | ); |
|
| 181 | } |
|
| 182 | ||
| 183 | private function makeRequest(array $basicAuth, $requestMethod, $pathInfo, array $getData = [], array $postData = []) |
|
| 184 | { |
|
| @@ 122-141 (lines=20) @@ | ||
| 119 | ); |
|
| 120 | } |
|
| 121 | ||
| 122 | public function testSetTotpSecret() |
|
| 123 | { |
|
| 124 | $otp = new Otp(); |
|
| 125 | $totpSecret = 'MM7TTLHPA7WZOJFB'; |
|
| 126 | $totpKey = $otp->totp(Encoding::base32DecodeUpper($totpSecret)); |
|
| 127 | ||
| 128 | $this->assertTrue( |
|
| 129 | $this->makeRequest( |
|
| 130 | ['vpn-user-portal', 'aabbcc'], |
|
| 131 | 'POST', |
|
| 132 | 'set_totp_secret', |
|
| 133 | [], |
|
| 134 | [ |
|
| 135 | 'user_id' => 'foo', |
|
| 136 | 'totp_secret' => $totpSecret, |
|
| 137 | 'totp_key' => $totpKey, |
|
| 138 | ] |
|
| 139 | ) |
|
| 140 | ); |
|
| 141 | } |
|
| 142 | ||
| 143 | public function testVerifyOtpKey() |
|
| 144 | { |
|
| @@ 143-161 (lines=19) @@ | ||
| 140 | ); |
|
| 141 | } |
|
| 142 | ||
| 143 | public function testVerifyOtpKey() |
|
| 144 | { |
|
| 145 | $otp = new Otp(); |
|
| 146 | $totpSecret = 'CN2XAL23SIFTDFXZ'; |
|
| 147 | $totpKey = $otp->totp(Encoding::base32DecodeUpper($totpSecret)); |
|
| 148 | ||
| 149 | $this->assertTrue( |
|
| 150 | $this->makeRequest( |
|
| 151 | ['vpn-user-portal', 'aabbcc'], |
|
| 152 | 'POST', |
|
| 153 | 'verify_totp_key', |
|
| 154 | [], |
|
| 155 | [ |
|
| 156 | 'user_id' => 'bar', |
|
| 157 | 'totp_key' => $totpKey, |
|
| 158 | ] |
|
| 159 | ) |
|
| 160 | ); |
|
| 161 | } |
|
| 162 | ||
| 163 | public function testVerifyOtpKeyWrong() |
|
| 164 | { |
|