enhancement(redis): add TLSConfig (#261)

* TLSConfig

* Update README.md

* add tls tests and certs

* Update test-redis.yml

* Update test-redis.yml

* Update test-redis.yml

* Update test-redis.yml

* Update test-redis.yml

correct tls port

* Update test-redis.yml

path

* Update test-redis.yml
This commit is contained in:
Jason McNeil
2022-01-09 17:48:57 -04:00
committed by GitHub
parent 2728ec3c02
commit 842a366c10
17 changed files with 415 additions and 37 deletions

View File

@@ -1,6 +1,8 @@
package redis
import (
"crypto/tls"
"log"
"testing"
"time"
@@ -142,3 +144,46 @@ func Test_Redis_Initalize_WithURL(t *testing.T) {
utils.AssertEqual(t, nil, testStoreUrl.Close())
}
func Test_Redis_Initalize_WithURL_TLS(t *testing.T) {
cer, err := tls.LoadX509KeyPair("./tests/tls/client.crt", "./tests/tls/client.key")
if err != nil {
log.Println(err)
return
}
tlsCfg := &tls.Config{
MinVersion: tls.VersionTLS12,
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
InsecureSkipVerify: true,
Certificates: []tls.Certificate{cer},
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
}
testStoreUrl := New(Config{
URL: "redis://localhost:6380",
TLSConfig: tlsCfg,
})
var (
key = "clark"
val = []byte("kent")
)
err = testStoreUrl.Set(key, val, 0)
utils.AssertEqual(t, nil, err)
result, err := testStoreUrl.Get(key)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, val, result)
err = testStoreUrl.Delete(key)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, nil, testStoreUrl.Close())
}