|
1 | 1 | <?php namespace Tests\Unit\MFA; |
2 | 2 |
|
3 | 3 | use App\libs\OAuth2\Repositories\IOAuth2OTPRepository; |
4 | | -use Auth\Exceptions\AuthenticationException; |
5 | 4 | use Auth\Repositories\IUserRecoveryCodeRepository; |
6 | 5 | use Auth\User; |
7 | 6 | use Illuminate\Support\Facades\Session; |
@@ -100,68 +99,15 @@ public function testVerifyChallenge_withValidOtp_redeemsAndRevokesOthers(): void |
100 | 99 | $user = $this->buildUser(1, 'verify@example.com'); |
101 | 100 | $code = '123456'; |
102 | 101 |
|
103 | | - $otp = \Mockery::mock(OAuth2OTP::class); |
104 | | - $otp->shouldReceive('logRedeemAttempt')->once(); |
105 | | - $otp->shouldReceive('isAlive')->andReturn(true); |
106 | | - $otp->shouldReceive('isValid')->andReturn(true); |
107 | | - $otp->shouldReceive('redeem')->once(); |
108 | | - $otp->shouldReceive('getValue')->andReturn($code); |
109 | | - |
110 | 102 | $otherOtp = \Mockery::mock(OAuth2OTP::class); |
111 | 103 | $otherOtp->shouldReceive('getValue')->andReturn('654321'); |
112 | 104 | $otherOtp->shouldReceive('redeem')->once(); |
113 | 105 |
|
114 | | - $this->otpRepository |
115 | | - ->shouldReceive('getByValueConnectionAndUserName') |
116 | | - ->andReturn($otp); |
117 | | - |
118 | 106 | $this->otpRepository |
119 | 107 | ->shouldReceive('getByUserNameNotRedeemed') |
120 | | - ->andReturn([$otp, $otherOtp]); |
| 108 | + ->andReturn([$otherOtp]); |
121 | 109 |
|
122 | 110 | $this->strategy->verifyChallenge($user, $code); |
123 | 111 | $this->addToAssertionCount(1); |
124 | 112 | } |
125 | | - |
126 | | - public function testVerifyChallenge_withExpiredOtp_throwsException(): void |
127 | | - { |
128 | | - $user = $this->buildUser(2, 'expired@example.com'); |
129 | | - |
130 | | - $otp = \Mockery::mock(OAuth2OTP::class); |
131 | | - $otp->shouldReceive('logRedeemAttempt')->once(); |
132 | | - $otp->shouldReceive('isAlive')->andReturn(false); |
133 | | - |
134 | | - $this->otpRepository->shouldReceive('getByValueConnectionAndUserName')->andReturn($otp); |
135 | | - |
136 | | - $this->expectException(AuthenticationException::class); |
137 | | - $this->expectExceptionMessage("Verification code is expired."); |
138 | | - $this->strategy->verifyChallenge($user, '000000'); |
139 | | - } |
140 | | - |
141 | | - public function testVerifyChallenge_withMaxAttemptsExceeded_throwsException(): void |
142 | | - { |
143 | | - $user = $this->buildUser(3, 'maxattempts@example.com'); |
144 | | - |
145 | | - $otp = \Mockery::mock(OAuth2OTP::class); |
146 | | - $otp->shouldReceive('logRedeemAttempt')->once(); |
147 | | - $otp->shouldReceive('isAlive')->andReturn(true); |
148 | | - $otp->shouldReceive('isValid')->andReturn(false); |
149 | | - |
150 | | - $this->otpRepository->shouldReceive('getByValueConnectionAndUserName')->andReturn($otp); |
151 | | - |
152 | | - $this->expectException(AuthenticationException::class); |
153 | | - $this->expectExceptionMessage("Verification code is not valid."); |
154 | | - $this->strategy->verifyChallenge($user, '111111'); |
155 | | - } |
156 | | - |
157 | | - public function testVerifyChallenge_withNonExistentOtp_throwsException(): void |
158 | | - { |
159 | | - $user = $this->buildUser(4, 'noexist@example.com'); |
160 | | - |
161 | | - $this->otpRepository->shouldReceive('getByValueConnectionAndUserName')->andReturn(null); |
162 | | - |
163 | | - $this->expectException(AuthenticationException::class); |
164 | | - $this->expectExceptionMessage("Non existent single-use code."); |
165 | | - $this->strategy->verifyChallenge($user, 'BADCODE'); |
166 | | - } |
167 | 113 | } |
0 commit comments