| @@ 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 | { |
|
| @@ 133-152 (lines=20) @@ | ||
| 130 | ); |
|
| 131 | } |
|
| 132 | ||
| 133 | public function testSetTotpSecret() |
|
| 134 | { |
|
| 135 | $otp = new Otp(); |
|
| 136 | $totpSecret = 'MM7TTLHPA7WZOJFB'; |
|
| 137 | $totpKey = $otp->totp(Encoding::base32DecodeUpper($totpSecret)); |
|
| 138 | ||
| 139 | $this->assertTrue( |
|
| 140 | $this->makeRequest( |
|
| 141 | ['vpn-user-portal', 'aabbcc'], |
|
| 142 | 'POST', |
|
| 143 | 'set_totp_secret', |
|
| 144 | [], |
|
| 145 | [ |
|
| 146 | 'user_id' => 'foo', |
|
| 147 | 'totp_secret' => $totpSecret, |
|
| 148 | 'totp_key' => $totpKey, |
|
| 149 | ] |
|
| 150 | ) |
|
| 151 | ); |
|
| 152 | } |
|
| 153 | ||
| 154 | public function testVerifyOtpKey() |
|
| 155 | { |
|
| @@ 154-172 (lines=19) @@ | ||
| 151 | ); |
|
| 152 | } |
|
| 153 | ||
| 154 | public function testVerifyOtpKey() |
|
| 155 | { |
|
| 156 | $otp = new Otp(); |
|
| 157 | $totpSecret = 'CN2XAL23SIFTDFXZ'; |
|
| 158 | $totpKey = $otp->totp(Encoding::base32DecodeUpper($totpSecret)); |
|
| 159 | ||
| 160 | $this->assertTrue( |
|
| 161 | $this->makeRequest( |
|
| 162 | ['vpn-user-portal', 'aabbcc'], |
|
| 163 | 'POST', |
|
| 164 | 'verify_totp_key', |
|
| 165 | [], |
|
| 166 | [ |
|
| 167 | 'user_id' => 'bar', |
|
| 168 | 'totp_key' => $totpKey, |
|
| 169 | ] |
|
| 170 | ) |
|
| 171 | ); |
|
| 172 | } |
|
| 173 | ||
| 174 | public function testVerifyOtpKeyWrong() |
|
| 175 | { |
|