Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

tls: minor fix on http api (#1008) #1036

Merged
merged 2 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,8 @@ func (s *Server) Start(ctx context.Context) (err error) {
if err != nil {
return terror.ErrMasterTLSConfigNotValid.Delegate(err)
}
if tls2 != nil && tls2.TLSConfig() != nil {
tls2.TLSConfig().InsecureSkipVerify = true
}

apiHandler, err := getHTTPAPIHandler(ctx, s.cfg.MasterAddr, tls2.ToGRPCDialOption())
apiHandler, err := getHTTPAPIHandler(ctx, s.cfg.AdvertiseAddr, tls2.ToGRPCDialOption())
if err != nil {
return
}
Expand Down
62 changes: 62 additions & 0 deletions tests/_dmctl_tools/check_master_http_apis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed 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,
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
"io/ioutil"
"net/http"
"os"

"github.com/pingcap/dm/tests/utils"

toolutils "github.com/pingcap/tidb-tools/pkg/utils"
)

// use show-ddl-locks request to test DM-master is online
func main() {
addr := os.Args[1]
sslCA := ""
sslCert := ""
sslKey := ""
transport := http.DefaultTransport.(*http.Transport).Clone()

if len(os.Args) == 5 {
sslCA = os.Args[2]
sslCert = os.Args[3]
sslKey = os.Args[4]

tls, err := toolutils.NewTLS(sslCA, sslCert, sslKey, "", nil)
if err != nil {
utils.ExitWithError(err)
}

tlsCfg := tls.TLSConfig()
tlsCfg.InsecureSkipVerify = true
transport.TLSClientConfig = tlsCfg
}

client := &http.Client{Transport: transport}

resp, err := client.Get("https://" + addr + "/apis/v1alpha1/members")
if err != nil {
utils.ExitWithError(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
utils.ExitWithError(err)
}
fmt.Println(string(body))
}
3 changes: 2 additions & 1 deletion tests/tls/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ function run() {
"query-status test" \
"\"result\": true" 2

echo "test http interface"
echo "test http and api interface"
check_rpc_alive $cur/../bin/check_master_online_http 127.0.0.1:$MASTER_PORT1 "$cur/conf/ca.pem" "$cur/conf/dm.pem" "$cur/conf/dm.key"
check_rpc_alive $cur/../bin/check_master_http_apis 127.0.0.1:$MASTER_PORT1 "$cur/conf/ca.pem" "$cur/conf/dm.pem" "$cur/conf/dm.key"

echo "use common name not in 'cert-allowed-cn' should not request success"
check_rpc_alive $cur/../bin/check_master_online_http 127.0.0.1:$MASTER_PORT1 "$cur/conf/ca.pem" "$cur/conf/other.pem" "$cur/conf/other.key" && exit 1 || true
Expand Down