...

Source file src/github.com/google/certificate-transparency-go/ctpolicy/applepolicy_test.go

Documentation: github.com/google/certificate-transparency-go/ctpolicy

     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  package ctpolicy
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/google/certificate-transparency-go/x509"
    20  
    21  	"github.com/kylelemons/godebug/pretty"
    22  )
    23  
    24  func wantedAppleGroups(count int) LogPolicyData {
    25  	gi := LogPolicyData{
    26  		BaseName: {
    27  			Name: BaseName,
    28  			LogURLs: map[string]bool{
    29  				"https://ct.googleapis.com/aviator/":        true,
    30  				"https://ct.googleapis.com/icarus/":         true,
    31  				"https://ct.googleapis.com/rocketeer/":      true,
    32  				"https://ct.googleapis.com/racketeer/":      true,
    33  				"https://ct.googleapis.com/logs/argon2020/": true,
    34  				"https://log.bob.io":                        true,
    35  			},
    36  			MinInclusions: count,
    37  			IsBase:        true,
    38  			LogWeights: map[string]float32{
    39  				"https://ct.googleapis.com/aviator/":        1.0,
    40  				"https://ct.googleapis.com/icarus/":         1.0,
    41  				"https://ct.googleapis.com/rocketeer/":      1.0,
    42  				"https://ct.googleapis.com/racketeer/":      1.0,
    43  				"https://ct.googleapis.com/logs/argon2020/": 1.0,
    44  				"https://log.bob.io":                        1.0,
    45  			},
    46  		},
    47  	}
    48  	return gi
    49  }
    50  
    51  func TestCheckApplePolicy(t *testing.T) {
    52  	tests := []struct {
    53  		name string
    54  		cert *x509.Certificate
    55  		want LogPolicyData
    56  	}{
    57  		{
    58  			name: "Short",
    59  			cert: getTestCertPEMShort(),
    60  			want: wantedAppleGroups(2),
    61  		},
    62  		{
    63  			name: "2-year",
    64  			cert: getTestCertPEM2Years(),
    65  			want: wantedAppleGroups(3),
    66  		},
    67  		{
    68  			name: "3-year",
    69  			cert: getTestCertPEM3Years(),
    70  			want: wantedAppleGroups(4),
    71  		},
    72  		{
    73  			name: "Long",
    74  			cert: getTestCertPEMLongOriginal(),
    75  			want: wantedAppleGroups(5),
    76  		},
    77  	}
    78  
    79  	var policy AppleCTPolicy
    80  	sampleLogList := sampleLogList(t)
    81  
    82  	for _, test := range tests {
    83  		t.Run(test.name, func(t *testing.T) {
    84  			groups, err := policy.LogsByGroup(test.cert, sampleLogList)
    85  			if err != nil {
    86  				t.Errorf("LogsByGroup returned an error: %v", err)
    87  			}
    88  			if diff := pretty.Compare(test.want, groups); diff != "" {
    89  				t.Errorf("LogsByGroup: (-want +got)\n%s", diff)
    90  			}
    91  		})
    92  	}
    93  }
    94  

View as plain text