You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/11/08 09:13:10 UTC

[GitHub] [apisix-dashboard] moonming commented on a change in pull request #719: bugfix: dashboard 2.0 failed to fetch ssl certificate not found

moonming commented on a change in pull request #719:
URL: https://github.com/apache/apisix-dashboard/pull/719#discussion_r519309618



##########
File path: api/test/e2e/ssl_test.go
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package e2e
+
+import (
+	"context"
+	"crypto/tls"
+	"encoding/json"
+	"io/ioutil"
+	"net"
+	"net/http"
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestSSL_Basic(t *testing.T) {
+	testCert, err := ioutil.ReadFile("../certs/test2.crt")
+	assert.Nil(t, err)
+	testKey, err := ioutil.ReadFile("../certs/test2.key")
+	assert.Nil(t, err)
+	apisixKey, err := ioutil.ReadFile("../certs/apisix.key")
+	assert.Nil(t, err)
+	body, err := json.Marshal(map[string]string{
+		"id":   "1",
+		"cert": string(testCert),
+		"key":  string(testKey),
+	})
+	assert.Nil(t, err)
+	invalidBody, err := json.Marshal(map[string]string{
+		"id":   "1",
+		"cert": string(testCert),
+		"key":  string(apisixKey),
+	})
+
+	//Before configuring SSL, make a HTTPS request
+	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
+	http.DefaultTransport.(*http.Transport).DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
+		if addr == "www.test2.com:9443" {
+			addr = "127.0.0.1:9443"
+		}
+		dialer := &net.Dialer{}
+		return dialer.DialContext(ctx, network, addr)
+	}
+	_, err = http.Get("https://www.test2.com:9443")
+	assert.NotNil(t, err)
+	assert.EqualError(t, err, "Get https://www.test2.com:9443: remote error: tls: internal error")
+
+	tests := []HttpTestCase{
+		{
+			caseDesc:     "create ssl fail - key and cert not match",
+			Object:       MangerApiExpect(t),
+			Method:       http.MethodPost,
+			Path:         "/apisix/admin/ssl",
+			Body:         string(invalidBody),
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+		{
+			caseDesc:     "create ssl successfully",
+			Object:       MangerApiExpect(t),
+			Method:       http.MethodPost,
+			Path:         "/apisix/admin/ssl",
+			Body:         string(body),
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello_",
+				"hosts": ["test2.com", "*.test2.com"],
+				"upstream": {
+					"nodes": {
+						"172.16.238.20:1980": 1
+					},
+					"type": "roundrobin"
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "hit the route just created using HTTPS",
+			Object:       APISIXHTTPSExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello_",
+			Headers:      map[string]string{"Host": "www.test2.com"},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world\n",
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc:     "delete route",
+			Object:       MangerApiExpect(t),
+			Method:       http.MethodDelete,
+			Path:         "/apisix/admin/routes/r1",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "delete ssl",
+			Object:       MangerApiExpect(t),
+			Method:       http.MethodDelete,
+			Path:         "/apisix/admin/ssl/1",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+
+	//try again after deleting SSL, make a HTTPS request
+	time.Sleep(time.Duration(20) * time.Millisecond)
+	_, err = http.Get("https://www.test2.com:9443")
+	assert.NotNil(t, err)
+	assert.EqualError(t, err, "Get https://www.test2.com:9443: remote error: tls: internal error")

Review comment:
       why return ssl error? The router has been deleted




----------------------------------------------------------------
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