| 1 |
/* |
| 2 |
Copyright 2021 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package options |
| 18 |
|
| 19 |
import ( |
| 20 |
"net" |
| 21 |
"testing" |
| 22 |
|
| 23 |
"k8s.io/apiserver/pkg/server" |
| 24 |
"k8s.io/client-go/rest" |
| 25 |
netutils "k8s.io/utils/net" |
| 26 |
) |
| 27 |
|
| 28 |
func TestEmptyMainCert(t *testing.T) { |
| 29 |
secureServingInfo := &server.SecureServingInfo{} |
| 30 |
var loopbackClientConfig *rest.Config |
| 31 |
|
| 32 |
s := (&SecureServingOptions{ |
| 33 |
BindAddress: netutils.ParseIPSloppy("127.0.0.1"), |
| 34 |
}).WithLoopback() |
| 35 |
ln, err := net.Listen("tcp", "127.0.0.1:0") |
| 36 |
if err != nil { |
| 37 |
t.Fatalf("failed to listen on 127.0.0.1:0") |
| 38 |
} |
| 39 |
defer ln.Close() |
| 40 |
s.Listener = ln |
| 41 |
s.BindPort = ln.Addr().(*net.TCPAddr).Port |
| 42 |
|
| 43 |
if err := s.ApplyTo(&secureServingInfo, &loopbackClientConfig); err != nil { |
| 44 |
t.Errorf("unexpected error: %v", err) |
| 45 |
} |
| 46 |
if loopbackClientConfig == nil { |
| 47 |
t.Errorf("unexpected empty loopbackClientConfig") |
| 48 |
} |
| 49 |
if e, a := 1, len(secureServingInfo.SNICerts); e != a { |
| 50 |
t.Errorf("expected %d SNICert, got %d", e, a) |
| 51 |
} |
| 52 |
} |