Skip to content

Commit

Permalink
feat: optional status list check for attestation vc
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Holovko <[email protected]>
  • Loading branch information
aholovko committed Dec 29, 2023
1 parent edcf8be commit 5fed7b2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 70 deletions.
10 changes: 6 additions & 4 deletions pkg/service/clientattestation/client_attestation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ func (s *Service) ValidatePresentation(
return nil
}

//nolint:gocritic
func (s *Service) validateAttestationVP(
ctx context.Context,
_ context.Context,
jwtVP string,
) (*verifiable.Presentation, []*verifiable.Credential, error) {
attestationVP, err := verifiable.ParsePresentation(
Expand Down Expand Up @@ -253,9 +254,10 @@ func (s *Service) validateAttestationVP(
}

// check attestation VC status
if err = s.vcStatusVerifier.ValidateVCStatus(ctx, vcc.Status, vcc.Issuer); err != nil {
return nil, nil, fmt.Errorf("validate attestation vc status: %w", err)
}
// TODO: status list check should be mandatory for attestation VC
//if err = s.vcStatusVerifier.ValidateVCStatus(ctx, vcc.Status, vcc.Issuer); err != nil {
// return nil, nil, fmt.Errorf("validate attestation vc status: %w", err)
//}

attestationVCs = append(attestationVCs, vc)
}
Expand Down
133 changes: 67 additions & 66 deletions pkg/service/clientattestation/client_attestation_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Copyright Gen Digital Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

//nolint:gocritic
package clientattestation_test

import (
Expand Down Expand Up @@ -46,7 +47,7 @@ const (

func TestService_ValidateIssuance(t *testing.T) {
httpClient := NewMockHTTPClient(gomock.NewController(t))
vcStatusVerifier := NewMockVCStatusVerifier(gomock.NewController(t))
//vcStatusVerifier := NewMockVCStatusVerifier(gomock.NewController(t))

proofCreators, defaultProofChecker := testsupport.NewKMSSignersAndVerifier(t,
[]testsupport.SigningKey{
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestService_ValidateIssuance(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)

httpClient.EXPECT().Do(gomock.Any()).DoAndReturn(
func(req *http.Request) (*http.Response, error) {
Expand All @@ -108,7 +109,7 @@ func TestService_ValidateIssuance(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
httpClient.EXPECT().Do(gomock.Any()).Times(0)

jwtVP = "invalid-jwt-vp"
Expand All @@ -123,7 +124,7 @@ func TestService_ValidateIssuance(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
httpClient.EXPECT().Do(gomock.Any()).Times(0)

jwtVP = createAttestationVP(t, nil, walletProofCreator)
Expand All @@ -138,7 +139,7 @@ func TestService_ValidateIssuance(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
httpClient.EXPECT().Do(gomock.Any()).Times(0)

attestationVC := createAttestationVC(t, attestationProofCreator, walletDID, true)
Expand All @@ -155,7 +156,7 @@ func TestService_ValidateIssuance(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
httpClient.EXPECT().Do(gomock.Any()).Times(0)

attestationVC := createAttestationVC(t, attestationProofCreator, "invalid-subject", false)
Expand All @@ -167,31 +168,31 @@ func TestService_ValidateIssuance(t *testing.T) {
require.ErrorContains(t, err, "check attestation vp proof")
},
},
{
name: "fail to validate attestation vc status",
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).
Return(errors.New("validate status error"))

httpClient.EXPECT().Do(gomock.Any()).Times(0)

attestationVC := createAttestationVC(t, attestationProofCreator, walletDID, false)
jwtVP = createAttestationVP(t, attestationVC, walletProofCreator)

profile = createIssuerProfile(t)
},
check: func(t *testing.T, err error) {
require.ErrorContains(t, err, "validate attestation vc status")
},
},
//{
// name: "fail to validate attestation vc status",
// setup: func() {
// proofChecker = defaultProofChecker
//
// vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).
// Return(errors.New("validate status error"))
//
// httpClient.EXPECT().Do(gomock.Any()).Times(0)
//
// attestationVC := createAttestationVC(t, attestationProofCreator, walletDID, false)
// jwtVP = createAttestationVP(t, attestationVC, walletProofCreator)
//
// profile = createIssuerProfile(t)
// },
// check: func(t *testing.T, err error) {
// require.ErrorContains(t, err, "validate attestation vc status")
// },
//},
{
name: "policy url not set in profile",
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)

httpClient.EXPECT().Do(gomock.Any()).Times(0)

Expand All @@ -213,7 +214,7 @@ func TestService_ValidateIssuance(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)

httpClient.EXPECT().Do(gomock.Any()).DoAndReturn(
func(req *http.Request) (*http.Response, error) {
Expand All @@ -235,7 +236,7 @@ func TestService_ValidateIssuance(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)

httpClient.EXPECT().Do(gomock.Any()).DoAndReturn(
func(req *http.Request) (*http.Response, error) {
Expand All @@ -260,7 +261,7 @@ func TestService_ValidateIssuance(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)

httpClient.EXPECT().Do(gomock.Any()).DoAndReturn(
func(req *http.Request) (*http.Response, error) {
Expand All @@ -285,7 +286,7 @@ func TestService_ValidateIssuance(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)

httpClient.EXPECT().Do(gomock.Any()).DoAndReturn(
func(req *http.Request) (*http.Response, error) {
Expand Down Expand Up @@ -313,10 +314,10 @@ func TestService_ValidateIssuance(t *testing.T) {
tt.check(t,
clientattestation.NewService(
&clientattestation.Config{
HTTPClient: httpClient,
DocumentLoader: testutil.DocumentLoader(t),
ProofChecker: proofChecker,
VCStatusVerifier: vcStatusVerifier,
HTTPClient: httpClient,
DocumentLoader: testutil.DocumentLoader(t),
ProofChecker: proofChecker,
//VCStatusVerifier: vcStatusVerifier,
},
).ValidateIssuance(context.Background(), profile, jwtVP),
)
Expand All @@ -326,7 +327,7 @@ func TestService_ValidateIssuance(t *testing.T) {

func TestService_ValidatePresentation(t *testing.T) {
httpClient := NewMockHTTPClient(gomock.NewController(t))
vcStatusVerifier := NewMockVCStatusVerifier(gomock.NewController(t))
//vcStatusVerifier := NewMockVCStatusVerifier(gomock.NewController(t))

proofCreators, defaultProofChecker := testsupport.NewKMSSignersAndVerifier(t,
[]testsupport.SigningKey{
Expand Down Expand Up @@ -361,7 +362,7 @@ func TestService_ValidatePresentation(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)

httpClient.EXPECT().Do(gomock.Any()).DoAndReturn(
func(req *http.Request) (*http.Response, error) {
Expand Down Expand Up @@ -397,7 +398,7 @@ func TestService_ValidatePresentation(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
httpClient.EXPECT().Do(gomock.Any()).Times(0)

jwtVP = "invalid-jwt-vp"
Expand All @@ -412,7 +413,7 @@ func TestService_ValidatePresentation(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
httpClient.EXPECT().Do(gomock.Any()).Times(0)

jwtVP = createAttestationVP(t, nil, walletProofCreator)
Expand All @@ -427,7 +428,7 @@ func TestService_ValidatePresentation(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
httpClient.EXPECT().Do(gomock.Any()).Times(0)

attestationVC := createAttestationVC(t, attestationProofCreator, walletDID, true)
Expand All @@ -444,7 +445,7 @@ func TestService_ValidatePresentation(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
httpClient.EXPECT().Do(gomock.Any()).Times(0)

attestationVC := createAttestationVC(t, attestationProofCreator, "invalid-subject", false)
Expand All @@ -456,31 +457,31 @@ func TestService_ValidatePresentation(t *testing.T) {
require.ErrorContains(t, err, "check attestation vp proof")
},
},
{
name: "fail to validate attestation vc status",
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).
Return(errors.New("validate status error"))

httpClient.EXPECT().Do(gomock.Any()).Times(0)

attestationVC := createAttestationVC(t, attestationProofCreator, walletDID, false)
jwtVP = createAttestationVP(t, attestationVC, walletProofCreator)

profile = createVerifierProfile(t)
},
check: func(t *testing.T, err error) {
require.ErrorContains(t, err, "validate attestation vc status")
},
},
//{
// name: "fail to validate attestation vc status",
// setup: func() {
// proofChecker = defaultProofChecker
//
// vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).
// Return(errors.New("validate status error"))
//
// httpClient.EXPECT().Do(gomock.Any()).Times(0)
//
// attestationVC := createAttestationVC(t, attestationProofCreator, walletDID, false)
// jwtVP = createAttestationVP(t, attestationVC, walletProofCreator)
//
// profile = createVerifierProfile(t)
// },
// check: func(t *testing.T, err error) {
// require.ErrorContains(t, err, "validate attestation vc status")
// },
//},
{
name: "policy url not set in profile",
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)

httpClient.EXPECT().Do(gomock.Any()).Times(0)

Expand All @@ -503,7 +504,7 @@ func TestService_ValidatePresentation(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)

httpClient.EXPECT().Do(gomock.Any()).DoAndReturn(
func(req *http.Request) (*http.Response, error) {
Expand All @@ -528,7 +529,7 @@ func TestService_ValidatePresentation(t *testing.T) {
setup: func() {
proofChecker = defaultProofChecker

vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
//vcStatusVerifier.EXPECT().ValidateVCStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)

httpClient.EXPECT().Do(gomock.Any()).DoAndReturn(
func(req *http.Request) (*http.Response, error) {
Expand Down Expand Up @@ -556,10 +557,10 @@ func TestService_ValidatePresentation(t *testing.T) {
tt.check(t,
clientattestation.NewService(
&clientattestation.Config{
HTTPClient: httpClient,
DocumentLoader: testutil.DocumentLoader(t),
ProofChecker: proofChecker,
VCStatusVerifier: vcStatusVerifier,
HTTPClient: httpClient,
DocumentLoader: testutil.DocumentLoader(t),
ProofChecker: proofChecker,
//VCStatusVerifier: vcStatusVerifier,
},
).ValidatePresentation(context.Background(), profile, jwtVP),
)
Expand Down

0 comments on commit 5fed7b2

Please sign in to comment.