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