-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #46057 Change-Id: Id3af101c54108d6fd5b65946c4358872358eefcc Reviewed-on: https://go-review.googlesource.com/c/go/+/388915 Trust: Roland Shoemaker <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Damien Neil <[email protected]>
- Loading branch information
1 parent
cd33b40
commit 4aacb7f
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package x509 | ||
|
||
import "testing" | ||
|
||
func TestCertPoolEqual(t *testing.T) { | ||
a, b := NewCertPool(), NewCertPool() | ||
if !a.Equal(b) { | ||
t.Error("two empty pools not equal") | ||
} | ||
|
||
tc := &Certificate{Raw: []byte{1, 2, 3}, RawSubject: []byte{2}} | ||
a.AddCert(tc) | ||
if a.Equal(b) { | ||
t.Error("empty pool equals non-empty pool") | ||
} | ||
|
||
b.AddCert(tc) | ||
if !a.Equal(b) { | ||
t.Error("two non-empty pools not equal") | ||
} | ||
|
||
otherTC := &Certificate{Raw: []byte{9, 8, 7}, RawSubject: []byte{8}} | ||
a.AddCert(otherTC) | ||
if a.Equal(b) { | ||
t.Error("non-equal pools equal") | ||
} | ||
|
||
systemA, err := SystemCertPool() | ||
if err != nil { | ||
t.Fatalf("unable to load system cert pool: %s", err) | ||
} | ||
systemB, err := SystemCertPool() | ||
if err != nil { | ||
t.Fatalf("unable to load system cert pool: %s", err) | ||
} | ||
if !systemA.Equal(systemB) { | ||
t.Error("two empty system pools not equal") | ||
} | ||
|
||
systemA.AddCert(tc) | ||
if systemA.Equal(systemB) { | ||
t.Error("empty system pool equals non-empty system pool") | ||
} | ||
|
||
systemB.AddCert(tc) | ||
if !systemA.Equal(systemB) { | ||
t.Error("two non-empty system pools not equal") | ||
} | ||
|
||
systemA.AddCert(otherTC) | ||
if systemA.Equal(systemB) { | ||
t.Error("non-equal system pools equal") | ||
} | ||
} |