1// Copyright 2016 Google Inc. 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 15package fixchain 16 17type fixTest struct { 18 cert string 19 chain []string 20 roots []string 21 22 function string 23 expectedChains [][]string 24 expectedErrs []errorType 25} 26 27var handleChainTests = []fixTest{ 28 // handleChain() 29 { // Correct chain returns chain 30 cert: googleLeaf, 31 chain: []string{thawteIntermediate, verisignRoot}, 32 roots: []string{verisignRoot}, 33 34 function: "handleChain", 35 expectedChains: [][]string{ 36 {"Google", "Thawte", "VeriSign"}, 37 }, 38 }, 39 { // No roots results in an error 40 cert: googleLeaf, 41 chain: []string{thawteIntermediate, verisignRoot}, 42 43 function: "handleChain", 44 expectedErrs: []errorType{VerifyFailed, FixFailed}, 45 }, 46 { // No roots where chain that will be built contains a loop results in error 47 cert: testC, 48 chain: []string{testB, testA}, 49 50 function: "handleChain", 51 expectedErrs: []errorType{VerifyFailed, FixFailed}, 52 }, 53 { // Incomplete chain returns a fixed chain 54 cert: googleLeaf, 55 roots: []string{verisignRoot}, 56 57 function: "handleChain", 58 expectedChains: [][]string{ 59 {"Google", "Thawte", "VeriSign"}, 60 }, 61 expectedErrs: []errorType{VerifyFailed}, 62 }, 63 { 64 cert: testLeaf, 65 roots: []string{testRoot}, 66 67 function: "handleChain", 68 expectedChains: [][]string{ 69 {"Leaf", "Intermediate2", "Intermediate1", "CA"}, 70 }, 71 expectedErrs: []errorType{VerifyFailed}, 72 }, 73 { // The wrong intermediate and root results in an error 74 cert: megaLeaf, 75 chain: []string{thawteIntermediate, verisignRoot}, 76 roots: []string{verisignRoot}, 77 78 function: "handleChain", 79 expectedErrs: []errorType{VerifyFailed, FixFailed}, 80 }, 81 { // The wrong root results in an error 82 cert: megaLeaf, 83 chain: []string{comodoIntermediate, verisignRoot}, 84 roots: []string{verisignRoot}, 85 86 function: "handleChain", 87 expectedErrs: []errorType{VerifyFailed, FixFailed}, 88 }, 89} 90 91type postTest struct { 92 url string 93 chain []string 94 95 urlScheme string 96 urlHost string 97 urlPath string 98 99 ferr *FixError 100 expectedErrs []errorType 101} 102 103var postTests = []postTest{ 104 { 105 url: "https://ct.googleapis.com/pilot", 106 chain: []string{googleLeaf, thawteIntermediate, verisignRoot}, 107 108 urlScheme: "https", 109 urlHost: "ct.googleapis.com", 110 urlPath: "/pilot/ct/v1/add-chain", 111 112 ferr: &FixError{Type: None}, 113 }, 114 { // Empty chain 115 url: "https://ct.googleapis.com/pilot", 116 117 urlScheme: "https", 118 urlHost: "ct.googleapis.com", 119 urlPath: "/pilot/ct/v1/add-chain", 120 121 ferr: &FixError{Type: None}, 122 }, 123 { 124 url: "https://ct.googleapis.com/pilot", 125 chain: []string{googleLeaf, thawteIntermediate, verisignRoot}, 126 127 ferr: &FixError{Type: LogPostFailed}, 128 expectedErrs: []errorType{LogPostFailed}, 129 }, 130} 131 132type fixAndLogTest struct { 133 url string 134 chain []string 135 136 // Expected items that will be queued to be fixed then logged 137 expectedCert string 138 expectedChain []string 139 expectedRoots []string 140 141 function string 142 expLoggedChains [][]string 143 expectedErrs []errorType 144} 145