...

Source file src/github.com/google/certificate-transparency-go/fixchain/hash_test.go

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

     1  // Copyright 2016 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 fixchain
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  func TestHashBag(t *testing.T) {
    22  	hashBagTests := []struct {
    23  		certList1 []string
    24  		certList2 []string
    25  		expEqual  bool
    26  		errMsg    string
    27  	}{
    28  		{
    29  			[]string{googleLeaf},
    30  			[]string{thawteIntermediate},
    31  			false,
    32  			"hash match between Bags containing different certs",
    33  		},
    34  		{
    35  			[]string{googleLeaf, thawteIntermediate},
    36  			[]string{thawteIntermediate, googleLeaf},
    37  			true,
    38  			"hash mismatch between Bags containing the same certs",
    39  		},
    40  		{
    41  			[]string{googleLeaf, thawteIntermediate},
    42  			[]string{thawteIntermediate, googleLeaf, thawteIntermediate},
    43  			false,
    44  			"hash match between Bags containing the same certs, but one with duplicates",
    45  		},
    46  	}
    47  
    48  	for i, test := range hashBagTests {
    49  		certList1 := extractTestChain(t, i, test.certList1)
    50  		certList2 := extractTestChain(t, i, test.certList2)
    51  		if (hashBag(certList1) == hashBag(certList2)) != test.expEqual {
    52  			t.Errorf("#%d: %s", i, test.errMsg)
    53  		}
    54  	}
    55  }
    56  

View as plain text