|
| 1 | +/* |
| 2 | +Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved. |
| 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 soap |
| 18 | + |
| 19 | +import ( |
| 20 | + "crypto/tls" |
| 21 | + "crypto/x509" |
| 22 | + "testing" |
| 23 | +) |
| 24 | + |
| 25 | +func TestIsCertificateUntrusted(t *testing.T) { |
| 26 | + type args struct { |
| 27 | + } |
| 28 | + tests := []struct { |
| 29 | + name string |
| 30 | + err error |
| 31 | + want bool |
| 32 | + }{ |
| 33 | + { |
| 34 | + name: "tls.CertificateVerificationError", |
| 35 | + err: x509.HostnameError{ |
| 36 | + Certificate: &x509.Certificate{}, |
| 37 | + Host: "1.2.3.4", |
| 38 | + }, |
| 39 | + want: true, |
| 40 | + }, |
| 41 | + { |
| 42 | + name: "tls.CertificateVerificationError", |
| 43 | + err: &tls.CertificateVerificationError{ |
| 44 | + UnverifiedCertificates: []*x509.Certificate{ |
| 45 | + &x509.Certificate{}, |
| 46 | + }, |
| 47 | + Err: x509.HostnameError{ |
| 48 | + Certificate: &x509.Certificate{}, |
| 49 | + Host: "5.6.7.8", |
| 50 | + }, |
| 51 | + }, |
| 52 | + want: true, |
| 53 | + }, |
| 54 | + } |
| 55 | + for _, tt := range tests { |
| 56 | + t.Run(tt.name, func(t *testing.T) { |
| 57 | + if got := IsCertificateUntrusted(tt.err); got != tt.want { |
| 58 | + t.Errorf("IsCertificateUntrusted() = %v, want %v", got, tt.want) |
| 59 | + } |
| 60 | + }) |
| 61 | + } |
| 62 | +} |
0 commit comments