|
87 | 87 | expect(Altcha.verify_solution(payload, hmac_key, true)).to be true |
88 | 88 | end |
89 | 89 |
|
| 90 | + it 'fails to verify an incorrect solution with salt splicing' do |
| 91 | + challenge_options_with_expires = Altcha::ChallengeOptions.new( |
| 92 | + algorithm: algorithm, |
| 93 | + expires: Time.now.to_i + 3600, |
| 94 | + hmac_key: hmac_key, |
| 95 | + salt: salt, |
| 96 | + number: 123 |
| 97 | + ) |
| 98 | + challenge = Altcha.create_challenge(challenge_options_with_expires) |
| 99 | + payload = { |
| 100 | + algorithm: algorithm, |
| 101 | + challenge: challenge.challenge, |
| 102 | + number: 23, |
| 103 | + salt: challenge.salt + '1', |
| 104 | + signature: challenge.signature |
| 105 | + } |
| 106 | + expect(Altcha.verify_solution(payload, hmac_key, true)).to be false |
| 107 | + end |
| 108 | + |
90 | 109 | it 'fails to verify an incorrect solution' do |
91 | 110 | payload = { algorithm: algorithm, challenge: 'wrong_challenge', number: number, salt: salt, signature: 'wrong_signature' } |
92 | 111 | expect(Altcha.verify_solution(payload, hmac_key, false)).to be false |
|
131 | 150 | describe '.solve_challenge' do |
132 | 151 | it 'solves a challenge correctly' do |
133 | 152 | challenge = Altcha.create_challenge(challenge_options) |
134 | | - solution = Altcha.solve_challenge(challenge.challenge, salt, algorithm, 10_000, 0) |
| 153 | + solution = Altcha.solve_challenge(challenge.challenge, challenge.salt, algorithm, 10_000, 0) |
135 | 154 | expect(solution).not_to be_nil |
136 | 155 | expect(solution.number).to eq(number) |
137 | 156 | end |
|
0 commit comments