forked from TrueCloudLab/certificates
Fix random order in tests.
This commit is contained in:
parent
8510e25b3b
commit
6116523055
1 changed files with 29 additions and 3 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -292,8 +293,11 @@ func TestAddFederationToRootCAs(t *testing.T) {
|
|||
return
|
||||
}
|
||||
if !reflect.DeepEqual(ctx.Config, tt.want) {
|
||||
// Federated roots are randomly sorted
|
||||
if !equalPools(ctx.Config.RootCAs, tt.want.RootCAs) || ctx.Config.ClientCAs != nil {
|
||||
t.Errorf("AddFederationToRootCAs() = %v, want %v", ctx.Config, tt.want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -345,8 +349,11 @@ func TestAddFederationToClientCAs(t *testing.T) {
|
|||
return
|
||||
}
|
||||
if !reflect.DeepEqual(ctx.Config, tt.want) {
|
||||
// Federated roots are randomly sorted
|
||||
if !equalPools(ctx.Config.ClientCAs, tt.want.ClientCAs) || ctx.Config.RootCAs != nil {
|
||||
t.Errorf("AddFederationToClientCAs() = %v, want %v", ctx.Config, tt.want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -444,8 +451,27 @@ func TestAddFederationToCAs(t *testing.T) {
|
|||
return
|
||||
}
|
||||
if !reflect.DeepEqual(ctx.Config, tt.want) {
|
||||
// Federated roots are randomly sorted
|
||||
if !equalPools(ctx.Config.ClientCAs, tt.want.ClientCAs) || !equalPools(ctx.Config.RootCAs, tt.want.RootCAs) {
|
||||
t.Errorf("AddFederationToCAs() = %v, want %v", ctx.Config, tt.want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func equalPools(a, b *x509.CertPool) bool {
|
||||
subjects := a.Subjects()
|
||||
sA := make([]string, len(subjects))
|
||||
for i := range subjects {
|
||||
sA[i] = string(subjects[i])
|
||||
}
|
||||
subjects = b.Subjects()
|
||||
sB := make([]string, len(subjects))
|
||||
for i := range subjects {
|
||||
sB[i] = string(subjects[i])
|
||||
}
|
||||
sort.Sort(sort.StringSlice(sA))
|
||||
sort.Sort(sort.StringSlice(sB))
|
||||
return reflect.DeepEqual(sA, sB)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue