File tree Expand file tree Collapse file tree 2 files changed +41
-13
lines changed
Expand file tree Collapse file tree 2 files changed +41
-13
lines changed Original file line number Diff line number Diff line change @@ -90,20 +90,29 @@ const _createClientBase = (clientName) => {
9090 try {
9191 // NOTE: settings the user explicitly to empty resolves auth problems, see
9292 // https://github.com/go-redis/redis/issues/1343
93- const redisCredentials = cfEnv . cfServiceCredentialsForLabel ( CF_REDIS_SERVICE_LABEL ) ;
94- const redisIsCluster = redisCredentials . cluster_mode ;
95- const url = redisCredentials . uri . replace ( / (?< = r e d i s s : \/ \/ ) [ \w - ] + ?(? = : ) / , "" ) ;
96- if ( redisIsCluster ) {
93+ const {
94+ cluster_mode : isCluster ,
95+ hostname : host ,
96+ port,
97+ password,
98+ tls,
99+ } = cfEnv . cfServiceCredentialsForLabel ( CF_REDIS_SERVICE_LABEL ) ;
100+ const redisClientOptions = {
101+ password,
102+ socket : {
103+ host,
104+ port,
105+ tls,
106+ } ,
107+ } ;
108+ if ( isCluster ) {
97109 return redis . createCluster ( {
98- rootNodes : [ { url } ] ,
110+ rootNodes : [ redisClientOptions ] ,
99111 // https://github.com/redis/node-redis/issues/1782
100- defaults : {
101- password : redisCredentials . password ,
102- socket : { tls : redisCredentials . tls } ,
103- } ,
112+ defaults : redisClientOptions ,
104113 } ) ;
105114 }
106- return redis . createClient ( { url } ) ;
115+ return redis . createClient ( redisClientOptions ) ;
107116 } catch ( err ) {
108117 throw new VError (
109118 { name : VERROR_CLUSTER_NAME , cause : err , info : { clientName } } ,
Original file line number Diff line number Diff line change @@ -87,17 +87,36 @@ describe("redis-adapter test", () => {
8787
8888 test ( "_createClientBase on CF" , async ( ) => {
8989 const mockUrl = "rediss://BAD_USERNAME:pwd@mockUrl" ;
90- const mockUrlUsable = mockUrl . replace ( "BAD_USERNAME" , "" ) ;
9190
9291 envMock . isOnCf = true ;
93- envMock . cfServiceCredentialsForLabel . mockReturnValueOnce ( { uri : mockUrl } ) ;
92+ envMock . cfServiceCredentialsForLabel . mockReturnValueOnce ( {
93+ cluster_mode : false ,
94+ uri : mockUrl ,
95+ hostname : "my-domain.com" ,
96+ port : "1234" ,
97+ password : "mock-password" ,
98+ tls : { tlsOption : "tlsOption" } ,
99+ } ) ;
94100
95101 const client = redisAdapter . _ . _createClientBase ( ) ;
96102
97103 expect ( envMock . cfServiceCredentialsForLabel ) . toHaveBeenCalledTimes ( 1 ) ;
98104 expect ( envMock . cfServiceCredentialsForLabel ) . toHaveBeenCalledWith ( "redis-cache" ) ;
99105 expect ( redis . createClient ) . toHaveBeenCalledTimes ( 1 ) ;
100- expect ( redis . createClient ) . toHaveBeenCalledWith ( { url : mockUrlUsable } ) ;
106+ expect ( redis . createClient . mock . calls [ 0 ] ) . toMatchInlineSnapshot ( `
107+ [
108+ {
109+ "password": "mock-password",
110+ "socket": {
111+ "host": "my-domain.com",
112+ "port": "1234",
113+ "tls": {
114+ "tlsOption": "tlsOption",
115+ },
116+ },
117+ },
118+ ]
119+ ` ) ;
101120 expect ( client ) . toBe ( mockClient ) ;
102121 expect ( loggerSpy . error ) . not . toHaveBeenCalled ( ) ;
103122 } ) ;
You can’t perform that action at this time.
0 commit comments