@@ -87,6 +87,64 @@ describe('node-vault', () => {
8787 } ) ;
8888 } ) ;
8989
90+ describe ( 'client initialization' , ( ) => {
91+ it ( 'should not trim endpoint if no trailing slash' , ( ) => {
92+ const defaultsStub = sinon . stub ( ) ;
93+ const vaultConfig = {
94+ endpoint : 'http://localhost:8200' ,
95+ 'request-promise' : {
96+ defaults : defaultsStub ,
97+ } ,
98+ } ;
99+ const vault = index ( vaultConfig ) ;
100+ vault . endpoint . should . equal ( 'http://localhost:8200' ) ;
101+ } ) ;
102+
103+ it ( 'should trim endpoint if trailing slash' , ( ) => {
104+ const defaultsStub = sinon . stub ( ) ;
105+ const vaultConfig = {
106+ endpoint : 'http://localhost:8200/' ,
107+ 'request-promise' : {
108+ defaults : defaultsStub ,
109+ } ,
110+ } ;
111+ const vault = index ( vaultConfig ) ;
112+ vault . endpoint . should . equal ( 'http://localhost:8200' ) ;
113+ } ) ;
114+
115+ it ( 'should not produce double slashes in request URI when endpoint has trailing slash' , ( done ) => {
116+ const request = sinon . stub ( ) ;
117+ const response = sinon . stub ( ) ;
118+ response . statusCode = 200 ;
119+ request . returns ( {
120+ then ( fn ) {
121+ return fn ( response ) ;
122+ } ,
123+ catch ( fn ) {
124+ return fn ( ) ;
125+ } ,
126+ } ) ;
127+
128+ const vault = index ( {
129+ endpoint : 'http://localhost:8200/' ,
130+ token : '123' ,
131+ 'request-promise' : {
132+ defaults : ( ) => request ,
133+ } ,
134+ } ) ;
135+
136+ vault . read ( 'secret/hello' )
137+ . then ( ( ) => {
138+ request . should . have . calledOnce ( ) ;
139+ const uri = request . firstCall . args [ 0 ] . uri ;
140+ uri . should . equal ( 'http://localhost:8200/v1/secret/hello' ) ;
141+ uri . should . not . contain ( '//v1' ) ;
142+ done ( ) ;
143+ } )
144+ . catch ( done ) ;
145+ } ) ;
146+ } ) ;
147+
90148 describe ( 'client' , ( ) => {
91149 let request = null ;
92150 let response = null ;
0 commit comments