Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Sep 26, 2024
1 parent 913c67b commit 8c3c6ca
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions verifier/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/notaryproject/notation-core-go/revocation"
"github.com/notaryproject/notation-core-go/revocation/purpose"
"github.com/notaryproject/notation-core-go/revocation/result"
revocationresult "github.com/notaryproject/notation-core-go/revocation/result"
"github.com/notaryproject/notation-core-go/signature"
_ "github.com/notaryproject/notation-core-go/signature/cose"
"github.com/notaryproject/notation-core-go/testhelper"
Expand Down Expand Up @@ -1240,15 +1239,15 @@ func TestIsRequiredVerificationPluginVer(t *testing.T) {
}

func TestRevocationFinalResult(t *testing.T) {
certResult := []*revocationresult.CertRevocationResult{
certResult := []*result.CertRevocationResult{
{
// update leaf cert result in each sub-test
},
{
Result: revocationresult.ResultNonRevokable,
ServerResults: []*revocationresult.ServerResult{
Result: result.ResultNonRevokable,
ServerResults: []*result.ServerResult{
{
Result: revocationresult.ResultNonRevokable,
Result: result.ResultNonRevokable,
},
},
},
Expand All @@ -1266,36 +1265,36 @@ func TestRevocationFinalResult(t *testing.T) {
},
}
t.Run("OCSP error without fallback", func(t *testing.T) {
certResult[0] = &revocationresult.CertRevocationResult{
Result: revocationresult.ResultUnknown,
ServerResults: []*revocationresult.ServerResult{
certResult[0] = &result.CertRevocationResult{
Result: result.ResultUnknown,
ServerResults: []*result.ServerResult{
{
Server: "http://ocsp.example.com",
Result: revocationresult.ResultUnknown,
Result: result.ResultUnknown,
Error: errors.New("ocsp error"),
RevocationMethod: result.RevocationMethodOCSP,
},
},
}

finalResult, problematicCertSubject := revocationFinalResult(certResult, certChain, log.Discard)
if finalResult != revocationresult.ResultUnknown || problematicCertSubject != "CN=leafCert" {
if finalResult != result.ResultUnknown || problematicCertSubject != "CN=leafCert" {
t.Fatalf("unexpected final result: %v, problematic cert subject: %s", finalResult, problematicCertSubject)
}
})

t.Run("OCSP error with fallback", func(t *testing.T) {
certResult[0] = &revocationresult.CertRevocationResult{
Result: revocationresult.ResultOK,
ServerResults: []*revocationresult.ServerResult{
certResult[0] = &result.CertRevocationResult{
Result: result.ResultOK,
ServerResults: []*result.ServerResult{
{
Server: "http://ocsp.example.com",
Result: revocationresult.ResultUnknown,
Result: result.ResultUnknown,
Error: errors.New("ocsp error"),
RevocationMethod: result.RevocationMethodOCSP,
},
{
Result: revocationresult.ResultOK,
Result: result.ResultOK,
Server: "http://crl.example.com",
RevocationMethod: result.RevocationMethodCRL,
},
Expand All @@ -1304,23 +1303,23 @@ func TestRevocationFinalResult(t *testing.T) {
}

finalResult, problematicCertSubject := revocationFinalResult(certResult, certChain, log.Discard)
if finalResult != revocationresult.ResultOK || problematicCertSubject != "" {
if finalResult != result.ResultOK || problematicCertSubject != "" {
t.Fatalf("unexpected final result: %v, problematic cert subject: %s", finalResult, problematicCertSubject)
}
})

t.Run("OCSP error with fallback and CRL error", func(t *testing.T) {
certResult[0] = &revocationresult.CertRevocationResult{
Result: revocationresult.ResultUnknown,
ServerResults: []*revocationresult.ServerResult{
certResult[0] = &result.CertRevocationResult{
Result: result.ResultUnknown,
ServerResults: []*result.ServerResult{
{
Server: "http://ocsp.example.com",
Result: revocationresult.ResultUnknown,
Result: result.ResultUnknown,
Error: errors.New("ocsp error"),
RevocationMethod: result.RevocationMethodOCSP,
},
{
Result: revocationresult.ResultUnknown,
Result: result.ResultUnknown,
Error: errors.New("crl error"),
RevocationMethod: result.RevocationMethodCRL,
},
Expand All @@ -1329,25 +1328,25 @@ func TestRevocationFinalResult(t *testing.T) {
}

finalResult, problematicCertSubject := revocationFinalResult(certResult, certChain, log.Discard)
if finalResult != revocationresult.ResultUnknown || problematicCertSubject != "CN=leafCert" {
if finalResult != result.ResultUnknown || problematicCertSubject != "CN=leafCert" {
t.Fatalf("unexpected final result: %v, problematic cert subject: %s", finalResult, problematicCertSubject)
}
})

t.Run("revocation method unknown error(should never reach here)", func(t *testing.T) {
certResult[0] = &revocationresult.CertRevocationResult{
Result: revocationresult.ResultUnknown,
ServerResults: []*revocationresult.ServerResult{
certResult[0] = &result.CertRevocationResult{
Result: result.ResultUnknown,
ServerResults: []*result.ServerResult{
{
Result: revocationresult.ResultUnknown,
Result: result.ResultUnknown,
Error: errors.New("unknown error"),
RevocationMethod: result.RevocationMethodUnknown,
},
},
}

finalResult, problematicCertSubject := revocationFinalResult(certResult, certChain, log.Discard)
if finalResult != revocationresult.ResultUnknown || problematicCertSubject != "CN=leafCert" {
if finalResult != result.ResultUnknown || problematicCertSubject != "CN=leafCert" {
t.Fatalf("unexpected final result: %v, problematic cert subject: %s", finalResult, problematicCertSubject)
}
})
Expand Down

0 comments on commit 8c3c6ca

Please sign in to comment.