...

Source file src/github.com/google/certificate-transparency-go/trillian/ctfe/cert_quota_test.go

Documentation: github.com/google/certificate-transparency-go/trillian/ctfe

     1  // Copyright 2018 Google LLC. All Rights Reserved.
     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 ctfe
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/google/certificate-transparency-go/trillian/ctfe/testonly"
    21  	"github.com/google/certificate-transparency-go/x509"
    22  	"github.com/google/certificate-transparency-go/x509util"
    23  )
    24  
    25  func mustDePEM(t *testing.T, pem string) *x509.Certificate {
    26  	t.Helper()
    27  	c, err := x509util.CertificateFromPEM([]byte(pem))
    28  	if x509.IsFatal(err) {
    29  		t.Fatalf("Failed to parse PEM: %v", err)
    30  	}
    31  	return c
    32  }
    33  
    34  func TestQuotaUserForCert(t *testing.T) {
    35  	for _, test := range []struct {
    36  		desc string
    37  		cert *x509.Certificate
    38  		want string
    39  	}{
    40  		{
    41  			desc: "cacert",
    42  			cert: mustDePEM(t, testonly.CACertPEM),
    43  			want: "@intermediate O=Certificate Transparency CA,L=Erw Wen,ST=Wales,C=GB 02adddca08",
    44  		},
    45  		{
    46  			desc: "intermediate",
    47  			cert: mustDePEM(t, testonly.FakeIntermediateCertPEM),
    48  			want: "@intermediate CN=FakeIntermediateAuthority,OU=Eng,O=Google,L=London,ST=London,C=GB 6e62e56f67",
    49  		},
    50  	} {
    51  		t.Run(test.desc, func(t *testing.T) {
    52  			if got := QuotaUserForCert(test.cert); got != test.want {
    53  				t.Fatalf("QuotaUserForCert() = %q, want %q", got, test.want)
    54  			}
    55  		})
    56  	}
    57  }
    58  

View as plain text