-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor extension functions to support x509 and google_x509
Signed-off-by: linus-sun <[email protected]>
- Loading branch information
Showing
7 changed files
with
121 additions
and
166 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -23,6 +23,9 @@ import ( | |
"strings" | ||
"testing" | ||
|
||
google_asn1 "github.com/google/certificate-transparency-go/asn1" | ||
google_x509 "github.com/google/certificate-transparency-go/x509" | ||
google_pkix "github.com/google/certificate-transparency-go/x509/pkix" | ||
"github.com/sigstore/rekor-monitor/pkg/fulcio/extensions" | ||
) | ||
|
||
|
@@ -382,6 +385,35 @@ func TestOIDMatchesValue(t *testing.T) { | |
} | ||
} | ||
|
||
// Test when OID is present and matches value | ||
func TestGoogleOIDMatchesValue(t *testing.T) { | ||
oid := asn1.ObjectIdentifier{2, 5, 29, 17} | ||
extValueString := "test cert value" | ||
extensionValues := []string{extValueString} | ||
marshalledExtValue, err := google_asn1.Marshal(extValueString) | ||
if err != nil { | ||
t.Errorf("error marshalling extension value: %v", err) | ||
} | ||
cert := &google_x509.Certificate{ | ||
Extensions: []google_pkix.Extension{ | ||
{ | ||
Id: google_asn1.ObjectIdentifier{2, 5, 29, 17}, | ||
Value: marshalledExtValue, | ||
}, | ||
}, | ||
} | ||
matches, matchedOID, extValue, err := OIDMatchesPolicy(cert, oid, extensionValues) | ||
if !matches || err != nil { | ||
t.Errorf("Expected true, got %v, error %v", matches, err) | ||
} | ||
if matchedOID.String() != oid.String() { | ||
t.Errorf("Expected oid to equal 2.5.29.17, got %s", matchedOID.String()) | ||
} | ||
if extValue != extValueString { | ||
t.Errorf("Expected string to equal 'test cert value', got %s", extValue) | ||
} | ||
} | ||
|
||
// Test when cert is present but the value does not match | ||
func TestCertDoesNotMatch(t *testing.T) { | ||
emailAddr := "[email protected]" | ||
|