Skip to content

Commit

Permalink
--insecure option not applied correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
theganyo committed Jun 9, 2020
1 parent b797953 commit 12d5248
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
65 changes: 65 additions & 0 deletions cmd/provision/provision_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2020 Google LLC
//
// 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,
// 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 provision

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/apigee/apigee-remote-service-cli/apigee"
"github.com/apigee/apigee-remote-service-cli/shared"
)

func TestVerifyRemoteServiceProxyTLS(t *testing.T) {

count := 0
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte("{}"))
count++
}))

auth := &apigee.EdgeAuth{}

// try without InsecureSkipVerify
p := &provision{
RootArgs: &shared.RootArgs{
RuntimeBase: ts.URL,
Token: "-",
InsecureSkipVerify: false,
},
verifyOnly: true,
}
if err := p.Resolve(false, false); err != nil {
t.Fatal(err)
}
if err := p.verifyRemoteServiceProxy(auth, shared.Printf); err == nil {
t.Errorf("got nil error, want TLS failure")
}

// try with InsecureSkipVerify
p.InsecureSkipVerify = true
if err := p.Resolve(false, false); err != nil {
t.Fatal(err)
}

if err := p.verifyRemoteServiceProxy(auth, shared.Printf); err != nil {
t.Errorf("unexpected error: %v", err)
}
if count != 4 {
t.Errorf("got %d, want %d", count, 4)
}
}
5 changes: 3 additions & 2 deletions shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ func (r *RootArgs) Resolve(skipAuth, requireRuntime bool) error {
BearerToken: r.Token,
SkipAuth: skipAuth,
},
GCPManaged: r.IsGCPManaged,
Debug: r.Verbose,
GCPManaged: r.IsGCPManaged,
Debug: r.Verbose,
InsecureSkipVerify: r.InsecureSkipVerify,
}

var err error
Expand Down

0 comments on commit 12d5248

Please sign in to comment.