Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // The script requests pin infinitely when the dialog is closed, and requests | |
| 6 // the input again when the PIN is wrong till 3 times. When the correct | |
| 7 // PIN (1234) is given, the script requests to close the dialog. | |
| 8 function userInputCallback(codeValue) { | |
| 9 if (chrome.runtime.lastError != null) { | |
| 10 chrome.test.fail('Error: ' + chrome.runtime.lastError.message); | |
|
Devlin
2016/11/01 16:24:30
We never actually check for test failures anywhere
igorcov
2016/11/04 15:51:42
Right, we don't have any test for that.
Devlin
2016/11/05 06:10:59
We should - having chrome.test.fail/chrome.test.su
igorcov
2016/11/22 13:50:47
I've changed the code to use the chrome.test.sendM
| |
| 11 return; | |
| 12 } | |
| 13 | |
| 14 if (attempts >= 3) { | |
| 15 console.info('Returning after maximum attempts exceeded'); | |
| 16 return; | |
| 17 } | |
| 18 | |
| 19 console.info('UserInput received, value = ' + codeValue); | |
| 20 if (!codeValue || !codeValue.userInput) { | |
| 21 console.info('User closed the dialog'); | |
| 22 chrome.certificateProvider.requestPin({signRequestId: 123}, | |
| 23 userInputCallback); | |
| 24 return; | |
| 25 } | |
| 26 | |
| 27 var success = (codeValue.userInput == '1234'); // validatePIN(codeValue); | |
|
Devlin
2016/11/01 16:24:30
parens unnecessary
Devlin
2016/11/01 16:24:30
what is this comment for?
igorcov
2016/11/04 15:51:42
Done.
igorcov
2016/11/04 15:51:42
It's just what that code is supposed to do. Fixed
| |
| 28 if (success) { | |
| 29 console.info('Success'); | |
| 30 chrome.certificateProvider.stopPinRequest({signRequestId: 123}, | |
| 31 closeCallback); | |
| 32 } else { | |
| 33 attempts++; | |
| 34 console.info('Invalid PIN'); | |
| 35 var code = attempts < 3 ? | |
| 36 {signRequestId: 123, errorType: 'INVALID_PIN'} : | |
| 37 {signRequestId: 123, requestType: 'PUK', | |
| 38 errorType: 'MAX_ATTEMPTS_EXCEEDED', | |
| 39 attemptsLeft: 0}; | |
| 40 chrome.certificateProvider.requestPin(code, userInputCallback); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 function closeCallback() { | |
| 45 console.info('Close finished on Chrome side'); | |
| 46 if (chrome.runtime.lastError != null) { | |
| 47 console.error('Error: ' + chrome.runtime.lastError.message); | |
| 48 return; | |
| 49 } | |
| 50 | |
| 51 // User authenticated. | |
| 52 console.info('Successfully authenticated!'); | |
| 53 } | |
| 54 | |
| 55 var attempts = 0; | |
| 56 chrome.certificateProvider.requestPin({signRequestId: 123}, userInputCallback); | |
| OLD | NEW |