...

Source file src/github.com/sigstore/cosign/v2/pkg/cosign/certextensions_test.go

Documentation: github.com/sigstore/cosign/v2/pkg/cosign

     1  // Copyright 2022 The Sigstore Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package cosign
    16  
    17  import (
    18  	"crypto/x509"
    19  	"crypto/x509/pkix"
    20  	"encoding/asn1"
    21  	"testing"
    22  )
    23  
    24  func createCert(t *testing.T) *x509.Certificate {
    25  	t.Helper()
    26  	return &x509.Certificate{
    27  		Extensions: []pkix.Extension{
    28  			{Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 1}, Value: []byte("myIssuer")},
    29  			{Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 2}, Value: []byte("myWorkflowTrigger")},
    30  			{Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 3}, Value: []byte("myWorkflowSha")},
    31  			{Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 4}, Value: []byte("myWorkflowName")},
    32  			{Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 5}, Value: []byte("myWorkflowRepository")},
    33  			{Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 6}, Value: []byte("myWorkflowRef")},
    34  		},
    35  	}
    36  }
    37  
    38  func TestCertExtensions(t *testing.T) {
    39  	t.Parallel()
    40  	cert := createCert(t)
    41  	exts := CertExtensions{Cert: cert}
    42  
    43  	if val := exts.GetIssuer(); val != "myIssuer" {
    44  		t.Fatal("CertExtension does not extract field 'oidcIssuer' correctly")
    45  	}
    46  
    47  	if val := exts.GetCertExtensionGithubWorkflowTrigger(); val != "myWorkflowTrigger" {
    48  		t.Fatal("CertExtension does not extract field 'githubWorkflowTrigger' correctly")
    49  	}
    50  
    51  	if val := exts.GetExtensionGithubWorkflowSha(); val != "myWorkflowSha" {
    52  		t.Fatal("CertExtension does not extract field 'githubWorkflowSha' correctly")
    53  	}
    54  
    55  	if val := exts.GetCertExtensionGithubWorkflowName(); val != "myWorkflowName" {
    56  		t.Fatal("CertExtension does not extract field 'githubWorkflowName' correctly")
    57  	}
    58  
    59  	if val := exts.GetCertExtensionGithubWorkflowRepository(); val != "myWorkflowRepository" {
    60  		t.Fatal("CertExtension does not extract field 'githubWorkflowRepository' correctly")
    61  	}
    62  
    63  	if val := exts.GetCertExtensionGithubWorkflowRef(); val != "myWorkflowRef" {
    64  		t.Fatal("CertExtension does not extract field 'githubWorkflowRef' correctly")
    65  	}
    66  }
    67  

View as plain text