@@ -12,91 +12,91 @@ import { obfuscate } from '../../src/logging/request-obfuscator';
12
12
describe ( 'RequestObfuscator' , ( ) => {
13
13
describe ( 'obfuscate' , ( ) => {
14
14
it ( 'should not obfuscate `request.body.params` when `method` is not listed for obfuscation' , ( ) => {
15
- const request = { body : '{"id":"1485369469422","method":"foo","params":["foobar"]}' } ;
15
+ const request = { body : '{"id":"1485369469422","method":"foo","params":["foobar"]}' , type : 'request' } ;
16
16
17
17
obfuscate ( request ) ;
18
18
19
- request . should . eql ( { body : '{"id":"1485369469422","method":"foo","params":["foobar"]}' } ) ;
19
+ request . body . should . eql ( '{"id":"1485369469422","method":"foo","params":["foobar"]}' ) ;
20
20
} ) ;
21
21
22
22
it ( 'should obfuscate the authorization header' , ( ) => {
23
- const request = { headers : { authorization : 'Basic ==foobar' } } ;
23
+ const request = { headers : { authorization : 'Basic ==foobar' } , type : 'request' } ;
24
24
25
25
obfuscate ( request ) ;
26
26
27
- request . should . eql ( { headers : { authorization : 'Basic ******' } } ) ;
27
+ request . headers . should . eql ( { authorization : 'Basic ******' } ) ;
28
28
} ) ;
29
29
30
30
it ( 'should obfuscate all private keys from `request.body` when `method` is `importmulti`' , ( ) => {
31
- const request = { body : '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["myprivate1","myprivate2"]},{"address":"foobar2","keys":["myprivate1","myprivate2"]}]]}' } ;
31
+ const request = { body : '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["myprivate1","myprivate2"]},{"address":"foobar2","keys":["myprivate1","myprivate2"]}]]}' , type : 'request' } ;
32
32
33
33
obfuscate ( request ) ;
34
34
35
- request . should . eql ( { body : '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["******","******"]},{"address":"foobar2","keys":["******","******"]}]]}' } ) ;
35
+ request . body . should . eql ( '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["******","******"]},{"address":"foobar2","keys":["******","******"]}]]}' ) ;
36
36
} ) ;
37
37
38
38
it ( 'should obfuscate the private key from `request.body` when `method` is `importprivkey`' , ( ) => {
39
- const request = { body : '{"id":"1485369469422","method":"importprivkey","params":["foobar"]}' } ;
39
+ const request = { body : '{"id":"1485369469422","method":"importprivkey","params":["foobar"]}' , type : 'request' } ;
40
40
41
41
obfuscate ( request ) ;
42
42
43
- request . should . eql ( { body : '{"id":"1485369469422","method":"importprivkey","params":["******"]}' } ) ;
43
+ request . body . should . eql ( '{"id":"1485369469422","method":"importprivkey","params":["******"]}' ) ;
44
44
} ) ;
45
45
46
46
it ( 'should obfuscate the private key from `request.body` when `method` is `signmessagewithprivkey`' , ( ) => {
47
- const request = { body : '{"id":"1485369469422","method":"signmessagewithprivkey","params":["foobar", "foobiz"]}' } ;
47
+ const request = { body : '{"id":"1485369469422","method":"signmessagewithprivkey","params":["foobar", "foobiz"]}' , type : 'request' } ;
48
48
49
49
obfuscate ( request ) ;
50
50
51
- request . should . eql ( { body : '{"id":"1485369469422","method":"signmessagewithprivkey","params":["******","foobiz"]}' } ) ;
51
+ request . body . should . eql ( '{"id":"1485369469422","method":"signmessagewithprivkey","params":["******","foobiz"]}' ) ;
52
52
} ) ;
53
53
54
54
it ( 'should obfuscate all private keys from `request.body` when `method` is `signrawtransaction`' , ( ) => {
55
- const request = { body : '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["biz", "boz"]]}' } ;
55
+ const request = { body : '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["biz", "boz"]]}' , type : 'request' } ;
56
56
57
57
obfuscate ( request ) ;
58
58
59
- request . should . eql ( { body : '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["******","******"]]}' } ) ;
59
+ request . body . should . eql ( '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["******","******"]]}' ) ;
60
60
} ) ;
61
61
62
62
it ( 'should obfuscate the passphrase from `request.body` when `method` is `encryptwallet`' , ( ) => {
63
- const request = { body : '{"id":"1485369469422","method":"encryptwallet","params":["foobar"]}' } ;
63
+ const request = { body : '{"id":"1485369469422","method":"encryptwallet","params":["foobar"]}' , type : 'request' } ;
64
64
65
65
obfuscate ( request ) ;
66
66
67
- request . should . eql ( { body : '{"id":"1485369469422","method":"encryptwallet","params":["******"]}' } ) ;
67
+ request . body . should . eql ( '{"id":"1485369469422","method":"encryptwallet","params":["******"]}' ) ;
68
68
} ) ;
69
69
70
70
it ( 'should obfuscate the passphrase from `request.body` when `method` is `walletpassphrase`' , ( ) => {
71
- const request = { body : '{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]}' } ;
71
+ const request = { body : '{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]}' , type : 'request' } ;
72
72
73
73
obfuscate ( request ) ;
74
74
75
- request . should . eql ( { body : '{"id":"1485369469422","method":"walletpassphrase","params":["******"]}' } ) ;
75
+ request . body . should . eql ( '{"id":"1485369469422","method":"walletpassphrase","params":["******"]}' ) ;
76
76
} ) ;
77
77
78
78
it ( 'should obfuscate the `request.body` of a batch request' , ( ) => {
79
- const request = { body : '[{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]},{"id":"1485369469423","method":"walletpassphrase","params":["foobar"]}]' } ;
79
+ const request = { body : '[{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]},{"id":"1485369469423","method":"walletpassphrase","params":["foobar"]}]' , type : 'request' } ;
80
80
81
81
obfuscate ( request ) ;
82
82
83
- request . should . eql ( { body : '[{"id":"1485369469422","method":"walletpassphrase","params":["******"]},{"id":"1485369469423","method":"walletpassphrase","params":["******"]}]' } ) ;
83
+ request . body . should . eql ( '[{"id":"1485369469422","method":"walletpassphrase","params":["******"]},{"id":"1485369469423","method":"walletpassphrase","params":["******"]}]' ) ;
84
84
} ) ;
85
85
86
86
it ( 'should obfuscate the private key from `response.body` when `method` is `dumpprivkey`' , ( ) => {
87
- const request = { response : { body : { id : '1485369469422-0' , result : 'foobiz' } } } ;
87
+ const request = { response : { body : { id : '1485369469422-0' , result : 'foobiz' } } , type : 'response' } ;
88
88
89
89
obfuscate ( request , { body : '{"id":"1485369469422","method":"dumpprivkey","params":["foobar"]}' } ) ;
90
90
91
- request . should . eql ( { response : { body : { id : '1485369469422-0' , result : '******' } } } ) ;
91
+ request . response . body . should . eql ( { id : '1485369469422-0' , result : '******' } ) ;
92
92
} ) ;
93
93
94
94
it ( 'should obfuscate the `response.body` when `headers.content-type` is `application/octet-stream`' , ( ) => {
95
- const request = { response : { body : new Buffer ( 'foobar' ) , headers : { 'content-type' : 'application/octet-stream' } } } ;
95
+ const request = { response : { body : new Buffer ( 'foobar' ) , headers : { 'content-type' : 'application/octet-stream' } } , type : 'response' } ;
96
96
97
97
obfuscate ( request , { uri : 'foobar.bin' } ) ;
98
98
99
- request . should . eql ( { response : { body : '******' , headers : { 'content-type' : 'application/octet-stream' } } } ) ;
99
+ request . response . should . eql ( { body : '******' , headers : { 'content-type' : 'application/octet-stream' } } ) ;
100
100
} ) ;
101
101
102
102
it ( 'should obfuscate the `request.response.body` of a batch request' , ( ) => {
@@ -107,7 +107,8 @@ describe('RequestObfuscator', () => {
107
107
{ id : '1485369469422-2' , result : 'foobiz' } ,
108
108
{ id : '1485369469422-1' , result : 'foo' }
109
109
]
110
- }
110
+ } ,
111
+ type : 'response'
111
112
} ;
112
113
113
114
obfuscate ( request , { body : '[{"id":"1485369469422-0","method":"dumpprivkey","params":["foobar"]},{"id":"1485369469422-2","method":"getnewaddress","params":["foobiz"]},{"id":"1485369469422-1","method":"dumpprivkey","params":["foobiz"]}]' } ) ;
@@ -119,7 +120,8 @@ describe('RequestObfuscator', () => {
119
120
{ id : '1485369469422-2' , result : 'foobiz' } ,
120
121
{ id : '1485369469422-1' , result : '******' }
121
122
]
122
- }
123
+ } ,
124
+ type : 'response'
123
125
} ) ;
124
126
} ) ;
125
127
} ) ;
0 commit comments