commit
d46c5b2f40
@ -1,74 +0,0 @@
|
|||||||
linters-settings:
|
|
||||||
govet:
|
|
||||||
check-shadowing: true
|
|
||||||
settings:
|
|
||||||
printf:
|
|
||||||
funcs:
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
|
|
||||||
revive:
|
|
||||||
min-confidence: 0
|
|
||||||
gocyclo:
|
|
||||||
min-complexity: 10
|
|
||||||
maligned:
|
|
||||||
suggest-new: true
|
|
||||||
dupl:
|
|
||||||
threshold: 100
|
|
||||||
goconst:
|
|
||||||
min-len: 2
|
|
||||||
min-occurrences: 2
|
|
||||||
depguard:
|
|
||||||
list-type: blacklist
|
|
||||||
packages:
|
|
||||||
# logging is allowed only by logutils.Log, logrus
|
|
||||||
# is allowed to use only in logutils package
|
|
||||||
- github.com/sirupsen/logrus
|
|
||||||
misspell:
|
|
||||||
locale: US
|
|
||||||
lll:
|
|
||||||
line-length: 140
|
|
||||||
goimports:
|
|
||||||
local-prefixes: github.com/golangci/golangci-lint
|
|
||||||
gocritic:
|
|
||||||
enabled-tags:
|
|
||||||
- performance
|
|
||||||
- style
|
|
||||||
- experimental
|
|
||||||
- diagnostic
|
|
||||||
disabled-checks:
|
|
||||||
- commentFormatting
|
|
||||||
- commentedOutCode
|
|
||||||
- evalOrder
|
|
||||||
- hugeParam
|
|
||||||
- octalLiteral
|
|
||||||
- rangeValCopy
|
|
||||||
- tooManyResultsChecker
|
|
||||||
- unnamedResult
|
|
||||||
|
|
||||||
linters:
|
|
||||||
disable-all: true
|
|
||||||
enable:
|
|
||||||
- gocritic
|
|
||||||
- gofmt
|
|
||||||
- gosimple
|
|
||||||
- govet
|
|
||||||
- ineffassign
|
|
||||||
- misspell
|
|
||||||
- revive
|
|
||||||
- staticcheck
|
|
||||||
- unused
|
|
||||||
|
|
||||||
run:
|
|
||||||
skip-dirs:
|
|
||||||
- pkg
|
|
||||||
|
|
||||||
issues:
|
|
||||||
exclude:
|
|
||||||
- can't lint
|
|
||||||
- declaration of "err" shadows declaration at line
|
|
||||||
- should have a package comment, unless it's in another file for this package
|
|
||||||
- error strings should not be capitalized or end with punctuation or a newline
|
|
||||||
- Wrapf call needs 1 arg but has 2 args
|
|
||||||
- cs.NegotiatedProtocolIsMutual is deprecated
|
|
@ -0,0 +1,82 @@
|
|||||||
|
//go:build go1.18
|
||||||
|
// +build go1.18
|
||||||
|
|
||||||
|
package provisioner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/x509"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestACME_GetAttestationRoots(t *testing.T) {
|
||||||
|
appleCA, err := os.ReadFile("testdata/certs/apple-att-ca.crt")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
yubicoCA, err := os.ReadFile("testdata/certs/yubico-piv-ca.crt")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pool := x509.NewCertPool()
|
||||||
|
pool.AppendCertsFromPEM(appleCA)
|
||||||
|
pool.AppendCertsFromPEM(yubicoCA)
|
||||||
|
|
||||||
|
type fields struct {
|
||||||
|
Type string
|
||||||
|
Name string
|
||||||
|
AttestationRoots []byte
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
want *x509.CertPool
|
||||||
|
want1 bool
|
||||||
|
}{
|
||||||
|
{"ok", fields{"ACME", "acme", bytes.Join([][]byte{appleCA, yubicoCA}, []byte("\n"))}, pool, true},
|
||||||
|
{"nil", fields{"ACME", "acme", nil}, nil, false},
|
||||||
|
{"empty", fields{"ACME", "acme", []byte{}}, nil, false},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
p := &ACME{
|
||||||
|
Type: tt.fields.Type,
|
||||||
|
Name: tt.fields.Name,
|
||||||
|
AttestationRoots: tt.fields.AttestationRoots,
|
||||||
|
}
|
||||||
|
if err := p.Init(Config{
|
||||||
|
Claims: globalProvisionerClaims,
|
||||||
|
Audiences: testAudiences,
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
got, got1 := p.GetAttestationRoots()
|
||||||
|
switch {
|
||||||
|
case tt.want == nil && got == nil:
|
||||||
|
break
|
||||||
|
case tt.want == nil && got != nil, tt.want != nil && got == nil:
|
||||||
|
t.Errorf("ACME.GetAttestationRoots() got = %v, want %v", got, tt.want)
|
||||||
|
default:
|
||||||
|
//nolint:staticcheck // this file only runs in go1.18
|
||||||
|
gotSubjects := got.Subjects()
|
||||||
|
//nolint:staticcheck // this file only runs in go1.18
|
||||||
|
wantSubjects := tt.want.Subjects()
|
||||||
|
if len(gotSubjects) != len(wantSubjects) {
|
||||||
|
t.Errorf("ACME.GetAttestationRoots() got = %v, want %v", got, tt.want)
|
||||||
|
} else {
|
||||||
|
for i, gotSub := range gotSubjects {
|
||||||
|
if !bytes.Equal(gotSub, wantSubjects[i]) {
|
||||||
|
t.Errorf("ACME.GetAttestationRoots() got = %v, want %v", got, tt.want)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if got1 != tt.want1 {
|
||||||
|
t.Errorf("ACME.GetAttestationRoots() got1 = %v, want %v", got1, tt.want1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
//go:build !go1.18
|
||||||
|
// +build !go1.18
|
||||||
|
|
||||||
|
package provisioner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/x509"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestACME_GetAttestationRoots(t *testing.T) {
|
||||||
|
appleCA, err := os.ReadFile("testdata/certs/apple-att-ca.crt")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
yubicoCA, err := os.ReadFile("testdata/certs/yubico-piv-ca.crt")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pool := x509.NewCertPool()
|
||||||
|
pool.AppendCertsFromPEM(appleCA)
|
||||||
|
pool.AppendCertsFromPEM(yubicoCA)
|
||||||
|
|
||||||
|
type fields struct {
|
||||||
|
Type string
|
||||||
|
Name string
|
||||||
|
AttestationRoots []byte
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
want *x509.CertPool
|
||||||
|
want1 bool
|
||||||
|
}{
|
||||||
|
{"ok", fields{"ACME", "acme", bytes.Join([][]byte{appleCA, yubicoCA}, []byte("\n"))}, pool, true},
|
||||||
|
{"nil", fields{"ACME", "acme", nil}, nil, false},
|
||||||
|
{"empty", fields{"ACME", "acme", []byte{}}, nil, false},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
p := &ACME{
|
||||||
|
Type: tt.fields.Type,
|
||||||
|
Name: tt.fields.Name,
|
||||||
|
AttestationRoots: tt.fields.AttestationRoots,
|
||||||
|
}
|
||||||
|
if err := p.Init(Config{
|
||||||
|
Claims: globalProvisionerClaims,
|
||||||
|
Audiences: testAudiences,
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
got, got1 := p.GetAttestationRoots()
|
||||||
|
if tt.want == nil && got != nil {
|
||||||
|
t.Errorf("ACME.GetAttestationRoots() got = %v, want %v", got, tt.want)
|
||||||
|
} else if !tt.want.Equal(got) {
|
||||||
|
t.Errorf("ACME.GetAttestationRoots() got = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
if got1 != tt.want1 {
|
||||||
|
t.Errorf("ACME.GetAttestationRoots() got1 = %v, want %v", got1, tt.want1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue