File tree Expand file tree Collapse file tree 4 files changed +24
-24
lines changed Expand file tree Collapse file tree 4 files changed +24
-24
lines changed Original file line number Diff line number Diff line change 1
1
2
2
import * as crypto from 'crypto' ;
3
3
import { ISecurity } from '../types' ;
4
- import { passwordDigest } from '../utils' ;
4
+ import { passwordDigest , xmlEscape } from '../utils' ;
5
5
6
6
const validPasswordTypes = [ 'PasswordDigest' , 'PasswordText' ] ;
7
7
@@ -87,7 +87,7 @@ export class WSSecurity implements ISecurity {
87
87
nonce = nHash . digest ( 'base64' ) ;
88
88
}
89
89
if ( this . _passwordType === 'PasswordText' ) {
90
- password = '<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' + this . _password + '</wsse:Password>' ;
90
+ password = '<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' + xmlEscape ( this . _password ) + '</wsse:Password>' ;
91
91
if ( nonce ) {
92
92
password += '<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">' + nonce + '</wsse:Nonce>' ;
93
93
}
@@ -103,7 +103,7 @@ export class WSSecurity implements ISecurity {
103
103
'xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">' +
104
104
timeStampXml +
105
105
'<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-' + created + '">' +
106
- '<wsse:Username>' + this . _username + '</wsse:Username>' +
106
+ '<wsse:Username>' + xmlEscape ( this . _username ) + '</wsse:Username>' +
107
107
password +
108
108
( this . _hasTokenCreated ? '<wsu:Created>' + created + '</wsu:Created>' : '' ) +
109
109
'</wsse:UsernameToken>' +
Original file line number Diff line number Diff line change @@ -48,3 +48,19 @@ export function splitQName<T>(nsName: T) {
48
48
name : topLevelName . substring ( prefixOffset + 1 ) ,
49
49
} ;
50
50
}
51
+
52
+ export function xmlEscape ( obj ) {
53
+ if ( typeof ( obj ) === 'string' ) {
54
+ if ( obj . substr ( 0 , 9 ) === '<![CDATA[' && obj . substr ( - 3 ) === ']]>' ) {
55
+ return obj ;
56
+ }
57
+ return obj
58
+ . replace ( / & / g, '&' )
59
+ . replace ( / < / g, '<' )
60
+ . replace ( / > / g, '>' )
61
+ . replace ( / " / g, '"' )
62
+ . replace ( / ' / g, ''' ) ;
63
+ }
64
+
65
+ return obj ;
66
+ }
Original file line number Diff line number Diff line change @@ -16,29 +16,13 @@ import * as url from 'url';
16
16
import { HttpClient } from '../http' ;
17
17
import { NamespaceContext } from '../nscontext' ;
18
18
import { IOptions } from '../types' ;
19
- import { findPrefix , splitQName , TNS_PREFIX } from '../utils' ;
19
+ import { findPrefix , splitQName , TNS_PREFIX , xmlEscape } from '../utils' ;
20
20
import * as elements from './elements' ;
21
21
22
22
const debug = debugBuilder ( 'node-soap' ) ;
23
23
24
24
const XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance' ;
25
25
26
- function xmlEscape ( obj ) {
27
- if ( typeof ( obj ) === 'string' ) {
28
- if ( obj . substr ( 0 , 9 ) === '<![CDATA[' && obj . substr ( - 3 ) === ']]>' ) {
29
- return obj ;
30
- }
31
- return obj
32
- . replace ( / & / g, '&' )
33
- . replace ( / < / g, '<' )
34
- . replace ( / > / g, '>' )
35
- . replace ( / " / g, '"' )
36
- . replace ( / ' / g, ''' ) ;
37
- }
38
-
39
- return obj ;
40
- }
41
-
42
26
const trimLeft = / ^ [ \s \xA0 ] + / ;
43
27
const trimRight = / [ \s \xA0 ] + $ / ;
44
28
Original file line number Diff line number Diff line change @@ -39,8 +39,8 @@ describe('WSSecurity', function() {
39
39
} ) ;
40
40
41
41
it ( 'should insert a WSSecurity when postProcess is called' , function ( ) {
42
- var username = 'myUser ' ;
43
- var password = 'myPass ' ;
42
+ var username = 'my&User ' ;
43
+ var password = 'my&Pass ' ;
44
44
var options = {
45
45
passwordType : 'PassWordText' ,
46
46
hasNonce : true ,
@@ -59,10 +59,10 @@ describe('WSSecurity', function() {
59
59
xml . should . containEql ( '<wsse:UsernameToken ' ) ;
60
60
xml . should . containEql ( 'xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" ' ) ;
61
61
xml . should . containEql ( 'wsu:Id="SecurityToken-' ) ;
62
- xml . should . containEql ( '<wsse:Username>myUser </wsse:Username>' ) ;
62
+ xml . should . containEql ( '<wsse:Username>my&User </wsse:Username>' ) ;
63
63
xml . should . containEql ( '<wsse:Password ' ) ;
64
64
xml . should . containEql ( 'Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' ) ;
65
- xml . should . containEql ( 'myPass </wsse:Password>' ) ;
65
+ xml . should . containEql ( 'my&Pass </wsse:Password>' ) ;
66
66
xml . should . containEql ( '<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">' ) ;
67
67
xml . should . containEql ( '</wsse:Nonce>' ) ;
68
68
xml . should . containEql ( '<wsu:Created>' ) ;
You can’t perform that action at this time.
0 commit comments