2022-04-19 12:41:36 +00:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestX509PolicyOptions_IsWildcardLiteralAllowed(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
options *X509PolicyOptions
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nil-options",
|
|
|
|
options: nil,
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
2022-04-21 21:45:05 +00:00
|
|
|
name: "not-set",
|
|
|
|
options: &X509PolicyOptions{},
|
|
|
|
want: false,
|
2022-04-19 12:41:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set-true",
|
|
|
|
options: &X509PolicyOptions{
|
2022-04-21 21:45:05 +00:00
|
|
|
AllowWildcardLiteral: true,
|
2022-04-19 12:41:36 +00:00
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set-false",
|
|
|
|
options: &X509PolicyOptions{
|
2022-04-21 21:45:05 +00:00
|
|
|
AllowWildcardLiteral: false,
|
2022-04-19 12:41:36 +00:00
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := tt.options.IsWildcardLiteralAllowed(); got != tt.want {
|
|
|
|
t.Errorf("X509PolicyOptions.IsWildcardLiteralAllowed() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestX509PolicyOptions_ShouldVerifySubjectCommonName(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
options *X509PolicyOptions
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nil-options",
|
|
|
|
options: nil,
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
2022-04-21 21:45:05 +00:00
|
|
|
name: "not-set",
|
|
|
|
options: &X509PolicyOptions{},
|
|
|
|
want: true,
|
2022-04-19 12:41:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set-true",
|
|
|
|
options: &X509PolicyOptions{
|
2022-04-21 21:45:05 +00:00
|
|
|
DisableSubjectCommonNameVerification: true,
|
2022-04-19 12:41:36 +00:00
|
|
|
},
|
2022-04-21 21:45:05 +00:00
|
|
|
want: false,
|
2022-04-19 12:41:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set-false",
|
|
|
|
options: &X509PolicyOptions{
|
2022-04-21 21:45:05 +00:00
|
|
|
DisableSubjectCommonNameVerification: false,
|
2022-04-19 12:41:36 +00:00
|
|
|
},
|
2022-04-21 21:45:05 +00:00
|
|
|
want: true,
|
2022-04-19 12:41:36 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := tt.options.ShouldVerifySubjectCommonName(); got != tt.want {
|
|
|
|
t.Errorf("X509PolicyOptions.ShouldVerifySubjectCommonName() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|