@@ -387,13 +387,14 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
387
387
}
388
388
389
389
function queryError ( query , err ) {
390
- query . reject ( Object . create ( err , {
390
+ Object . defineProperties ( err , {
391
391
stack : { value : err . stack + query . origin . replace ( / .* \n / , '\n' ) , enumerable : options . debug } ,
392
392
query : { value : query . string , enumerable : options . debug } ,
393
393
parameters : { value : query . parameters , enumerable : options . debug } ,
394
394
args : { value : query . args , enumerable : options . debug } ,
395
395
types : { value : query . statement && query . statement . types , enumerable : options . debug }
396
- } ) )
396
+ } )
397
+ query . reject ( err )
397
398
}
398
399
399
400
function end ( ) {
@@ -442,7 +443,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
442
443
closedDate = performance . now ( )
443
444
hadError && options . shared . retries ++
444
445
delay = ( typeof backoff === 'function' ? backoff ( options . shared . retries ) : backoff ) * 1000
445
- onclose ( connection )
446
+ onclose ( connection , Errors . connection ( 'CONNECTION_CLOSED' , options , socket ) )
446
447
}
447
448
448
449
/* Handlers */
@@ -658,27 +659,30 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
658
659
659
660
/* c8 ignore next 5 */
660
661
async function AuthenticationCleartextPassword ( ) {
662
+ const payload = await Pass ( )
661
663
write (
662
- b ( ) . p ( ) . str ( await Pass ( ) ) . z ( 1 ) . end ( )
664
+ b ( ) . p ( ) . str ( payload ) . z ( 1 ) . end ( )
663
665
)
664
666
}
665
667
666
668
async function AuthenticationMD5Password ( x ) {
667
- write (
668
- b ( ) . p ( ) . str (
669
- 'md5' +
670
- ( await md5 ( Buffer . concat ( [
669
+ const payload = 'md5' + (
670
+ await md5 (
671
+ Buffer . concat ( [
671
672
Buffer . from ( await md5 ( ( await Pass ( ) ) + user ) ) ,
672
673
x . subarray ( 9 )
673
- ] ) ) )
674
- ) . z ( 1 ) . end ( )
674
+ ] )
675
+ )
676
+ )
677
+ write (
678
+ b ( ) . p ( ) . str ( payload ) . z ( 1 ) . end ( )
675
679
)
676
680
}
677
681
678
682
async function SASL ( ) {
683
+ nonce = ( await crypto . randomBytes ( 18 ) ) . toString ( 'base64' )
679
684
b ( ) . p ( ) . str ( 'SCRAM-SHA-256' + b . N )
680
685
const i = b . i
681
- nonce = ( await crypto . randomBytes ( 18 ) ) . toString ( 'base64' )
682
686
write ( b . inc ( 4 ) . str ( 'n,,n=*,r=' + nonce ) . i32 ( b . i - i - 4 , i ) . end ( ) )
683
687
}
684
688
@@ -700,12 +704,12 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
700
704
701
705
serverSignature = ( await hmac ( await hmac ( saltedPassword , 'Server Key' ) , auth ) ) . toString ( 'base64' )
702
706
707
+ const payload = 'c=biws,r=' + res . r + ',p=' + xor (
708
+ clientKey , Buffer . from ( await hmac ( await sha256 ( clientKey ) , auth ) )
709
+ ) . toString ( 'base64' )
710
+
703
711
write (
704
- b ( ) . p ( ) . str (
705
- 'c=biws,r=' + res . r + ',p=' + xor (
706
- clientKey , Buffer . from ( await hmac ( await sha256 ( clientKey ) , auth ) )
707
- ) . toString ( 'base64' )
708
- ) . end ( )
712
+ b ( ) . p ( ) . str ( payload ) . end ( )
709
713
)
710
714
}
711
715
0 commit comments