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