You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/01/11 11:21:24 UTC

[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #825: support get cert info from env

tianxiaoliang commented on a change in pull request #825:
URL: https://github.com/apache/servicecomb-service-center/pull/825#discussion_r554977787



##########
File path: pkg/tlsutil/tlsutil_test.go
##########
@@ -77,6 +111,21 @@ func TestGetServerTLSConfig(t *testing.T) {
 	}
 }
 
+func TestGetClientTLSConfigFromEnv(t *testing.T) {
+	opts := append(DefaultServerTLSOptions(),
+		WithVerifyPeer(true),
+		WithVerifyHostName(false),
+		WithVersion(ParseSSLProtocol("TLSv1.0"), tls.VersionTLS12),
+		WithCipherSuits(ParseDefaultSSLCipherSuites("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384")),
+	)
+
+	opts = append(opts, preFromEnvMode()...)
+	_, err := GetClientTLSConfig(opts...)
+	if err != nil {
+		t.Fatalf("GetClientTLSConfig failed")

Review comment:
       断言

##########
File path: pkg/tlsutil/tlsutil_test.go
##########
@@ -42,6 +43,39 @@ func TestParseDefaultSSLCipherSuites(t *testing.T) {
 	}
 }
 
+func preFromEnvMode() []SSLConfigOption {
+	ca, _ := ioutil.ReadFile(sslRoot + "trust.cer")
+	cert, _ := ioutil.ReadFile(sslRoot + "server.cer")
+	key, _ := ioutil.ReadFile(sslRoot + "server_key.pem")
+	pwd, _ := ioutil.ReadFile(sslRoot + "cert_pwd")
+
+	_ = os.Setenv("ENV_CA", string(ca))
+	_ = os.Setenv("ENV_CERT", string(cert))
+	_ = os.Setenv("ENV_CERT_KEY", string(key))
+
+	return []SSLConfigOption{
+		WithKeyPass(string(pwd)),
+		WithEnvNameCA("ENV_CA"),
+		WithEnvNameCert("ENV_CERT"),
+		WithEnvNameCertKey("ENV_CERT_KEY"),
+	}
+}
+
+func TestGetServerTLSConfigFromEnv(t *testing.T) {
+	opts := append(DefaultServerTLSOptions(),
+		WithVerifyPeer(true),
+		WithVerifyHostName(false),
+		WithVersion(ParseSSLProtocol("TLSv1.0"), tls.VersionTLS12),
+		WithCipherSuits(ParseDefaultSSLCipherSuites("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384")),
+	)
+
+	opts = append(opts, preFromEnvMode()...)
+	_, err := GetServerTLSConfig(opts...)
+	if err != nil {
+		t.Fatalf("GetServerTLSConfig from env mode failed")

Review comment:
       断言,不要再维护if了




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org